mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-21 05:46:03 +00:00
feat: make desktop mode easy to uninstall safely (#1311)
This commit is contained in:
1 parent
d012a1f5b6
commit
22f7d5b909
6 files changed
+266
-7
No files matched your search
@@ -118,7 +118,8 @@ object DesktopCatalog {
|
||||
|
||||
fun desktopPresent(context: Context): Boolean {
|
||||
val root = LinuxRuntime.rootDir(context)
|
||||
return File(root, DesktopRemoval.PENDING).exists() || marker(context, DESKTOP_ID).exists()
|
||||
return File(root, DesktopRemoval.PENDING).exists() || marker(context, DESKTOP_ID).exists() ||
|
||||
journal(root, DESKTOP_ID).exists()
|
||||
}
|
||||
|
||||
fun desktopSize(context: Context): Long = DesktopRemoval.installedSize(context)
|
||||
@@ -126,8 +127,21 @@ object DesktopCatalog {
|
||||
fun cleanLegacy(context: Context, listener: LinuxRuntimeInstaller.ProgressListener? = null) =
|
||||
DesktopRemoval.cleanLegacy(context, listener)
|
||||
|
||||
fun removeDesktop(context: Context, listener: LinuxRuntimeInstaller.ProgressListener): String? =
|
||||
fun removeDesktop(context: Context, listener: LinuxRuntimeInstaller.ProgressListener): String? = synchronized(installLock) {
|
||||
DesktopRemoval.remove(context, listener)
|
||||
}
|
||||
|
||||
internal fun discardDesktopInstall(context: Context) {
|
||||
val entry = interrupted(context).firstOrNull { it.id == DESKTOP_ID }
|
||||
val journal = journal(LinuxRuntime.rootDir(context), DESKTOP_ID)
|
||||
entry?.let {
|
||||
val download = downloadFile(context, it)
|
||||
for (file in listOf(download, File(download.path + ".resume.properties"))) {
|
||||
check(!file.exists() || file.delete()) { "Could not remove desktop download ${file.name}" }
|
||||
}
|
||||
}
|
||||
check(!journal.exists() || journal.delete()) { "Could not clear desktop installation" }
|
||||
}
|
||||
|
||||
fun install(context: Context, entry: Entry, listener: LinuxRuntimeInstaller.ProgressListener?): String? = synchronized(installLock) {
|
||||
installLocked(context, entry, listener)
|
||||
|
||||
@@ -44,9 +44,10 @@ internal object DesktopRemoval {
|
||||
val root = LinuxRuntime.rootDir(context)
|
||||
val pending = File(root, PENDING)
|
||||
val marker = File(root, ".droiddeck-pkg-${DesktopCatalog.DESKTOP_ID}")
|
||||
val version = FileUtils.readString(pending)?.trim() ?: FileUtils.readString(marker)?.trim()
|
||||
val installing = DesktopCatalog.interrupted(root).firstOrNull { it.id == DesktopCatalog.DESKTOP_ID }
|
||||
val version = FileUtils.readString(pending)?.trim() ?: installing?.version ?: FileUtils.readString(marker)?.trim()
|
||||
val versions = context.assets.open("desktop-removal/versions.txt").bufferedReader().use { it.readLines() }
|
||||
check(version in versions) { context.getString(R.string.desktop_removal_unknown) }
|
||||
check(version in versions && (installing == null || installing.version in versions)) { context.getString(R.string.desktop_removal_unknown) }
|
||||
val entries = lines(context, "kde-remove.tsv.gzip").map(DesktopFileRemoval.Entry::parse)
|
||||
val keep = protected(context, root)
|
||||
cleanLegacy(context, listener)
|
||||
@@ -63,6 +64,7 @@ internal object DesktopRemoval {
|
||||
if (!target.delete()) error("Could not remove $path")
|
||||
}
|
||||
}
|
||||
DesktopCatalog.discardDesktopInstall(context)
|
||||
if (!pending.delete()) error("Could not finish desktop removal")
|
||||
Log.i("DesktopRemoval", "KDE: $result")
|
||||
listener.onProgress(context.getString(R.string.desktop_removed), 100)
|
||||
|
||||
Reference in new issue
Block a user