add game version check

This commit is contained in:
qimiko committed 2024-01-12 17:40:52 -07:00
1 parent 7cdbe45ad6
commit 588e0b8e58
4 files changed
+86 -2

No files matched your search

@@ -13,13 +13,16 @@ import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.PlayArrow import androidx.compose.material.icons.filled.PlayArrow
import androidx.compose.material.icons.filled.Settings import androidx.compose.material.icons.filled.Settings
import androidx.compose.material.icons.filled.Warning
import androidx.compose.material3.* import androidx.compose.material3.*
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalContext
@@ -36,6 +39,7 @@ import com.geode.launcher.ui.theme.GeodeLauncherTheme
import com.geode.launcher.ui.theme.LocalTheme import com.geode.launcher.ui.theme.LocalTheme
import com.geode.launcher.ui.theme.Theme import com.geode.launcher.ui.theme.Theme
import com.geode.launcher.ui.theme.Typography import com.geode.launcher.ui.theme.Typography
import com.geode.launcher.utils.Constants
import com.geode.launcher.utils.LaunchUtils import com.geode.launcher.utils.LaunchUtils
import com.geode.launcher.utils.PreferenceUtils import com.geode.launcher.utils.PreferenceUtils
import com.geode.launcher.utils.ReleaseManager import com.geode.launcher.utils.ReleaseManager
@@ -142,6 +146,57 @@ fun UpdateMessageIndicator(
} }
@Composable
fun UpdateWarning() {
val context = LocalContext.current
val packageManager = context.packageManager
val gdVersionCode = remember { LaunchUtils.getGeometryDashVersionCode(packageManager) }
val gdVersionString = remember { LaunchUtils.getGeometryDashVersionString(packageManager) }
var showUpdateWarning by remember { mutableStateOf(true) }
if (gdVersionCode != Constants.SUPPORTED_VERSION_CODE) {
if (showUpdateWarning) {
AlertDialog(
icon = {
Icon(
Icons.Filled.Warning,
contentDescription = stringResource(R.string.launcher_warning_icon_alt)
)
},
title = {
Text(stringResource(R.string.launcher_unsupported_version_title))
},
text = {
Text(stringResource(
R.string.launcher_unsupported_version_description,
gdVersionString, Constants.SUPPORTED_VERSION_STRING
))
},
confirmButton = {
TextButton(onClick = {
showUpdateWarning = false
onLaunch(context)
}) {
Text(stringResource(R.string.message_box_accept))
}
},
dismissButton = {
TextButton(onClick = { showUpdateWarning = false }) {
Text(stringResource(R.string.message_box_cancel))
}
},
onDismissRequest = { showUpdateWarning = false }
)
}
} else {
LaunchedEffect(gdVersionCode) {
onLaunch(context)
}
}
}
@Composable @Composable
fun UpdateCard(releaseViewModel: ReleaseViewModel, modifier: Modifier = Modifier) { fun UpdateCard(releaseViewModel: ReleaseViewModel, modifier: Modifier = Modifier) {
val context = LocalContext.current val context = LocalContext.current
@@ -260,6 +315,8 @@ fun MainScreen(
?.hasUpdated ?: false ?.hasUpdated ?: false
val geodeInstalled = geodePreinstalled || geodeJustInstalled val geodeInstalled = geodePreinstalled || geodeJustInstalled
var beginLaunch by remember { mutableStateOf(false) }
LaunchedEffect(shouldUpdate) { LaunchedEffect(shouldUpdate) {
if (shouldUpdate && !releaseViewModel.hasPerformedCheck) { if (shouldUpdate && !releaseViewModel.hasPerformedCheck) {
releaseViewModel.runReleaseCheck() releaseViewModel.runReleaseCheck()
@@ -293,7 +350,7 @@ fun MainScreen(
onCountdownFinish = { onCountdownFinish = {
// just in case this changed async // just in case this changed async
if (shouldAutomaticallyLaunch.value) { if (shouldAutomaticallyLaunch.value) {
onLaunch(context) beginLaunch = true
} }
} }
) )
@@ -314,7 +371,7 @@ fun MainScreen(
Row { Row {
Button( Button(
onClick = { onLaunch(context) }, onClick = { beginLaunch = true },
enabled = !releaseViewModel.isInUpdate enabled = !releaseViewModel.isInUpdate
) { ) {
Icon( Icon(
@@ -378,6 +435,10 @@ fun MainScreen(
modifier = Modifier.padding(12.dp) modifier = Modifier.padding(12.dp)
) )
} }
if (beginLaunch) {
UpdateWarning()
}
} }
@Preview(showSystemUi = true) @Preview(showSystemUi = true)
@@ -12,4 +12,7 @@ object Constants {
// this value is hardcoded into GD // this value is hardcoded into GD
@SuppressLint("SdCardPath") @SuppressLint("SdCardPath")
const val GJ_DATA_DIR = "/data/data/${PACKAGE_NAME}" const val GJ_DATA_DIR = "/data/data/${PACKAGE_NAME}"
const val SUPPORTED_VERSION_CODE = 37L
const val SUPPORTED_VERSION_STRING = "2.2.13"
} }
@@ -18,6 +18,21 @@ object LaunchUtils {
} }
} }
fun getGeometryDashVersionCode(packageManager: PackageManager): Long {
val game = packageManager.getPackageInfo(Constants.PACKAGE_NAME, 0)
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
game.longVersionCode
} else {
game.versionCode.toLong()
}
}
fun getGeometryDashVersionString(packageManager: PackageManager): String {
val game = packageManager.getPackageInfo(Constants.PACKAGE_NAME, 0)
return game.versionName
}
fun getApplicationArchitecture(): String { fun getApplicationArchitecture(): String {
// supposedly CPU_ABI returns the current arch for the running application // supposedly CPU_ABI returns the current arch for the running application
// despite being deprecated, this is also one of the few ways to get this information // despite being deprecated, this is also one of the few ways to get this information
+5
View File
@@ -18,6 +18,11 @@
<item quantity="one">Automatically launching game in %1$d second.</item> <item quantity="one">Automatically launching game in %1$d second.</item>
<item quantity="other">Automatically launching game in %1$d seconds.</item> <item quantity="other">Automatically launching game in %1$d seconds.</item>
</plurals> </plurals>
<string name="launcher_warning_icon_alt">warning</string>
<string name="launcher_unsupported_version_title">Unsupported version</string>
<string name="launcher_unsupported_version_description">
The current version of Geometry Dash is not compatible with the version supported by the launcher (%2$s).\nLaunch will continue, but crashes may occur!
</string>
<!-- Updater strings --> <!-- Updater strings -->
<string name="release_fetch_failed">Update failed.\n%1$s</string> <string name="release_fetch_failed">Update failed.\n%1$s</string>