Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Temporarily use DEFAULT if SHIZUKU permissions are not granted #15

Merged
merged 2 commits into from
Jan 16, 2025
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
Expand Up @@ -7,10 +7,12 @@ import app.revenge.manager.domain.manager.PreferenceManager
import app.revenge.manager.installer.Installer
import app.revenge.manager.installer.session.SessionInstaller
import app.revenge.manager.installer.shizuku.ShizukuInstaller
import app.revenge.manager.installer.shizuku.ShizukuPermissions
import app.revenge.manager.installer.step.Step
import app.revenge.manager.installer.step.StepGroup
import app.revenge.manager.installer.step.StepRunner
import app.revenge.manager.utils.isMiui
import app.revenge.manager.utils.showToast
import org.koin.core.component.inject
import java.io.File

Expand Down Expand Up @@ -38,7 +40,15 @@ class InstallStep(
?.takeIf { it.isNotEmpty() }
?: throw Error("Missing APKs from LSPatch step; failure likely")

val installer: Installer = when (preferences.installMethod) {
val installMethod = if (preferences.installMethod == InstallMethod.SHIZUKU && !ShizukuPermissions.waitShizukuPermissions()) {
// Temporarily use DEFAULT if SHIZUKU permissions are not granted
context.showToast(R.string.msg_shizuku_denied)
InstallMethod.DEFAULT
} else {
preferences.installMethod
}

val installer: Installer = when (installMethod) {
InstallMethod.DEFAULT -> SessionInstaller(context)
InstallMethod.SHIZUKU -> ShizukuInstaller(context)
}
Expand Down
22 changes: 2 additions & 20 deletions app/src/main/java/app/revenge/manager/ui/activity/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,15 @@ import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.core.app.ActivityCompat
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.lifecycle.lifecycleScope
import cafe.adriel.voyager.navigator.Navigator
import cafe.adriel.voyager.transitions.SlideTransition
import app.revenge.manager.domain.manager.InstallMethod
import app.revenge.manager.domain.manager.PreferenceManager
import app.revenge.manager.installer.shizuku.ShizukuPermissions
import app.revenge.manager.ui.screen.home.HomeScreen
import app.revenge.manager.ui.screen.installer.InstallerScreen
import app.revenge.manager.ui.theme.RevengeManagerTheme
import app.revenge.manager.utils.DiscordVersion
import app.revenge.manager.utils.Intents
import kotlinx.coroutines.launch
import org.koin.android.ext.android.inject
import cafe.adriel.voyager.navigator.Navigator
import cafe.adriel.voyager.transitions.SlideTransition

class MainActivity : ComponentActivity() {

private val preferences: PreferenceManager by inject()

override fun onCreate(savedInstanceState: Bundle?) {
installSplashScreen()
enableEdgeToEdge()
Expand All @@ -40,14 +31,6 @@ class MainActivity : ComponentActivity() {
)
}

if (preferences.installMethod == InstallMethod.SHIZUKU) {
lifecycleScope.launch {
if (!ShizukuPermissions.waitShizukuPermissions()) {
preferences.installMethod = InstallMethod.DEFAULT
}
}
}
oSumAtrIX marked this conversation as resolved.
Show resolved Hide resolved

val screen = if (intent.action == Intents.Actions.INSTALL && version != null) {
InstallerScreen(DiscordVersion.fromVersionCode(version)!!)
} else {
Expand All @@ -62,5 +45,4 @@ class MainActivity : ComponentActivity() {
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import androidx.paging.Pager
import androidx.paging.PagingConfig
import androidx.paging.cachedIn
import app.revenge.manager.BuildConfig
import cafe.adriel.voyager.core.model.ScreenModel
import cafe.adriel.voyager.core.model.screenModelScope
import app.revenge.manager.R
import app.revenge.manager.domain.manager.DownloadManager
import app.revenge.manager.domain.manager.InstallManager
import app.revenge.manager.domain.manager.InstallMethod
Expand All @@ -22,12 +21,16 @@ import app.revenge.manager.domain.repository.RestRepository
import app.revenge.manager.installer.Installer
import app.revenge.manager.installer.session.SessionInstaller
import app.revenge.manager.installer.shizuku.ShizukuInstaller
import app.revenge.manager.installer.shizuku.ShizukuPermissions
import app.revenge.manager.network.dto.Release
import app.revenge.manager.network.utils.CommitsPagingSource
import app.revenge.manager.network.utils.dataOrNull
import app.revenge.manager.network.utils.ifSuccessful
import app.revenge.manager.utils.DiscordVersion
import app.revenge.manager.utils.isMiui
import app.revenge.manager.utils.showToast
import cafe.adriel.voyager.core.model.ScreenModel
import cafe.adriel.voyager.core.model.screenModelScope
import kotlinx.coroutines.launch
import java.io.File

Expand All @@ -52,7 +55,9 @@ class HomeViewModel(

var showUpdateDialog by mutableStateOf(false)
var isUpdating by mutableStateOf(false)
val commits = Pager(PagingConfig(pageSize = 30)) { CommitsPagingSource(repo) }.flow.cachedIn(screenModelScope)
val commits = Pager(PagingConfig(pageSize = 30)) { CommitsPagingSource(repo) }.flow.cachedIn(
screenModelScope
)

init {
getDiscordVersions()
Expand Down Expand Up @@ -129,7 +134,15 @@ class HomeViewModel(
downloadManager.downloadUpdate(update)
isUpdating = false

val installer: Installer = when (prefs.installMethod) {
val installMethod = if (prefs.installMethod == InstallMethod.SHIZUKU && !ShizukuPermissions.waitShizukuPermissions()) {
// Temporarily use DEFAULT if SHIZUKU permissions are not granted
context.showToast(R.string.msg_shizuku_denied)
InstallMethod.DEFAULT
} else {
prefs.installMethod
}

val installer: Installer = when (installMethod) {
InstallMethod.DEFAULT -> SessionInstaller(context)
InstallMethod.SHIZUKU -> ShizukuInstaller(context)
}
Expand Down
Loading