Skip to content

Commit 0368e72

Browse files
authored
Merge pull request #529 from OpenHub-Store/feat/528-disable-update-check
2 parents d0c917f + 12efdf8 commit 0368e72

37 files changed

Lines changed: 195 additions & 18 deletions

File tree

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,14 @@ class GithubStoreApp : Application() {
127127
private fun scheduleBackgroundUpdateChecks() {
128128
appScope.launch {
129129
try {
130-
val intervalHours = get<TweaksRepository>().getUpdateCheckInterval().first()
130+
val tweaks = get<TweaksRepository>()
131+
val enabled = tweaks.getUpdateCheckEnabled().first()
132+
if (!enabled) {
133+
UpdateScheduler.cancel(this@GithubStoreApp)
134+
Logger.i { "Background update check disabled — skipping schedule" }
135+
return@launch
136+
}
137+
val intervalHours = tweaks.getUpdateCheckInterval().first()
131138
UpdateScheduler.schedule(
132139
context = this@GithubStoreApp,
133140
intervalHours = intervalHours,

core/data/src/androidMain/kotlin/zed/rainxch/core/data/services/AndroidUpdateScheduleManager.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,8 @@ class AndroidUpdateScheduleManager(
99
override fun reschedule(intervalHours: Long) {
1010
UpdateScheduler.reschedule(context, intervalHours)
1111
}
12+
13+
override fun cancel() {
14+
UpdateScheduler.cancel(context)
15+
}
1216
}

core/data/src/androidMain/kotlin/zed/rainxch/core/data/services/BootReceiver.kt

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,38 @@ import android.content.BroadcastReceiver
44
import android.content.Context
55
import android.content.Intent
66
import co.touchlab.kermit.Logger
7+
import kotlinx.coroutines.flow.first
8+
import kotlinx.coroutines.runBlocking
9+
import org.koin.core.context.GlobalContext
10+
import zed.rainxch.core.domain.repository.TweaksRepository
711

812
/**
913
* Reschedules periodic update checks after device reboot.
1014
* Registered statically in AndroidManifest.xml.
1115
*/
1216
class BootReceiver : BroadcastReceiver() {
1317
override fun onReceive(context: Context, intent: Intent?) {
14-
if (intent?.action == Intent.ACTION_BOOT_COMPLETED) {
15-
Logger.i { "BootReceiver: Device booted, scheduling update checks" }
16-
UpdateScheduler.schedule(context)
18+
if (intent?.action != Intent.ACTION_BOOT_COMPLETED) return
19+
val pendingResult = goAsync()
20+
try {
21+
val enabled =
22+
runCatching {
23+
runBlocking {
24+
GlobalContext.get().get<TweaksRepository>().getUpdateCheckEnabled().first()
25+
}
26+
}.getOrElse {
27+
Logger.w(it) { "BootReceiver: Failed to read update-check flag, defaulting to enabled" }
28+
true
29+
}
30+
if (enabled) {
31+
Logger.i { "BootReceiver: Device booted, scheduling update checks" }
32+
UpdateScheduler.schedule(context)
33+
} else {
34+
Logger.i { "BootReceiver: Device booted, update check disabled — skipping" }
35+
UpdateScheduler.cancel(context)
36+
}
37+
} finally {
38+
pendingResult.finish()
1739
}
1840
}
1941
}

core/data/src/commonMain/kotlin/zed/rainxch/core/data/repository/TweaksRepositoryImpl.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,17 @@ class TweaksRepositoryImpl(
156156
}
157157
}
158158

159+
override fun getUpdateCheckEnabled(): Flow<Boolean> =
160+
preferences.data.map { prefs ->
161+
prefs[UPDATE_CHECK_ENABLED_KEY] ?: true
162+
}
163+
164+
override suspend fun setUpdateCheckEnabled(enabled: Boolean) {
165+
preferences.edit { prefs ->
166+
prefs[UPDATE_CHECK_ENABLED_KEY] = enabled
167+
}
168+
}
169+
159170
override fun getUpdateCheckInterval(): Flow<Long> =
160171
preferences.data.map { prefs ->
161172
prefs[UPDATE_CHECK_INTERVAL_KEY] ?: DEFAULT_UPDATE_CHECK_INTERVAL_HOURS
@@ -409,6 +420,7 @@ class TweaksRepositoryImpl(
409420
private val INSTALLER_TYPE_KEY = stringPreferencesKey("installer_type")
410421
private val INSTALLER_ATTRIBUTION_KEY = stringPreferencesKey("installer_attribution")
411422
private val AUTO_UPDATE_KEY = booleanPreferencesKey("auto_update_enabled")
423+
private val UPDATE_CHECK_ENABLED_KEY = booleanPreferencesKey("update_check_enabled")
412424
private val UPDATE_CHECK_INTERVAL_KEY = longPreferencesKey("update_check_interval_hours")
413425
private val INCLUDE_PRE_RELEASES_KEY = booleanPreferencesKey("include_pre_releases")
414426
private val HIDE_SEEN_ENABLED_KEY = booleanPreferencesKey("hide_seen_enabled")

core/data/src/jvmMain/kotlin/zed/rainxch/core/data/services/DesktopUpdateScheduleManager.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,8 @@ class DesktopUpdateScheduleManager : UpdateScheduleManager {
99
override fun reschedule(intervalHours: Long) {
1010
// No background scheduler on Desktop
1111
}
12+
13+
override fun cancel() {
14+
// No background scheduler on Desktop
15+
}
1216
}

core/domain/src/commonMain/kotlin/zed/rainxch/core/domain/repository/TweaksRepository.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ interface TweaksRepository {
4141

4242
suspend fun setAutoUpdateEnabled(enabled: Boolean)
4343

44+
fun getUpdateCheckEnabled(): Flow<Boolean>
45+
46+
suspend fun setUpdateCheckEnabled(enabled: Boolean)
47+
4448
fun getUpdateCheckInterval(): Flow<Long>
4549

4650
suspend fun setUpdateCheckInterval(hours: Long)

core/domain/src/commonMain/kotlin/zed/rainxch/core/domain/system/UpdateScheduleManager.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,10 @@ interface UpdateScheduleManager {
1010
* Takes effect immediately (replaces existing schedule).
1111
*/
1212
fun reschedule(intervalHours: Long)
13+
14+
/**
15+
* Cancels every pending update-check / auto-update worker. Used
16+
* when the user disables background update checking entirely.
17+
*/
18+
fun cancel()
1319
}

core/presentation/src/commonMain/composeResources/files/whatsnew/16.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
"Manual rescan surfaces every GitHub-style app on device.",
2626
"Tighter auth handling — transient 401s no longer trigger spurious sign-outs.",
2727
"Open-issues count now shown to everyone, including signed-out users — the count now comes from the backend.",
28-
"License now shown for every repo regardless of sign-in state — sourced from backend, no more GitHub quota cost per Details open."
28+
"License now shown for every repo regardless of sign-in state — sourced from backend, no more GitHub quota cost per Details open.",
29+
"Background update check can be turned off entirely — saves battery if you'd rather check for updates manually."
2930
]
3031
},
3132
{

core/presentation/src/commonMain/composeResources/files/whatsnew/ar/16.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
"إعادة المسح اليدوي تُظهر كل تطبيقات GitHub الموجودة على الجهاز دون تفويت أيّ منها.",
2626
"معالجة أكثر صرامة للمصادقة: استجابات 401 العابرة لم تعد تتسبّب في تسجيل خروج خاطئ.",
2727
"عداد المشكلات المفتوحة يظهر الآن للجميع بمن فيهم غير المسجَّلين — يأتي من الخادم الخلفي دون أي تكلفة لحصص GitHub.",
28-
"الترخيص يظهر الآن لكل مستودع بصرف النظر عن حالة تسجيل الدخول — يأتي من الخادم الخلفي بدون أي استهلاك لحصص GitHub عند فتح صفحة التفاصيل."
28+
"الترخيص يظهر الآن لكل مستودع بصرف النظر عن حالة تسجيل الدخول — يأتي من الخادم الخلفي بدون أي استهلاك لحصص GitHub عند فتح صفحة التفاصيل.",
29+
"يمكنك إيقاف التحقق التلقائي من التحديثات في الخلفية بالكامل — يوفّر البطارية إذا كنت تفضّل التحقق يدوياً."
2930
]
3031
},
3132
{

core/presentation/src/commonMain/composeResources/files/whatsnew/bn/16.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
"ম্যানুয়াল রি-স্ক্যান এখন ডিভাইসে থাকা সব GitHub-ধাঁচের অ্যাপ তুলে আনে।",
2626
"অথেনটিকেশন আরও সংযত: সাময়িক 401 আর ভুল করে সাইন-আউট ঘটায় না।",
2727
"ওপেন ইস্যুর সংখ্যা এখন সবাইকে দেখানো হয়, এমনকি সাইন-ইন না করা ব্যবহারকারীদেরও — ব্যাকএন্ড থেকে আসে, GitHub কোটায় কোনো খরচ নেই।",
28-
"লাইসেন্স এখন প্রতিটি রিপোর জন্য সাইন-ইন স্ট্যাটাস নির্বিশেষে দেখানো হয় — ব্যাকএন্ড থেকে আসে, ডিটেইলস খোলার সময় GitHub কোটায় আর কোনো খরচ নেই।"
28+
"লাইসেন্স এখন প্রতিটি রিপোর জন্য সাইন-ইন স্ট্যাটাস নির্বিশেষে দেখানো হয় — ব্যাকএন্ড থেকে আসে, ডিটেইলস খোলার সময় GitHub কোটায় আর কোনো খরচ নেই।",
29+
"ব্যাকগ্রাউন্ড আপডেট চেক পুরোপুরি বন্ধ করা যায় — ম্যানুয়ালি চেক করতে চাইলে ব্যাটারি বাঁচে।"
2930
]
3031
},
3132
{

0 commit comments

Comments
 (0)