mirror of
https://github.com/geode-sdk/android-launcher.git
synced 2026-10-22 16:42:38 +00:00
show message when game fails to load
This commit is contained in:
5 files changed
+133
-30
No files matched your search
@@ -50,31 +50,60 @@ class GeometryDashActivity : AppCompatActivity(), Cocos2dxHelper.Cocos2dxHelperL
|
||||
|
||||
// return back to main if Geometry Dash isn't found
|
||||
if (!LaunchUtils.isGeometryDashInstalled(packageManager)) {
|
||||
val launchIntent = Intent(this, MainActivity::class.java)
|
||||
launchIntent.flags = Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
|
||||
startActivity(launchIntent)
|
||||
}
|
||||
|
||||
val gdPackageInfo = packageManager.getPackageInfo(Constants.PACKAGE_NAME, 0)
|
||||
|
||||
try {
|
||||
LaunchUtils.addAssetsFromPackage(assets, gdPackageInfo)
|
||||
} catch (e: NoSuchMethodException) {
|
||||
e.printStackTrace()
|
||||
returnToMain()
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
// fixes bugs specific to the new app directory, such as package name
|
||||
val saveDir = LaunchUtils.getSaveDirectory(this)
|
||||
saveDir.mkdir()
|
||||
|
||||
LauncherFix.loadLibrary()
|
||||
LauncherFix.setOriginalDataPath(Constants.GJ_DATA_DIR)
|
||||
LauncherFix.setDataPath(saveDir.path)
|
||||
tryLoadGame()
|
||||
} catch (e: UnsatisfiedLinkError) {
|
||||
e.printStackTrace()
|
||||
|
||||
// generates helpful information for use in debugging library load failures
|
||||
val gdPackageInfo = packageManager.getPackageInfo(Constants.PACKAGE_NAME, 0)
|
||||
|
||||
val abi = LaunchUtils.applicationArchitecture
|
||||
val isExtracted = gdPackageInfo.applicationInfo.flags and ApplicationInfo.FLAG_EXTRACT_NATIVE_LIBS == ApplicationInfo.FLAG_EXTRACT_NATIVE_LIBS
|
||||
val isSplit = (gdPackageInfo.applicationInfo.splitSourceDirs?.size ?: 0) > 1
|
||||
|
||||
val metadata = "Geometry Dash metadata:\nSplit sources: $isSplit\nExtracted libraries: $isExtracted\nLauncher architecture: $abi"
|
||||
Log.i("GeodeLauncher", metadata)
|
||||
|
||||
returnToMain(
|
||||
getString(R.string.load_failed_link_error),
|
||||
getString(R.string.load_failed_link_error_description)
|
||||
)
|
||||
|
||||
return
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
|
||||
returnToMain(
|
||||
getString(R.string.load_failed_generic_error),
|
||||
getString(R.string.load_failed_generic_error_description, e.message ?: "UnknownException")
|
||||
)
|
||||
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
private fun returnToMain(returnTitle: String? = null, returnMessage: String? = null) {
|
||||
val launchIntent = Intent(this, MainActivity::class.java).apply {
|
||||
flags = Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
|
||||
if (!returnTitle.isNullOrEmpty() && !returnMessage.isNullOrEmpty()) {
|
||||
putExtra(Constants.LAUNCHER_KEY_RETURN_TITLE, returnTitle)
|
||||
putExtra(Constants.LAUNCHER_KEY_RETURN_MESSAGE, returnMessage)
|
||||
}
|
||||
}
|
||||
|
||||
startActivity(launchIntent)
|
||||
}
|
||||
|
||||
private fun tryLoadGame() {
|
||||
val gdPackageInfo = packageManager.getPackageInfo(Constants.PACKAGE_NAME, 0)
|
||||
|
||||
setupRedirection(gdPackageInfo)
|
||||
|
||||
// request read and write permissions
|
||||
requestPermissions(
|
||||
@@ -95,25 +124,49 @@ class GeometryDashActivity : AppCompatActivity(), Cocos2dxHelper.Cocos2dxHelperL
|
||||
loadTestingLibraries()
|
||||
}
|
||||
|
||||
FMOD.init(this)
|
||||
|
||||
setContentView(createView())
|
||||
|
||||
// call native functions after native libraries init
|
||||
JniToCpp.setupHSSAssets(
|
||||
gdPackageInfo.applicationInfo.sourceDir,
|
||||
Environment.getExternalStorageDirectory().absolutePath
|
||||
)
|
||||
Cocos2dxHelper.nativeSetApkPath(gdPackageInfo.applicationInfo.sourceDir)
|
||||
|
||||
BaseRobTopActivity.setCurrentActivity(this)
|
||||
registerReceiver()
|
||||
setupPostLibraryLoad(gdPackageInfo)
|
||||
|
||||
if (!loadGeodeLibrary()) {
|
||||
Log.w("GeodeLauncher", "could not load Geode object!")
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupRedirection(packageInfo: PackageInfo) {
|
||||
try {
|
||||
LaunchUtils.addAssetsFromPackage(assets, packageInfo)
|
||||
} catch (e: NoSuchMethodException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
|
||||
try {
|
||||
// fixes bugs specific to the new app directory, such as package name
|
||||
val saveDir = LaunchUtils.getSaveDirectory(this)
|
||||
saveDir.mkdir()
|
||||
|
||||
LauncherFix.loadLibrary()
|
||||
LauncherFix.setOriginalDataPath(Constants.GJ_DATA_DIR)
|
||||
LauncherFix.setDataPath(saveDir.path)
|
||||
} catch (e: UnsatisfiedLinkError) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupPostLibraryLoad(packageInfo: PackageInfo) {
|
||||
FMOD.init(this)
|
||||
|
||||
// call native functions after native libraries init
|
||||
JniToCpp.setupHSSAssets(
|
||||
packageInfo.applicationInfo.sourceDir,
|
||||
Environment.getExternalStorageDirectory().absolutePath
|
||||
)
|
||||
Cocos2dxHelper.nativeSetApkPath(packageInfo.applicationInfo.sourceDir)
|
||||
|
||||
BaseRobTopActivity.setCurrentActivity(this)
|
||||
registerReceiver()
|
||||
}
|
||||
|
||||
@SuppressLint("UnsafeDynamicallyLoadedCode")
|
||||
private fun tryLoadLibrary(packageInfo: PackageInfo, libraryName: String) {
|
||||
val nativeDir = getNativeLibraryDirectory(packageInfo.applicationInfo)
|
||||
|
||||
@@ -55,6 +55,9 @@ class MainActivity : ComponentActivity() {
|
||||
val gdInstalled = LaunchUtils.isGeometryDashInstalled(packageManager)
|
||||
val geodeInstalled = LaunchUtils.isGeodeInstalled(this)
|
||||
|
||||
val returnMessage = intent.extras?.getString(Constants.LAUNCHER_KEY_RETURN_MESSAGE)
|
||||
val returnTitle = intent.extras?.getString(Constants.LAUNCHER_KEY_RETURN_TITLE)
|
||||
|
||||
setContent {
|
||||
val themeOption by PreferenceUtils.useIntPreference(PreferenceUtils.Key.THEME)
|
||||
val theme = Theme.fromInt(themeOption)
|
||||
@@ -68,6 +71,10 @@ class MainActivity : ComponentActivity() {
|
||||
color = MaterialTheme.colorScheme.background
|
||||
) {
|
||||
MainScreen(gdInstalled, geodeInstalled)
|
||||
|
||||
if (!returnMessage.isNullOrEmpty() && !returnTitle.isNullOrEmpty()) {
|
||||
LoadFailedDialog(returnTitle, returnMessage)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -146,6 +153,30 @@ fun UpdateMessageIndicator(
|
||||
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun LoadFailedDialog(returnTitle: String, returnMessage: String) {
|
||||
var showDialog by remember { mutableStateOf(true) }
|
||||
|
||||
if (showDialog) {
|
||||
AlertDialog(
|
||||
icon = {
|
||||
Icon(
|
||||
painterResource(R.drawable.icon_error),
|
||||
contentDescription = stringResource(R.string.launcher_error_icon_alt)
|
||||
)
|
||||
},
|
||||
title = { Text(returnTitle) },
|
||||
text = { Text(returnMessage) },
|
||||
confirmButton = {
|
||||
TextButton(onClick = { showDialog = false }) {
|
||||
Text(stringResource(R.string.message_box_accept))
|
||||
}
|
||||
},
|
||||
onDismissRequest = { showDialog = false }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun UpdateWarning() {
|
||||
val context = LocalContext.current
|
||||
|
||||
@@ -15,4 +15,8 @@ object Constants {
|
||||
|
||||
const val SUPPORTED_VERSION_CODE = 37L
|
||||
const val SUPPORTED_VERSION_STRING = "2.2.13"
|
||||
|
||||
const val LAUNCHER_KEY_RETURN_TITLE = "return_title"
|
||||
const val LAUNCHER_KEY_RETURN_MESSAGE = "return_message"
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user