add version info to settings

This commit is contained in:
Chloe committed 2025-01-17 17:11:54 -07:00
1 parent acb07db6f2
commit b409a200bb
4 files changed
+120 -15

No files matched your search

@@ -35,10 +35,12 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.input.nestedscroll.nestedScroll import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.platform.LocalClipboardManager
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.Role import androidx.compose.ui.semantics.Role
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
@@ -405,11 +407,73 @@ fun SettingsScreen(
) )
} }
Text( OptionsGroup(stringResource(R.string.preference_category_about)) {
stringResource(R.string.preference_launcher_version, BuildConfig.VERSION_NAME), val clipboard = LocalClipboardManager.current
style = Typography.labelSmall,
modifier = Modifier.padding(horizontal = 16.dp, vertical = 4.dp) OptionsButton(
) stringResource(R.string.preference_launcher_version_name),
stringResource(R.string.preference_launcher_version_description, BuildConfig.VERSION_NAME),
displayInline = true
) {
clipboard.setText(AnnotatedString(context.getString(
R.string.preference_launcher_version,
BuildConfig.VERSION_NAME
)))
}
OptionsButton(
stringResource(R.string.preference_loader_version_name),
stringResource(R.string.preference_loader_version_description, currentRelease ?: "unknown"),
displayInline = true
) {
clipboard.setText(AnnotatedString(context.getString(
R.string.preference_loader_version,
currentRelease ?: "unknown"
)))
}
val gameInstalled = remember {
GamePackageUtils.isGameInstalled(context.packageManager)
}
if (gameInstalled) {
val gameVersion = remember {
GamePackageUtils.getUnifiedVersionName(context.packageManager)
}
val gameSource = remember {
context.getString(when (GamePackageUtils.identifyGameSource(context.packageManager)) {
GamePackageUtils.GameSource.GOOGLE -> R.string.preference_game_source_google
GamePackageUtils.GameSource.AMAZON -> R.string.preference_game_source_amazon
else -> R.string.preference_game_source_unknown
})
}
OptionsButton(
stringResource(R.string.preference_game_version_name),
stringResource(R.string.preference_game_version_description, gameVersion, gameSource),
displayInline = true
) {
clipboard.setText(AnnotatedString(context.getString(
R.string.preference_game_version,
gameVersion,
gameSource
)))
}
OptionsButton(
stringResource(R.string.preference_architecture_name),
stringResource(R.string.preference_architecture_description, Build.MODEL, LaunchUtils.applicationArchitecture),
displayInline = true
) {
clipboard.setText(AnnotatedString(context.getString(
R.string.preference_architecture,
Build.MODEL,
LaunchUtils.applicationArchitecture
)))
}
}
}
} }
} }
) )
@@ -37,6 +37,7 @@ import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.Role import androidx.compose.ui.semantics.Role
import androidx.compose.ui.text.input.KeyboardType import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Dialog import androidx.compose.ui.window.Dialog
@@ -297,18 +298,22 @@ fun <T> SelectDialog(
} }
@Composable @Composable
fun OptionsButton(title: String, description: String? = null, icon: (@Composable () -> Unit)? = null, onClick: () -> Unit) { fun OptionsButton(title: String, description: String? = null, icon: (@Composable () -> Unit)? = null, displayInline: Boolean = false, onClick: () -> Unit) {
OptionsCard( OptionsCard(
title = { title = {
OptionsTitle( OptionsTitle(
title = title, title = title,
description = description, description = description.takeIf { !displayInline },
icon = icon icon = icon
) )
}, },
modifier = Modifier modifier = Modifier
.clickable(onClick = onClick, role = Role.Button) .clickable(onClick = onClick, role = Role.Button)
) { } ) {
if (displayInline && description != null) {
Text(description, textAlign = TextAlign.End)
}
}
} }
@Composable @Composable
@@ -113,24 +113,40 @@ object GamePackageUtils {
} }
private const val GAME_CERTIFICATE_HASH = "f5e7d8284d72c461a5f022d0cf755df101c3bb1e69cbe241bc1aef2cc5610a43" private const val GAME_CERTIFICATE_HASH = "f5e7d8284d72c461a5f022d0cf755df101c3bb1e69cbe241bc1aef2cc5610a43"
private const val AMAZON_CERTIFICATE_HASH = "1f228081e4d66e006887d4ba0f3d40e96a80c758b84231f11cd5c1c9aef6048f"
private fun validateCertificate(certificate: ByteArray): Boolean = private fun validateCertificate(certificate: ByteArray): GameSource = when (val hash = certificate.toByteString().sha256().hex()) {
certificate.toByteString().sha256().hex() == GAME_CERTIFICATE_HASH GAME_CERTIFICATE_HASH -> GameSource.GOOGLE
AMAZON_CERTIFICATE_HASH -> GameSource.AMAZON
else -> {
println("Encountered certificate hash: $hash")
GameSource.UNKNOWN
}
}
fun identifyGameLegitimacy(packageManager: PackageManager): Boolean { enum class GameSource {
UNKNOWN, GOOGLE, AMAZON
}
fun identifyGameSource(packageManager: PackageManager): GameSource {
@Suppress("DEPRECATION") @Suppress("DEPRECATION")
val certificates = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { val certificates = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
val game = packageManager.getPackageInfo(Constants.PACKAGE_NAME, PackageManager.GET_SIGNING_CERTIFICATES) val game = packageManager.getPackageInfo(Constants.PACKAGE_NAME, PackageManager.GET_SIGNING_CERTIFICATES)
val signingInfo = game.signingInfo val signingInfo = game.signingInfo
signingInfo?.signingCertificateHistory ?: return false signingInfo?.signingCertificateHistory ?: return GameSource.UNKNOWN
} else { } else {
val game = packageManager.getPackageInfo(Constants.PACKAGE_NAME, PackageManager.GET_SIGNATURES) val game = packageManager.getPackageInfo(Constants.PACKAGE_NAME, PackageManager.GET_SIGNATURES)
game.signatures game.signatures
} }
return certificates?.any { return certificates?.map {
validateCertificate(it.toByteArray()) validateCertificate(it.toByteArray())
} ?: false }?.firstOrNull {
it != GameSource.UNKNOWN
} ?: GameSource.UNKNOWN
} }
fun identifyGameLegitimacy(packageManager: PackageManager) =
identifyGameSource(packageManager) != GameSource.UNKNOWN
} }
+21 -1
View File
@@ -149,9 +149,29 @@
<string name="preference_release_channel_beta">Pre-release</string> <string name="preference_release_channel_beta">Pre-release</string>
<string name="preference_release_channel_nightly">Nightly</string> <string name="preference_release_channel_nightly">Nightly</string>
<string name="preference_category_about">About</string>
<string name="preference_launcher_version_name">Android Launcher</string>
<string name="preference_launcher_version_description">v%1$s</string>
<string name="preference_launcher_version">Android Launcher v%1$s</string>
<string name="preference_loader_version_name">Geode</string>
<string name="preference_loader_version_description">%1$s</string>
<string name="preference_loader_version">Geode %1$s</string>
<string name="preference_game_version_name">Geometry Dash</string>
<string name="preference_game_version_description">%1$s (%2$s)</string>
<string name="preference_game_version">Geometry Dash %1$s (%2$s)</string>
<string name="preference_game_source_google">Google</string>
<string name="preference_game_source_amazon">Amazon</string>
<string name="preference_game_source_unknown">Unknown</string>
<string name="preference_architecture_name">Device</string>
<string name="preference_architecture_description">%1$s (%2$s)</string>
<string name="preference_architecture">%1$s (%2$s)</string>
<string name="preference_check_for_updates_button">Check for updates</string> <string name="preference_check_for_updates_button">Check for updates</string>
<string name="preference_check_for_updates_description">Current loader version: %1$s</string> <string name="preference_check_for_updates_description">Current loader version: %1$s</string>
<string name="preference_launcher_version">Geode Launcher v%1$s</string>
<string name="preference_check_for_updates_failed">Update failed. See logs for more details.</string> <string name="preference_check_for_updates_failed">Update failed. See logs for more details.</string>
<string name="preference_check_for_updates_none_found">No updates found.</string> <string name="preference_check_for_updates_none_found">No updates found.</string>
<string name="preference_check_for_updates_success">Geode has been updated!</string> <string name="preference_check_for_updates_success">Geode has been updated!</string>