This commit is contained in:
Ax333l 2024-12-21 20:56:12 +01:00
parent 1982ac27e2
commit 1231bc106c
No known key found for this signature in database
GPG Key ID: D2B4D85271127D23
4 changed files with 24 additions and 10 deletions

View File

@ -29,9 +29,7 @@ class Filesystem(private val app: Application) {
* This is the same as [tempDir], but does not get cleared on system-initiated process death. * This is the same as [tempDir], but does not get cleared on system-initiated process death.
* Paths to this directory can be safely stored in parcels. * Paths to this directory can be safely stored in parcels.
*/ */
val uiTempDir: File = app.getDir("ui_ephemeral", Context.MODE_PRIVATE).apply { val uiTempDir: File = app.getDir("ui_ephemeral", Context.MODE_PRIVATE)
mkdirs()
}
fun externalFilesDir(): Path = Environment.getExternalStorageDirectory().toPath() fun externalFilesDir(): Path = Environment.getExternalStorageDirectory().toPath()

View File

@ -45,7 +45,11 @@ fun PatcherScreen(
onBackClick: () -> Unit, onBackClick: () -> Unit,
vm: PatcherViewModel vm: PatcherViewModel
) { ) {
BackHandler(onBack = onBackClick) fun leaveScreen() {
vm.onBack()
onBackClick()
}
BackHandler(onBack = ::leaveScreen)
val context = LocalContext.current val context = LocalContext.current
val exportApkLauncher = val exportApkLauncher =
@ -107,7 +111,7 @@ fun PatcherScreen(
topBar = { topBar = {
AppTopBar( AppTopBar(
title = stringResource(R.string.patcher), title = stringResource(R.string.patcher),
onBackClick = onBackClick onBackClick = ::leaveScreen
) )
}, },
bottomBar = { bottomBar = {

View File

@ -6,8 +6,11 @@ import android.net.Uri
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue import androidx.compose.runtime.setValue
import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import androidx.lifecycle.viewmodel.compose.SavedStateHandleSaveableApi
import androidx.lifecycle.viewmodel.compose.saveable
import app.revanced.manager.R import app.revanced.manager.R
import app.revanced.manager.data.platform.Filesystem import app.revanced.manager.data.platform.Filesystem
import app.revanced.manager.domain.repository.PatchBundleRepository import app.revanced.manager.domain.repository.PatchBundleRepository
@ -23,13 +26,20 @@ import kotlinx.coroutines.withContext
import java.io.File import java.io.File
import java.nio.file.Files import java.nio.file.Files
@OptIn(SavedStateHandleSaveableApi::class)
class AppSelectorViewModel( class AppSelectorViewModel(
private val app: Application, private val app: Application,
private val pm: PM, private val pm: PM,
fs: Filesystem, fs: Filesystem,
private val patchBundleRepository: PatchBundleRepository private val patchBundleRepository: PatchBundleRepository,
savedStateHandle: SavedStateHandle,
) : ViewModel() { ) : ViewModel() {
private val inputFile = File(fs.uiTempDir, "input.apk").also(File::delete) private val inputFile = savedStateHandle.saveable(key = "inputFile") {
File(
fs.uiTempDir,
"input.apk"
).also(File::delete)
}
val appList = pm.appList val appList = pm.appList
private val storageSelectionChannel = Channel<SelectedApp.Local>() private val storageSelectionChannel = Channel<SelectedApp.Local>()

View File

@ -10,7 +10,6 @@ import android.net.Uri
import android.os.ParcelUuid import android.os.ParcelUuid
import android.util.Log import android.util.Log
import androidx.activity.result.ActivityResult import androidx.activity.result.ActivityResult
import androidx.compose.runtime.Stable
import androidx.compose.runtime.derivedStateOf import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.mutableStateOf
@ -65,12 +64,12 @@ import kotlinx.coroutines.launch
import kotlinx.coroutines.time.withTimeout import kotlinx.coroutines.time.withTimeout
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import org.koin.core.component.KoinComponent import org.koin.core.component.KoinComponent
import org.koin.core.component.get
import org.koin.core.component.inject import org.koin.core.component.inject
import java.io.File import java.io.File
import java.nio.file.Files import java.nio.file.Files
import java.time.Duration import java.time.Duration
@Stable
@OptIn(SavedStateHandleSaveableApi::class, PluginHostApi::class) @OptIn(SavedStateHandleSaveableApi::class, PluginHostApi::class)
class PatcherViewModel( class PatcherViewModel(
private val input: Destination.Patcher private val input: Destination.Patcher
@ -81,7 +80,7 @@ class PatcherViewModel(
private val workerRepository: WorkerRepository by inject() private val workerRepository: WorkerRepository by inject()
private val installedAppRepository: InstalledAppRepository by inject() private val installedAppRepository: InstalledAppRepository by inject()
private val rootInstaller: RootInstaller by inject() private val rootInstaller: RootInstaller by inject()
private val savedStateHandle: SavedStateHandle by inject() private val savedStateHandle: SavedStateHandle = get()
private var installedApp: InstalledApp? = null private var installedApp: InstalledApp? = null
val packageName = input.selectedApp.packageName val packageName = input.selectedApp.packageName
@ -325,7 +324,10 @@ class PatcherViewModel(
} }
} }
} }
}
fun onBack() {
// tempDir cannot be deleted inside onCleared because it gets called on system-initiated process death.
tempDir.deleteRecursively() tempDir.deleteRecursively()
} }