Skip to content

Commit 2a2d4ea

Browse files
committed
Fix #83: Add System Installer fallback button on install failure
1 parent f00e974 commit 2a2d4ea

6 files changed

Lines changed: 35 additions & 0 deletions

File tree

app/src/main/java/app/pwhs/universalinstaller/presentation/install/DialogInstallActivity.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,24 @@ class DialogInstallActivity : ComponentActivity() {
425425
onSkipParse = if (isApk) {
426426
{ viewModel.skipParseAndInstallSingle() }
427427
} else null,
428+
onFallbackInstall = {
429+
val apkUri = dialogTarget?.apkUri
430+
if (isApk && apkUri != null) {
431+
try {
432+
val intent = Intent(Intent.ACTION_VIEW).apply {
433+
setDataAndType(apkUri, "application/vnd.android.package-archive")
434+
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_GRANT_READ_URI_PERMISSION
435+
}
436+
startActivity(intent)
437+
} catch (e: Exception) {
438+
Timber.e(e, "Failed to launch system installer fallback")
439+
Toast.makeText(context, "System installer not available", Toast.LENGTH_SHORT).show()
440+
}
441+
viewModel.dialogClose()
442+
viewModel.clearDialogTarget()
443+
finish()
444+
}
445+
}.takeIf { isApk && dialogTarget?.apkUri != null },
428446
)
429447

430448
PositionDialog(

app/src/main/java/app/pwhs/universalinstaller/presentation/install/InstallUiState.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ data class DialogTarget(
4242
val packageName: String,
4343
val appName: String,
4444
val iconPath: String?,
45+
val apkUri: android.net.Uri? = null,
4546
)
4647

4748
sealed interface DownloadState {

app/src/main/java/app/pwhs/universalinstaller/presentation/install/InstallViewModel.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,7 @@ class InstallViewModel(
464464
packageName = pkgForTarget,
465465
appName = nameForTarget,
466466
iconPath = iconPath,
467+
apkUri = originalUri,
467468
)
468469
}
469470
} else null,
@@ -487,6 +488,7 @@ class InstallViewModel(
487488
packageName = pkgForTarget,
488489
appName = nameForTarget,
489490
iconPath = iconPath,
491+
apkUri = originalUri,
490492
)
491493
}
492494
} else null,

app/src/main/java/app/pwhs/universalinstaller/presentation/install/dialog/DialogGenerator.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ fun generateDialogParams(
5252
onToggleAllUsers: (Boolean) -> Unit,
5353
onSelectUserId: (Int?) -> Unit,
5454
onSkipParse: (() -> Unit)? = null,
55+
onFallbackInstall: (() -> Unit)? = null,
5556
): DialogParams {
5657
return when (val stage = uiState.dialogStage) {
5758
DialogStage.Loading -> {
@@ -217,6 +218,7 @@ fun generateDialogParams(
217218
errorMessage = stage.errorMessage,
218219
onClose = onCloseAfterResult,
219220
onRetry = onRetry,
221+
onFallbackInstall = onFallbackInstall
220222
)
221223
}
222224
)

app/src/main/java/app/pwhs/universalinstaller/presentation/install/dialog/DialogInstallStages.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ fun DialogFailedContent(
275275
errorMessage: String,
276276
onClose: () -> Unit,
277277
onRetry: (() -> Unit)? = null,
278+
onFallbackInstall: (() -> Unit)? = null,
278279
) {
279280
val context = androidx.compose.ui.platform.LocalContext.current
280281
val clipboard = androidx.compose.ui.platform.LocalClipboard.current
@@ -346,6 +347,16 @@ fun DialogFailedContent(
346347

347348
Spacer(modifier = Modifier.height(12.dp))
348349

350+
if (onFallbackInstall != null) {
351+
Button(
352+
onClick = onFallbackInstall,
353+
modifier = Modifier.fillMaxWidth(),
354+
) {
355+
Text(stringResource(R.string.dialog_failed_fallback_install, "Install via System Installer"))
356+
}
357+
Spacer(modifier = Modifier.height(8.dp))
358+
}
359+
349360
if (onRetry != null) {
350361
Row(
351362
modifier = Modifier.fillMaxWidth(),

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,7 @@
550550
<string name="dialog_failed_title">Installation failed</string>
551551
<string name="dialog_failed_retry">Retry</string>
552552
<string name="dialog_failed_close">Close</string>
553+
<string name="dialog_failed_fallback_install">Install via System Installer</string>
553554
<string name="dialog_version_downgrade">⚠ Downgrade: %1$s → %2$s</string>
554555
<string name="dialog_chip_downgrade">Downgrade</string>
555556
<string name="dialog_chip_split_apk">Split APK</string>

0 commit comments

Comments
 (0)