Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import co.touchlab.kermit.Logger
import zed.rainxch.core.domain.model.AssetArchitectureMatcher
import zed.rainxch.core.domain.model.GithubAsset
import zed.rainxch.core.domain.model.SystemArchitecture
import zed.rainxch.core.domain.system.InstallOutcome
import zed.rainxch.core.domain.system.Installer
import zed.rainxch.core.domain.system.InstallerInfoExtractor
import java.io.File
Expand Down Expand Up @@ -134,7 +135,7 @@ class AndroidInstaller(
override suspend fun install(
filePath: String,
extOrMime: String,
) {
): InstallOutcome {
val file = File(filePath)
if (!file.exists()) {
throw IllegalStateException("APK file not found: $filePath")
Expand All @@ -158,6 +159,8 @@ class AndroidInstaller(
} else {
throw IllegalStateException("No installer available on this device")
}

return InstallOutcome.DELEGATED_TO_SYSTEM
}

override fun uninstall(packageName: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import zed.rainxch.core.domain.model.GithubAsset
import zed.rainxch.core.domain.model.InstallerType
import zed.rainxch.core.domain.model.SystemArchitecture
import zed.rainxch.core.domain.repository.TweaksRepository
import zed.rainxch.core.domain.system.InstallOutcome
import zed.rainxch.core.domain.system.Installer
import zed.rainxch.core.domain.system.InstallerInfoExtractor

Expand Down Expand Up @@ -97,7 +98,7 @@ class ShizukuInstallerWrapper(
override suspend fun install(
filePath: String,
extOrMime: String,
) {
): InstallOutcome {
Logger.d(TAG) { "install() called — filePath=$filePath, extOrMime=$extOrMime" }
Logger.d(TAG) { "cachedInstallerType=$cachedInstallerType, shizukuStatus=${shizukuServiceManager.status.value}" }

Expand All @@ -122,7 +123,7 @@ class ShizukuInstallerWrapper(
Logger.d(TAG) { "Shizuku installPackage() returned: $result" }
if (result == 0) {
Logger.d(TAG) { "Shizuku install SUCCEEDED for: $filePath" }
return
return InstallOutcome.COMPLETED
}
Logger.w(TAG) { "Shizuku install FAILED with code: $result, falling back to standard installer" }
} else {
Expand All @@ -137,7 +138,7 @@ class ShizukuInstallerWrapper(

Logger.d(TAG) { "Using standard AndroidInstaller for: $filePath" }
androidInstaller.ensurePermissionsOrThrow(extOrMime)
androidInstaller.install(filePath, extOrMime)
return androidInstaller.install(filePath, extOrMime)
}

override fun uninstall(packageName: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import zed.rainxch.core.domain.model.AssetArchitectureMatcher
import zed.rainxch.core.domain.model.GithubAsset
import zed.rainxch.core.domain.model.Platform
import zed.rainxch.core.domain.model.SystemArchitecture
import zed.rainxch.core.domain.system.InstallOutcome
import zed.rainxch.core.domain.system.Installer
import zed.rainxch.core.domain.system.InstallerInfoExtractor
import java.awt.Desktop
Expand Down Expand Up @@ -353,21 +354,24 @@ class DesktopInstaller(
override suspend fun install(
filePath: String,
extOrMime: String,
) = withContext(Dispatchers.IO) {
val file = File(filePath)
if (!file.exists()) {
throw IllegalStateException("File not found: $filePath")
}
): InstallOutcome =
withContext(Dispatchers.IO) {
val file = File(filePath)
if (!file.exists()) {
throw IllegalStateException("File not found: $filePath")
}

val ext = extOrMime.lowercase().removePrefix(".")
val ext = extOrMime.lowercase().removePrefix(".")

when (platform) {
Platform.WINDOWS -> installWindows(file, ext)
Platform.MACOS -> installMacOS(file, ext)
Platform.LINUX -> installLinux(file, ext)
else -> throw UnsupportedOperationException("Installation not supported on $platform")
when (platform) {
Platform.WINDOWS -> installWindows(file, ext)
Platform.MACOS -> installMacOS(file, ext)
Platform.LINUX -> installLinux(file, ext)
else -> throw UnsupportedOperationException("Installation not supported on $platform")
}

InstallOutcome.DELEGATED_TO_SYSTEM
}
Comment on lines 354 to 374
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Return COMPLETED for the synchronous desktop paths.

This now always reports DELEGATED_TO_SYSTEM, but several branches finish before install(...) returns: installAppImage(), successful installDebPackage() / installRpmPackage() runs, and the successful .pkg flow that waits for installer. Any caller that relies on InstallOutcome will misclassify those installs as pending. Thread the outcome back from the platform helpers instead of hard-coding it here.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@core/data/src/jvmMain/kotlin/zed/rainxch/core/data/services/DesktopInstaller.kt`
around lines 354 - 374, The install(...) function currently ignores the outcome
from platform-specific installers and always returns
InstallOutcome.DELEGATED_TO_SYSTEM; change it to capture and return the
InstallOutcome returned by installWindows(file, ext), installMacOS(file, ext),
or installLinux(file, ext) so synchronous flows (e.g., installAppImage,
successful installDebPackage/installRpmPackage, and the .pkg installer flow) can
return InstallOutcome.COMPLETED when appropriate; update the when(...)
expression to assign its result to a variable (or directly return the when
result) and ensure the method returns that InstallOutcome instead of the
hard-coded value.

}

private fun installWindows(
file: File,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,25 @@ package zed.rainxch.core.domain.system
import zed.rainxch.core.domain.model.GithubAsset
import zed.rainxch.core.domain.model.SystemArchitecture

/**
* Result of an [Installer.install] call.
*/
enum class InstallOutcome {
/**
* Installation completed synchronously (e.g. Shizuku silent install).
* The package is already installed on the system — no need to wait
* for a broadcast to confirm.
*/
COMPLETED,

/**
* Installation was handed off to the system UI or an external process.
* The caller should treat the install as pending until a
* PACKAGE_ADDED / PACKAGE_REPLACED broadcast confirms it.
*/
DELEGATED_TO_SYSTEM,
}

interface Installer {
suspend fun isSupported(extOrMime: String): Boolean

Expand All @@ -11,7 +30,7 @@ interface Installer {
suspend fun install(
filePath: String,
extOrMime: String,
)
): InstallOutcome

fun uninstall(packageName: String)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import zed.rainxch.core.domain.repository.InstalledAppsRepository
import zed.rainxch.core.domain.repository.SeenReposRepository
import zed.rainxch.core.domain.repository.StarredRepository
import zed.rainxch.core.domain.repository.TweaksRepository
import zed.rainxch.core.domain.system.InstallOutcome
import zed.rainxch.core.domain.system.Installer
import zed.rainxch.core.domain.system.PackageMonitor
import zed.rainxch.core.domain.use_cases.SyncInstalledAppsUseCase
Expand Down Expand Up @@ -1192,7 +1193,7 @@ class DetailsViewModel(
}
}

installer.install(filePath, ext)
val installOutcome = installer.install(filePath, ext)

// Launch attestation check asynchronously (non-blocking)
launchAttestationCheck(filePath)
Expand All @@ -1205,6 +1206,7 @@ class DetailsViewModel(
releaseTag = releaseTag,
isUpdate = isUpdate,
filePath = filePath,
installOutcome = installOutcome,
)
} else {
viewModelScope.launch {
Expand Down Expand Up @@ -1394,6 +1396,7 @@ class DetailsViewModel(
releaseTag: String,
isUpdate: Boolean,
filePath: String,
installOutcome: InstallOutcome = InstallOutcome.DELEGATED_TO_SYSTEM,
) {
try {
val repo = _state.value.repository ?: return
Expand Down Expand Up @@ -1455,7 +1458,7 @@ class DetailsViewModel(
releaseNotes = "",
systemArchitecture = installer.detectSystemArchitecture().name,
fileExtension = assetName.substringAfterLast('.', ""),
isPendingInstall = true,
isPendingInstall = installOutcome != InstallOutcome.COMPLETED,
installedVersionName = apkInfo.versionName,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "=== updateAppVersion declarations / implementations ==="
fd 'InstalledAppsRepository.*\.kt$' | while read -r file; do
  echo "--- $file ---"
  rg -n -C4 '\bupdateAppVersion\s*\(' "$file"
done

echo
echo "=== pending-flag writes near repository methods ==="
fd 'InstalledAppsRepository.*\.kt$' | while read -r file; do
  echo "--- $file ---"
  rg -n -C4 'isPendingInstall|updatePendingStatus' "$file"
done

echo
echo "=== package receiver handling ==="
fd 'PackageEventReceiver\.kt$' | while read -r file; do
  echo "--- $file ---"
  rg -n -C4 'updateAppVersion|updatePendingStatus|isPendingInstall' "$file"
done

Repository: OpenHub-Store/GitHub-Store

Length of output: 4300


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "=== Full updateAppVersion implementation ==="
rg -n -A 20 'override suspend fun updateAppVersion' core/data/src/commonMain/kotlin/zed/rainxch/core/data/repository/InstalledAppsRepositoryImpl.kt

echo
echo "=== DetailsViewModel update branch around insertOrUpdateApp ==="
rg -n -B 5 -A 15 'updateAppVersion' feature/details/presentation/src/commonMain/kotlin/zed/rainxch/details/presentation/DetailsViewModel.kt | head -80

echo
echo "=== DetailsViewModel insert branch for comparison ==="
rg -n -B 5 -A 15 'insertApp\|isPendingInstall.*=' feature/details/presentation/src/commonMain/kotlin/zed/rainxch/details/presentation/DetailsViewModel.kt | head -100

Repository: OpenHub-Store/GitHub-Store

Length of output: 1949


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "=== Full updateAppVersion implementation (lines 181-240) ==="
sed -n '181,240p' core/data/src/commonMain/kotlin/zed/rainxch/core/data/repository/InstalledAppsRepositoryImpl.kt

echo
echo "=== DetailsViewModel isPendingInstall assignments ==="
rg -n 'isPendingInstall\s*=' feature/details/presentation/src/commonMain/kotlin/zed/rainxch/details/presentation/DetailsViewModel.kt

echo
echo "=== DetailsViewModel updatePendingStatus calls ==="
rg -n 'updatePendingStatus' feature/details/presentation/src/commonMain/kotlin/zed/rainxch/details/presentation/DetailsViewModel.kt

echo
echo "=== Complete insert branch in DetailsViewModel (lines 1433-1465) ==="
sed -n '1433,1465p' feature/details/presentation/src/commonMain/kotlin/zed/rainxch/details/presentation/DetailsViewModel.kt

Repository: OpenHub-Store/GitHub-Store

Length of output: 4514


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "=== Context around updatePendingStatus call at line 272 ==="
sed -n '260,285p' feature/details/presentation/src/commonMain/kotlin/zed/rainxch/details/presentation/DetailsViewModel.kt

echo
echo "=== Check if there's a pending status write between updateAppVersion call and end of update branch ==="
sed -n '1423,1480p' feature/details/presentation/src/commonMain/kotlin/zed/rainxch/details/presentation/DetailsViewModel.kt

Repository: OpenHub-Store/GitHub-Store

Length of output: 4248


Update path does not set pending status for delegated installs.

The insert branch correctly sets isPendingInstall = installOutcome != InstallOutcome.COMPLETED, but the update branch at line 1424 calls updateAppVersion(...) without any subsequent pending-status handling. The updateAppVersion() method does not include isPendingInstall in its update and has no parameter for it. This means delegated Android updates are never marked pending, causing PackageEventReceiver.onPackageInstalled() to skip the pending-install logic since the flag remains unset.

Either add a updatePendingStatus() call after updateAppVersion() in the update path, or add isPendingInstall handling to updateAppVersion() itself to match the insert path behavior.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@feature/details/presentation/src/commonMain/kotlin/zed/rainxch/details/presentation/DetailsViewModel.kt`
around lines 1459 - 1462, The update path currently calls updateAppVersion(...)
but never sets isPendingInstall, so delegated Android updates are not marked
pending and PackageEventReceiver.onPackageInstalled() skips pending-install
logic; fix by either extending updateAppVersion(...) to accept and persist an
isPendingInstall parameter (compute isPendingInstall = installOutcome !=
InstallOutcome.COMPLETED and update the DB there) or, if you prefer minimal
change, call a new or existing updatePendingStatus(appId, isPendingInstall)
immediately after updateAppVersion(...) in the update branch; ensure you
reference InstallOutcome, isPendingInstall, updateAppVersion, and
PackageEventReceiver.onPackageInstalled when making the change so the pending
flag is stored consistently with the insert branch.

installedVersionCode = apkInfo.versionCode,
latestVersionName = apkInfo.versionName,
Expand Down