forked from geode-sdk/android-launcher
add game version check
This commit is contained in:
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.filled.PlayArrow
|
||||
import androidx.compose.material.icons.filled.Settings
|
||||
import androidx.compose.material.icons.filled.Warning
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
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.Theme
|
||||
import com.geode.launcher.ui.theme.Typography
|
||||
import com.geode.launcher.utils.Constants
|
||||
import com.geode.launcher.utils.LaunchUtils
|
||||
import com.geode.launcher.utils.PreferenceUtils
|
||||
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
|
||||
fun UpdateCard(releaseViewModel: ReleaseViewModel, modifier: Modifier = Modifier) {
|
||||
val context = LocalContext.current
|
||||
@@ -260,6 +315,8 @@ fun MainScreen(
|
||||
?.hasUpdated ?: false
|
||||
val geodeInstalled = geodePreinstalled || geodeJustInstalled
|
||||
|
||||
var beginLaunch by remember { mutableStateOf(false) }
|
||||
|
||||
LaunchedEffect(shouldUpdate) {
|
||||
if (shouldUpdate && !releaseViewModel.hasPerformedCheck) {
|
||||
releaseViewModel.runReleaseCheck()
|
||||
@@ -293,7 +350,7 @@ fun MainScreen(
|
||||
onCountdownFinish = {
|
||||
// just in case this changed async
|
||||
if (shouldAutomaticallyLaunch.value) {
|
||||
onLaunch(context)
|
||||
beginLaunch = true
|
||||
}
|
||||
}
|
||||
)
|
||||
@@ -314,7 +371,7 @@ fun MainScreen(
|
||||
|
||||
Row {
|
||||
Button(
|
||||
onClick = { onLaunch(context) },
|
||||
onClick = { beginLaunch = true },
|
||||
enabled = !releaseViewModel.isInUpdate
|
||||
) {
|
||||
Icon(
|
||||
@@ -378,6 +435,10 @@ fun MainScreen(
|
||||
modifier = Modifier.padding(12.dp)
|
||||
)
|
||||
}
|
||||
|
||||
if (beginLaunch) {
|
||||
UpdateWarning()
|
||||
}
|
||||
}
|
||||
|
||||
@Preview(showSystemUi = true)
|
||||
|
||||
@@ -12,4 +12,7 @@ object Constants {
|
||||
// this value is hardcoded into GD
|
||||
@SuppressLint("SdCardPath")
|
||||
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 {
|
||||
// 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
|
||||
|
||||
@@ -18,6 +18,11 @@
|
||||
<item quantity="one">Automatically launching game in %1$d second.</item>
|
||||
<item quantity="other">Automatically launching game in %1$d seconds.</item>
|
||||
</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 -->
|
||||
<string name="release_fetch_failed">Update failed.\n%1$s</string>
|
||||
|
||||
Reference in new issue
Block a user