Skip to content

Commit 82b1971

Browse files
committed
Refactor self-registration logic and add logging in GithubStoreApp
- Replace hardcoded `SELF_PACKAGE_NAME` with the dynamic `packageName` property. - Update `SELF_AVATAR_URL` to point to the official repository app icon. - Integrate `kermit` logging to track self-registration success, warnings, and errors. - Add a null check for `systemInfo` to prevent registration if package info is missing. - Add `touchlab.kermit` dependency to `composeApp/build.gradle.kts`.
1 parent 2203fec commit 82b1971

2 files changed

Lines changed: 21 additions & 12 deletions

File tree

composeApp/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ kotlin {
6969
implementation(libs.liquid)
7070
implementation(libs.jetbrains.compose.material.icons.extended)
7171

72+
implementation(libs.touchlab.kermit)
73+
7274
implementation(compose.runtime)
7375
implementation(compose.foundation)
7476
implementation(libs.jetbrains.compose.material3)

composeApp/src/androidMain/kotlin/zed/rainxch/githubstore/app/GithubStoreApp.kt

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import android.app.Application
44
import android.app.NotificationChannel
55
import android.app.NotificationManager
66
import android.os.Build
7+
import co.touchlab.kermit.Logger
78
import kotlinx.coroutines.CoroutineScope
89
import kotlinx.coroutines.Dispatchers
910
import kotlinx.coroutines.SupervisorJob
@@ -86,31 +87,33 @@ class GithubStoreApp : Application() {
8687
}
8788
}
8889

89-
/**
90-
* Automatically registers GitHub Store itself as a tracked installed app on first launch.
91-
* This allows the app to track its own updates and auto-update via Shizuku.
92-
*/
9390
private fun registerSelfAsInstalledApp() {
9491
appScope.launch {
9592
try {
9693
val repo = get<InstalledAppsRepository>()
97-
val existing = repo.getAppByPackage(SELF_PACKAGE_NAME)
94+
val selfPackageName = packageName
95+
val existing = repo.getAppByPackage(selfPackageName)
96+
9897
if (existing != null) return@launch
9998

10099
val packageMonitor = get<PackageMonitor>()
101-
val systemInfo = packageMonitor.getInstalledPackageInfo(SELF_PACKAGE_NAME)
100+
val systemInfo = packageMonitor.getInstalledPackageInfo(selfPackageName)
101+
if (systemInfo == null) {
102+
Logger.w { "GithubStoreApp: Skip self-registration, package info missing for $selfPackageName" }
103+
return@launch
104+
}
102105

103106
val now = System.currentTimeMillis()
104-
val versionName = systemInfo?.versionName ?: ""
105-
val versionCode = systemInfo?.versionCode ?: 0L
107+
val versionName = systemInfo.versionName
108+
val versionCode = systemInfo.versionCode
106109

107110
val selfApp =
108111
InstalledApp(
109-
packageName = SELF_PACKAGE_NAME,
112+
packageName = selfPackageName,
110113
repoId = 0L,
111114
repoName = SELF_REPO_NAME,
112115
repoOwner = SELF_REPO_OWNER,
113-
repoOwnerAvatarUrl = "https://avatars.githubusercontent.com/u/221085707",
116+
repoOwnerAvatarUrl = SELF_AVATAR_URL,
114117
repoDescription = "A cross-platform app store for GitHub releases",
115118
primaryLanguage = "Kotlin",
116119
repoUrl = "https://github.com/$SELF_REPO_OWNER/$SELF_REPO_NAME",
@@ -137,15 +140,19 @@ class GithubStoreApp : Application() {
137140
)
138141

139142
repo.saveInstalledApp(selfApp)
140-
} catch (_: Exception) {
143+
Logger.e("GitHub Store App: App added")
144+
} catch (e: Exception) {
145+
Logger.e("GitHub Store App", e)
141146
}
142147
}
143148
}
144149

145150
companion object {
146-
private const val SELF_PACKAGE_NAME = "zed.rainxch.githubstore"
147151
private const val SELF_REPO_OWNER = "OpenHub-Store"
148152
private const val SELF_REPO_NAME = "GitHub-Store"
153+
private const val SELF_AVATAR_URL =
154+
@Suppress("ktlint:standard:max-line-length")
155+
"https://raw.githubusercontent.com/OpenHub-Store/GitHub-Store/refs/heads/main/media-resources/app_icon.png"
149156
const val UPDATES_CHANNEL_ID = "app_updates"
150157
const val UPDATE_SERVICE_CHANNEL_ID = "update_service"
151158
}

0 commit comments

Comments
 (0)