fix permission poups and add settings to see permission state
This commit is contained in:
@@ -83,8 +83,26 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
|
||||
_uiState.update { it.copy(isoDirectory = savedDirectory, currentPath = savedDirectory) }
|
||||
navigationStack.add(savedDirectory)
|
||||
|
||||
// Check root access (don't request, just check - wizard handles requesting)
|
||||
val hasRoot = RootManager.hasRoot()
|
||||
// First check cached root status (no popup) - user may have granted in Magisk settings
|
||||
val cachedRootStatus = RootManager.isRootGrantedCached()
|
||||
|
||||
val hasRoot = when {
|
||||
// If cached status says granted, root is available
|
||||
cachedRootStatus == true -> true
|
||||
// If cached status says denied, check if user wants to retry
|
||||
cachedRootStatus == false -> false
|
||||
// If unknown, check preference from wizard
|
||||
else -> {
|
||||
val prefs = getApplication<android.app.Application>()
|
||||
.getSharedPreferences("iso_drive_prefs", android.content.Context.MODE_PRIVATE)
|
||||
val rootGrantedInWizard = prefs.getBoolean("root_granted", false)
|
||||
if (rootGrantedInWizard) {
|
||||
RootManager.hasRoot()
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
_uiState.update { it.copy(hasRoot = hasRoot) }
|
||||
|
||||
if (hasRoot) {
|
||||
@@ -267,6 +285,72 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
|
||||
return navigationStack.size > 1
|
||||
}
|
||||
|
||||
fun requestRootAccess() {
|
||||
viewModelScope.launch {
|
||||
val granted = RootManager.requestRoot()
|
||||
if (granted) {
|
||||
// Save to preferences
|
||||
getApplication<android.app.Application>()
|
||||
.getSharedPreferences("iso_drive_prefs", android.content.Context.MODE_PRIVATE)
|
||||
.edit()
|
||||
.putBoolean("root_granted", true)
|
||||
.apply()
|
||||
|
||||
// Re-initialize with root
|
||||
_uiState.update { it.copy(hasRoot = true, rootDenied = false) }
|
||||
isoDriveManager.initialize()
|
||||
|
||||
val supportStatus = isoDriveManager.isSupported()
|
||||
val isSupported = supportStatus == SupportStatus.CONFIGFS_SUPPORTED ||
|
||||
supportStatus == SupportStatus.SYSFS_SUPPORTED
|
||||
|
||||
_uiState.update { it.copy(isSupported = isSupported) }
|
||||
|
||||
if (isSupported) {
|
||||
loadFiles()
|
||||
checkMountStatus()
|
||||
}
|
||||
|
||||
_uiState.update { it.copy(successMessage = "Root access granted") }
|
||||
} else {
|
||||
// User denied root access
|
||||
_uiState.update { it.copy(rootDenied = true) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun refreshRootStatus() {
|
||||
viewModelScope.launch {
|
||||
// Check cached status (no popup)
|
||||
val cachedStatus = RootManager.isRootGrantedCached()
|
||||
if (cachedStatus == true && !_uiState.value.hasRoot) {
|
||||
// Root was granted externally (e.g., in Magisk settings)
|
||||
_uiState.update { it.copy(hasRoot = true, rootDenied = false) }
|
||||
|
||||
// Save to preferences
|
||||
getApplication<android.app.Application>()
|
||||
.getSharedPreferences("iso_drive_prefs", android.content.Context.MODE_PRIVATE)
|
||||
.edit()
|
||||
.putBoolean("root_granted", true)
|
||||
.apply()
|
||||
|
||||
// Initialize if needed
|
||||
isoDriveManager.initialize()
|
||||
|
||||
val supportStatus = isoDriveManager.isSupported()
|
||||
val isSupported = supportStatus == SupportStatus.CONFIGFS_SUPPORTED ||
|
||||
supportStatus == SupportStatus.SYSFS_SUPPORTED
|
||||
|
||||
_uiState.update { it.copy(isSupported = isSupported) }
|
||||
|
||||
if (isSupported) {
|
||||
loadFiles()
|
||||
checkMountStatus()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun clearError() {
|
||||
_uiState.update { it.copy(errorMessage = null) }
|
||||
}
|
||||
@@ -279,6 +363,7 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
|
||||
data class MainUiState(
|
||||
val isLoading: Boolean = true,
|
||||
val hasRoot: Boolean = false,
|
||||
val rootDenied: Boolean = false, // True if user denied root in Magisk
|
||||
val isSupported: Boolean = false,
|
||||
val mountStatus: MountStatus = MountStatus.UNMOUNTED,
|
||||
val isoFiles: List<IsoFile> = emptyList(),
|
||||
|
||||
Reference in New Issue
Block a user