File tree 3 files changed +45
-1
lines changed
kotlin/com/aliucord/manager/ui
3 files changed +45
-1
lines changed Original file line number Diff line number Diff line change 2
2
<manifest xmlns : android =" http://schemas.android.com/apk/res/android"
3
3
xmlns : tools =" http://schemas.android.com/tools" >
4
4
5
- <uses-permission android : name =" android.permission.ACCESS_NETWORK_STATE" />
6
5
<uses-permission android : name =" android.permission.INTERNET" />
6
+ <uses-permission android : name =" android.permission.WAKE_LOCK" />
7
+ <uses-permission android : name =" android.permission.ACCESS_NETWORK_STATE" />
7
8
<uses-permission android : name =" android.permission.REQUEST_INSTALL_PACKAGES" />
8
9
<uses-permission android : name =" android.permission.REQUEST_DELETE_PACKAGES" />
9
10
<uses-permission android : name =" android.permission.UPDATE_PACKAGES_WITHOUT_USER_ACTION" />
Original file line number Diff line number Diff line change
1
+ package com.aliucord.manager.ui.components
2
+
3
+ import android.app.Activity
4
+ import android.content.Context
5
+ import android.content.ContextWrapper
6
+ import android.view.WindowManager
7
+ import androidx.compose.runtime.Composable
8
+ import androidx.compose.runtime.DisposableEffect
9
+ import androidx.compose.ui.platform.LocalContext
10
+
11
+ /* *
12
+ * Maintain an active screen wakelock as long as [active] is true and this component is in scope.
13
+ */
14
+ @Composable
15
+ fun Wakelock (active : Boolean = false) {
16
+ val context = LocalContext .current
17
+ DisposableEffect (active) {
18
+ val window = context.findActivity()?.window
19
+
20
+ if (active) {
21
+ window?.addFlags(WindowManager .LayoutParams .FLAG_KEEP_SCREEN_ON )
22
+ } else {
23
+ window?.clearFlags(WindowManager .LayoutParams .FLAG_KEEP_SCREEN_ON )
24
+ }
25
+
26
+ onDispose {
27
+ window?.clearFlags(WindowManager .LayoutParams .FLAG_KEEP_SCREEN_ON )
28
+ }
29
+ }
30
+ }
31
+
32
+ private fun Context.findActivity (): Activity ? {
33
+ var context = this
34
+ while (context is ContextWrapper ) {
35
+ if (context is Activity ) return context
36
+ context = context.baseContext
37
+ }
38
+ return null
39
+ }
Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ import cafe.adriel.voyager.navigator.LocalNavigator
25
25
import cafe.adriel.voyager.navigator.currentOrThrow
26
26
import com.aliucord.manager.R
27
27
import com.aliucord.manager.installer.steps.StepGroup
28
+ import com.aliucord.manager.ui.components.Wakelock
28
29
import com.aliucord.manager.ui.components.back
29
30
import com.aliucord.manager.ui.components.dialogs.InstallerAbortDialog
30
31
import com.aliucord.manager.ui.screens.install.components.StepGroupCard
@@ -45,6 +46,9 @@ class InstallScreen(private val data: InstallOptions) : Screen {
45
46
navigator.back(currentActivity = null )
46
47
}
47
48
49
+ // Prevent screen from turning off while working
50
+ Wakelock (active = state.value is InstallScreenState .Working )
51
+
48
52
// Exit warning dialog (dismiss itself if install process state changes, esp. for Success)
49
53
var showAbortWarning by remember(model.state.collectAsState()) { mutableStateOf(false ) }
50
54
You can’t perform that action at this time.
0 commit comments