Always use Private installer to update Private extensions (#3614)
* Use Private installer to update Private extensions This forces the Private installer for any extension which was installed privately, bypassing whichever setting the user selected in Settings > Advanced > Installer. * [skip ci] Changelog entry * [skip ci] Update CHANGELOG.md Co-authored-by: AntsyLich <59261191+AntsyLich@users.noreply.github.com> --------- Co-authored-by: AntsyLich <59261191+AntsyLich@users.noreply.github.com>
This commit is contained in:
@@ -19,6 +19,9 @@ The format is a modified version of [Keep a Changelog](https://keepachangelog.co
|
||||
### Changed
|
||||
- Detect Shizuku with permission check ([@Small-Ku](https://github.com/Small-Ku)) ([#3565](https://github.com/mihonapp/mihon/pull/3565))
|
||||
|
||||
### Improved
|
||||
- Always use Private installer to update privately installed extensions ([@MajorTanya](https://github.com/MajorTanya)) ([#3614](https://github.com/mihonapp/mihon/pull/3614))
|
||||
|
||||
### Fixed
|
||||
- Fixed app bars remaining visible after changing pages by tapping in the paged reader after using the chapter navigator slider ([@AntsyLich](https://github.com/AntsyLich)) ([#3567](https://github.com/mihonapp/mihon/pull/3567))
|
||||
- Fixed MangaBaka User Agent string ([@MajorTanya](https://github.com/MajorTanya)) ([#3578](https://github.com/mihonapp/mihon/pull/3578))
|
||||
|
||||
@@ -240,7 +240,8 @@ class ExtensionManager(
|
||||
*/
|
||||
fun updateExtension(extension: Extension.Installed): Flow<InstallStep> {
|
||||
val availableExt = availableExtensionMapFlow.value[extension.pkgName] ?: return emptyFlow()
|
||||
return installExtension(availableExt)
|
||||
val isUpdateForPrivatelyInstalled = !extension.isShared
|
||||
return installer.downloadAndInstall(availableExt.apkUrl, availableExt, isUpdateForPrivatelyInstalled)
|
||||
}
|
||||
|
||||
fun cancelInstallUpdateExtension(extension: Extension) {
|
||||
|
||||
@@ -49,8 +49,13 @@ internal class ExtensionInstaller(
|
||||
*
|
||||
* @param url The url of the apk.
|
||||
* @param extension The extension to install.
|
||||
* @param isUpdateForPrivatelyInstalled If this is an update for a privately installed extension
|
||||
*/
|
||||
fun downloadAndInstall(url: String, extension: Extension): Flow<InstallStep> {
|
||||
fun downloadAndInstall(
|
||||
url: String,
|
||||
extension: Extension,
|
||||
isUpdateForPrivatelyInstalled: Boolean = false,
|
||||
): Flow<InstallStep> {
|
||||
val downloadId = extension.pkgName.hashCode().toLong()
|
||||
cancelInstall(extension.pkgName)
|
||||
|
||||
@@ -74,7 +79,7 @@ internal class ExtensionInstaller(
|
||||
}
|
||||
|
||||
step.value = InstallStep.Installing
|
||||
installApk(downloadId, tmpFile)
|
||||
installApk(downloadId, tmpFile, isUpdateForPrivatelyInstalled)
|
||||
} catch (e: Exception) {
|
||||
if (e is InterruptedException) {
|
||||
// Canceled
|
||||
@@ -99,8 +104,14 @@ internal class ExtensionInstaller(
|
||||
* Starts an intent to install the extension at the given uri.
|
||||
*
|
||||
* @param tempFile The file of the extension to install. Delete after use.
|
||||
* @param isUpdateForPrivatelyInstalled If this install is an update for a privately installed extension
|
||||
*/
|
||||
private fun installApk(downloadId: Long, tempFile: File) {
|
||||
private fun installApk(downloadId: Long, tempFile: File, isUpdateForPrivatelyInstalled: Boolean = false) {
|
||||
if (isUpdateForPrivatelyInstalled) {
|
||||
installApkPrivately(downloadId, tempFile)
|
||||
return
|
||||
}
|
||||
|
||||
when (val installer = extensionInstaller.get()) {
|
||||
BasePreferences.ExtensionInstaller.LEGACY -> {
|
||||
val intent = Intent(context, ExtensionInstallActivity::class.java)
|
||||
@@ -110,7 +121,24 @@ internal class ExtensionInstaller(
|
||||
|
||||
context.startActivity(intent)
|
||||
}
|
||||
|
||||
BasePreferences.ExtensionInstaller.PRIVATE -> {
|
||||
installApkPrivately(downloadId, tempFile)
|
||||
}
|
||||
|
||||
else -> {
|
||||
val intent = ExtensionInstallService.getIntent(
|
||||
context,
|
||||
downloadId,
|
||||
tempFile.getUriCompat(context),
|
||||
installer,
|
||||
)
|
||||
ContextCompat.startForegroundService(context, intent)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun installApkPrivately(downloadId: Long, tempFile: File) {
|
||||
try {
|
||||
if (ExtensionLoader.installPrivateExtensionFile(context, tempFile)) {
|
||||
updateInstallStep(downloadId, InstallStep.Installed)
|
||||
@@ -124,17 +152,6 @@ internal class ExtensionInstaller(
|
||||
|
||||
tempFile.delete()
|
||||
}
|
||||
else -> {
|
||||
val intent = ExtensionInstallService.getIntent(
|
||||
context,
|
||||
downloadId,
|
||||
tempFile.getUriCompat(context),
|
||||
installer,
|
||||
)
|
||||
ContextCompat.startForegroundService(context, intent)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancels extension install and remove from download manager and installer.
|
||||
|
||||
Reference in New Issue
Block a user