Skip to content

Commit

Permalink
fix: separate same-name extension's installing status from different …
Browse files Browse the repository at this point in the history
…repos (#295)
  • Loading branch information
cuong-tran authored Aug 26, 2024
1 parent 228abc3 commit a876742
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,12 @@ class ExtensionManager(
}

fun cancelInstallUpdateExtension(extension: Extension) {
installer.cancelInstall(extension.pkgName)
installer.cancelInstall(
extension.pkgName +
// KMK -->
":${extension.signatureHash}",
// KMK <--
)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ internal class ExtensionInstaller(private val context: Context) {
* @param extension The extension to install.
*/
fun downloadAndInstall(url: String, extension: Extension): Flow<InstallStep> {
val pkgName = extension.pkgName
val pkgName = extension.pkgName +
// KMK -->
":${extension.signatureHash}"
// KMK <--

val oldDownload = activeDownloads[pkgName]
if (oldDownload != null) {
Expand Down Expand Up @@ -236,7 +239,7 @@ internal class ExtensionInstaller(private val context: Context) {
/**
* Deletes the download for the given package name.
*
* @param pkgName The package name of the download to delete.
* @param pkgName The package name of the download to delete together with its signature.
*/
private fun deleteDownload(pkgName: String) {
val downloadId = activeDownloads.remove(pkgName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,15 @@ class ExtensionsScreenModel(
val context = Injekt.get<Application>()
val extensionMapper: (Map<String, InstallStep>) -> ((Extension) -> ExtensionUiModel.Item) = { map ->
{
ExtensionUiModel.Item(it, map[it.pkgName] ?: InstallStep.Idle)
ExtensionUiModel.Item(
it,
map[
it.pkgName +
// KMK -->
":${it.signatureHash}",
// KMK <--
] ?: InstallStep.Idle,
)
}
}
val queryFilter: (String) -> ((Extension) -> Boolean) = { query ->
Expand Down Expand Up @@ -193,11 +201,26 @@ class ExtensionsScreenModel(
}

private fun addDownloadState(extension: Extension, installStep: InstallStep) {
currentDownloads.update { it + Pair(extension.pkgName, installStep) }
currentDownloads.update {
it + Pair(
extension.pkgName +
// KMK -->
":${extension.signatureHash}",
// KMK <--
installStep,
)
}
}

private fun removeDownloadState(extension: Extension) {
currentDownloads.update { it - extension.pkgName }
currentDownloads.update {
it - (
extension.pkgName +
// KMK -->
":${extension.signatureHash}"
// KMK <--
)
}
}

private suspend fun Flow<InstallStep>.collectToInstallUpdate(extension: Extension) =
Expand Down

0 comments on commit a876742

Please sign in to comment.