Skip to content

Commit 3d9f3e9

Browse files
committed
fix: shortcut
1 parent 367434c commit 3d9f3e9

1 file changed

Lines changed: 14 additions & 23 deletions

File tree

app/src/main/java/app/pwhs/universalinstaller/MainActivity.kt

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@ private enum class AppRoute { Splash, Onboarding, Main }
3939

4040
class MainActivity : ComponentActivity() {
4141

42-
private val notificationPermissionLauncher = registerForActivityResult(
43-
ActivityResultContracts.RequestPermission()
44-
) { /* granted or not — uninstall flow works either way, notifications just won't show */ }
45-
4642
override fun attachBaseContext(newBase: Context) {
4743
super.attachBaseContext(LocaleHelper.wrap(newBase))
4844
}
@@ -112,15 +108,6 @@ class MainActivity : ComponentActivity() {
112108
}
113109

114110
val intentScheme = intent?.data?.scheme
115-
val shortcutRoute = remember(intent) {
116-
if (intentScheme == "universalinstaller") {
117-
when (intent?.data?.host) {
118-
"sync" -> com.ramcosta.composedestinations.generated.destinations.SyncScreenDestination
119-
"uninstall" -> com.ramcosta.composedestinations.generated.destinations.UninstallScreenDestination
120-
else -> null
121-
}
122-
} else null
123-
}
124111

125112
// Post the intent URI AFTER the composable tree is set up, so InstallScreen
126113
// is already composed (when skipSplash == true) and can process it immediately.
@@ -139,12 +126,23 @@ class MainActivity : ComponentActivity() {
139126
)
140127
AppRoute.Main -> {
141128
LaunchedEffect(Unit) {
142-
startActivity(Intent(this@MainActivity, app.pwhs.universalinstaller.presentation.install.InstallActivity::class.java).apply {
129+
val uri = intent?.data
130+
val targetActivity = if (uri?.scheme == "universalinstaller") {
131+
when (uri.host) {
132+
"sync" -> app.pwhs.universalinstaller.presentation.sync.SyncActivity::class.java
133+
"uninstall" -> app.pwhs.universalinstaller.presentation.uninstall.UninstallActivity::class.java
134+
else -> app.pwhs.universalinstaller.presentation.install.InstallActivity::class.java
135+
}
136+
} else {
137+
app.pwhs.universalinstaller.presentation.install.InstallActivity::class.java
138+
}
139+
startActivity(Intent(this@MainActivity, targetActivity).apply {
143140
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
144141
})
145142
finish()
146143
}
147-
} }
144+
}
145+
}
148146
}
149147
}
150148
}
@@ -173,14 +171,6 @@ class MainActivity : ComponentActivity() {
173171
ShortcutManagerCompat.addDynamicShortcuts(this, listOf(syncShortcut, uninstallShortcut))
174172
}
175173

176-
private fun maybeRequestNotificationPermission() {
177-
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) return
178-
val granted = ContextCompat.checkSelfPermission(
179-
this, Manifest.permission.POST_NOTIFICATIONS
180-
) == PackageManager.PERMISSION_GRANTED
181-
if (!granted) notificationPermissionLauncher.launch(Manifest.permission.POST_NOTIFICATIONS)
182-
}
183-
184174
override fun onNewIntent(intent: Intent) {
185175
super.onNewIntent(intent)
186176
setIntent(intent)
@@ -198,6 +188,7 @@ class MainActivity : ComponentActivity() {
198188
when (intent.action) {
199189
Intent.ACTION_VIEW, Intent.ACTION_INSTALL_PACKAGE -> {
200190
val uri: Uri = intent.data ?: return
191+
if (uri.scheme == "universalinstaller") return
201192
IntentHandoff.post(uri)
202193
}
203194
Intent.ACTION_SEND -> {

0 commit comments

Comments
 (0)