fix(app/setup): auto skip
This commit is contained in:
@@ -198,7 +198,7 @@ class RemoteSideContext(
|
||||
}
|
||||
}
|
||||
|
||||
if (!sharedPreferences.getBoolean("debug_disable_mapper", false) && (mappings.isMappingsOutdated() || !mappings.isMappingsLoaded)) {
|
||||
if (!sharedPreferences.getBoolean("debug_disable_mapper", false) && mappings.getSnapchatPackageInfo() != null && mappings.isMappingsOutdated()) {
|
||||
requirements = requirements or Requirements.MAPPINGS
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import me.rhunk.snapenhance.RemoteSideContext
|
||||
|
||||
abstract class SetupScreen {
|
||||
lateinit var context: RemoteSideContext
|
||||
lateinit var allowNext: (Boolean) -> Unit
|
||||
lateinit var allowNext: (canGoNext: Boolean) -> Unit
|
||||
lateinit var goNext: () -> Unit
|
||||
lateinit var route: String
|
||||
|
||||
|
||||
@@ -2,10 +2,8 @@ package me.rhunk.snapenhance.ui.setup.screens.impl
|
||||
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.CircularProgressIndicator
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.dp
|
||||
@@ -28,52 +26,38 @@ class MappingsScreen : SetupScreen() {
|
||||
}) {
|
||||
remember { AlertDialogs(context.translation) }.InfoDialog(title = infoText!!) {
|
||||
infoText = null
|
||||
goNext()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun tryToGenerateMappings() {
|
||||
//check for snapchat installation
|
||||
val installationSummary = context.installationSummary
|
||||
if (installationSummary.snapchatInfo == null) {
|
||||
throw Exception(context.translation["setup.mappings.generate_failure_no_snapchat"])
|
||||
}
|
||||
with(context.mappings) {
|
||||
refresh()
|
||||
}
|
||||
}
|
||||
|
||||
var hasMappings by remember { mutableStateOf(false) }
|
||||
|
||||
DialogText(text = context.translation["setup.mappings.dialog"])
|
||||
if (hasMappings) return
|
||||
Button(onClick = {
|
||||
if (isGenerating) return@Button
|
||||
isGenerating = true
|
||||
LaunchedEffect(Unit) {
|
||||
coroutineScope.launch(Dispatchers.IO) {
|
||||
if (isGenerating) return@launch
|
||||
isGenerating = true
|
||||
runCatching {
|
||||
tryToGenerateMappings()
|
||||
allowNext(true)
|
||||
infoText = context.translation["setup.mappings.generate_success"]
|
||||
hasMappings = true
|
||||
if (context.installationSummary.snapchatInfo == null) {
|
||||
throw Exception(context.translation["setup.mappings.generate_failure_no_snapchat"])
|
||||
}
|
||||
context.mappings.refresh()
|
||||
goNext()
|
||||
}.onFailure {
|
||||
isGenerating = false
|
||||
infoText = context.translation["setup.mappings.generate_failure"] + "\n\n" + it.message
|
||||
context.log.error("Failed to generate mappings", it)
|
||||
}
|
||||
}
|
||||
}) {
|
||||
if (isGenerating) {
|
||||
CircularProgressIndicator(
|
||||
modifier = Modifier
|
||||
.padding()
|
||||
.size(30.dp),
|
||||
strokeWidth = 3.dp,
|
||||
color = MaterialTheme.colorScheme.onPrimary
|
||||
)
|
||||
} else {
|
||||
Text(text = context.translation["setup.mappings.generate_button"])
|
||||
}
|
||||
}
|
||||
|
||||
if (isGenerating) {
|
||||
DialogText(text = context.translation["setup.mappings.dialog"])
|
||||
CircularProgressIndicator(
|
||||
modifier = Modifier
|
||||
.padding()
|
||||
.size(50.dp),
|
||||
strokeWidth = 3.dp,
|
||||
color = MaterialTheme.colorScheme.onPrimary
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,17 +17,16 @@ import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.OutlinedCard
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.mutableStateMapOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import me.rhunk.snapenhance.ui.setup.screens.SetupScreen
|
||||
import me.rhunk.snapenhance.ui.util.ActivityLauncherHelper
|
||||
import me.rhunk.snapenhance.ui.util.OnLifecycleEvent
|
||||
|
||||
data class PermissionData(
|
||||
val translationKey: String,
|
||||
@@ -125,12 +124,26 @@ class PermissionsScreen : SetupScreen() {
|
||||
)
|
||||
}
|
||||
|
||||
allowNext(permissions.all { perm -> grantedPermissions[perm.translationKey] == true })
|
||||
|
||||
LaunchedEffect(Unit) {
|
||||
fun updateState() {
|
||||
permissions.forEach { perm ->
|
||||
grantedPermissions[perm.translationKey] = perm.isPermissionGranted()
|
||||
}
|
||||
if (permissions.all { perm -> grantedPermissions[perm.translationKey] == true }) {
|
||||
goNext()
|
||||
}
|
||||
}
|
||||
|
||||
OnLifecycleEvent { _, event ->
|
||||
if (event != Lifecycle.Event.ON_RESUME) return@OnLifecycleEvent
|
||||
updateState()
|
||||
coroutineScope.launch {
|
||||
delay(1000)
|
||||
updateState()
|
||||
}
|
||||
}
|
||||
|
||||
LaunchedEffect(Unit) {
|
||||
updateState()
|
||||
}
|
||||
|
||||
DialogText(text = context.translation["setup.permissions.dialog"])
|
||||
@@ -156,7 +169,11 @@ class PermissionsScreen : SetupScreen() {
|
||||
GrantedIcon()
|
||||
} else {
|
||||
RequestButton {
|
||||
perm.requestPermission(perm)
|
||||
if (perm.isPermissionGranted()) {
|
||||
grantedPermissions[perm.translationKey] = true
|
||||
} else {
|
||||
perm.requestPermission(perm)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,26 +9,13 @@ import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.dp
|
||||
import me.rhunk.snapenhance.ui.setup.screens.SetupScreen
|
||||
import me.rhunk.snapenhance.ui.util.ActivityLauncherHelper
|
||||
import me.rhunk.snapenhance.ui.util.ObservableMutableState
|
||||
import me.rhunk.snapenhance.ui.util.chooseFolder
|
||||
|
||||
class SaveFolderScreen : SetupScreen() {
|
||||
private lateinit var saveFolder: ObservableMutableState<String>
|
||||
|
||||
private lateinit var activityLauncherHelper: ActivityLauncherHelper
|
||||
|
||||
override fun init() {
|
||||
activityLauncherHelper = ActivityLauncherHelper(context.activity!!)
|
||||
saveFolder = ObservableMutableState(
|
||||
defaultValue = "",
|
||||
onChange = { _, newValue ->
|
||||
if (newValue.isNotBlank()) {
|
||||
context.config.root.downloader.saveFolder.set(newValue)
|
||||
context.config.writeConfig()
|
||||
allowNext(true)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
@@ -37,7 +24,10 @@ class SaveFolderScreen : SetupScreen() {
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
Button(onClick = {
|
||||
activityLauncherHelper.chooseFolder {
|
||||
saveFolder.value = it
|
||||
if (it.isBlank()) return@chooseFolder
|
||||
context.config.root.downloader.saveFolder.set(it)
|
||||
context.config.writeConfig()
|
||||
goNext()
|
||||
}
|
||||
}) {
|
||||
Text(text = context.translation["setup.dialogs.select_save_folder_button"])
|
||||
|
||||
@@ -6,11 +6,9 @@
|
||||
"select_save_folder_button": "Select Folder"
|
||||
},
|
||||
"mappings": {
|
||||
"dialog": "To dynamically support a wide range of Snapchat Versions, mappings are necessary for SnapEnhance to function properly, this should not take more than 5 seconds.",
|
||||
"generate_button": "Generate",
|
||||
"dialog": "Generating Mappings, this may take a while ...",
|
||||
"generate_failure_no_snapchat": "SnapEnhance was unable to detect Snapchat, please try reinstalling Snapchat.",
|
||||
"generate_failure": "An error occurred while trying to generate mappings, please try again.",
|
||||
"generate_success": "Mappings generated successfully."
|
||||
"generate_failure": "An error occurred while trying to generate mappings, please try again."
|
||||
},
|
||||
"permissions": {
|
||||
"dialog": "To continue you need to fit the following requirements:",
|
||||
|
||||
Reference in New Issue
Block a user