Skip to content

Commit b23d815

Browse files
committed
Improve error handling and refine self-registration logic in GithubStoreApp
- Added a try-catch block to `scheduleBackgroundUpdateChecks` to handle and log potential failures during update scheduling. - Replaced the hardcoded `0L` repository ID with a new `SELF_REPO_ID` constant in `registerSelfAsInstalledApp`. - Refined logging in `registerSelfAsInstalledApp`, changing the success message to info level and improving the error log format.
1 parent 82b1971 commit b23d815

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,15 @@ class GithubStoreApp : Application() {
8282

8383
private fun scheduleBackgroundUpdateChecks() {
8484
appScope.launch {
85-
val intervalHours = get<ThemesRepository>().getUpdateCheckInterval().first()
86-
UpdateScheduler.schedule(context = this@GithubStoreApp, intervalHours = intervalHours)
85+
try {
86+
val intervalHours = get<ThemesRepository>().getUpdateCheckInterval().first()
87+
UpdateScheduler.schedule(
88+
context = this@GithubStoreApp,
89+
intervalHours = intervalHours,
90+
)
91+
} catch (e: Exception) {
92+
Logger.e(e) { "Failed to schedule background update checks" }
93+
}
8794
}
8895
}
8996

@@ -110,7 +117,7 @@ class GithubStoreApp : Application() {
110117
val selfApp =
111118
InstalledApp(
112119
packageName = selfPackageName,
113-
repoId = 0L,
120+
repoId = SELF_REPO_ID,
114121
repoName = SELF_REPO_NAME,
115122
repoOwner = SELF_REPO_OWNER,
116123
repoOwnerAvatarUrl = SELF_AVATAR_URL,
@@ -140,14 +147,15 @@ class GithubStoreApp : Application() {
140147
)
141148

142149
repo.saveInstalledApp(selfApp)
143-
Logger.e("GitHub Store App: App added")
150+
Logger.i("GitHub Store App: App added")
144151
} catch (e: Exception) {
145-
Logger.e("GitHub Store App", e)
152+
Logger.e(e) { "GitHub Store App: Failed to register self as installed app" }
146153
}
147154
}
148155
}
149156

150157
companion object {
158+
private const val SELF_REPO_ID = 1101281251L
151159
private const val SELF_REPO_OWNER = "OpenHub-Store"
152160
private const val SELF_REPO_NAME = "GitHub-Store"
153161
private const val SELF_AVATAR_URL =

0 commit comments

Comments
 (0)