Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// SPDX-License-Identifier: GPL-3.0-only
package helium314.keyboard.settings

import helium314.keyboard.latin.utils.getActivity
import androidx.compose.ui.platform.LocalContext
import androidx.activity.compose.BackHandler
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.foundation.layout.Box
Expand Down Expand Up @@ -301,7 +303,9 @@ fun <T: Any?> SearchScreen(
showSearch = value
if (!value) searchText = TextFieldValue()
}
BackHandler {
// the wizard covers this screen and handles Back itself
val wizardShowing = (LocalContext.current.getActivity() as? SettingsActivity)?.welcomeWizardShowing == true
BackHandler(enabled = !wizardShowing) {
if (showSearch || searchText.text.isNotEmpty()) setShowSearch(false)
else onClickBack()
}
Expand Down
24 changes: 19 additions & 5 deletions app/src/main/java/helium314/keyboard/settings/WelcomeWizard.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// SPDX-License-Identifier: GPL-3.0-only
package helium314.keyboard.settings

import helium314.keyboard.latin.utils.getActivity
import androidx.activity.compose.BackHandler
import helium314.keyboard.latin.common.LocaleUtils.localizedDisplayName
import java.io.File
import android.view.inputmethod.InputMethodSubtype
Expand Down Expand Up @@ -84,6 +86,20 @@ fun WelcomeWizard(
}
var step by rememberSaveable { mutableIntStateOf(determineStep()) }
var requiresRestart by rememberSaveable { mutableStateOf(false) }
// a loaded library or plugin only works after a restart, so every way out of the wizard restarts
fun restartIfNeeded() {
if (!requiresRestart) return
ctx.prefs().edit(commit = true) {} // flush pending writes before the process ends
Runtime.getRuntime().exit(0)
}
BackHandler(enabled = requiresRestart) {
ctx.getActivity()?.finish()
restartIfNeeded()
}
val skip = {
close()
restartIfNeeded()
}
var refreshTrigger by remember { mutableIntStateOf(0) }

LaunchedEffect(step) {
Expand Down Expand Up @@ -177,7 +193,7 @@ fun WelcomeWizard(
Text(stringResource(R.string.setup_step_previous))
}
} else {
androidx.compose.material3.TextButton(onClick = close) {
androidx.compose.material3.TextButton(onClick = skip) {
Text(stringResource(R.string.setup_skip_action))
}
}
Expand All @@ -196,7 +212,7 @@ fun WelcomeWizard(

@Composable fun steps() {
if (step == 0)
Step0(onClick = { step = 1 }, onSkip = close)
Step0(onClick = { step = 1 }, onSkip = skip)
else
Column(Modifier.fillMaxSize()) {
val launcher = rememberLauncherForActivityResult(ActivityResultContracts.StartActivityForResult()) {
Expand Down Expand Up @@ -449,9 +465,7 @@ fun WelcomeWizard(
}
}
finish()
if (requiresRestart) {
Runtime.getRuntime().exit(0)
}
restartIfNeeded()
},
{ step-- }
) {
Expand Down
Loading