Skip to content

Open source Grok Bot alternative, Bring your own agent and subscription: message Claude Code, Codex, Gemini CLI, Cursor, Copilot and 40+ AI agents as bots on your own computer, from iPhone, Mac, Windows, Linux or terminal. Agent-agnostic and free. Also a Muse and Dots alternative. Built in Rust.

fix(android): keep widgets updating with several computers and the review invitation from cancelling itself

leepokai309c0d8fd7cd
diff --git a/apps/android/app/src/main/kotlin/com/codync/android/ReviewPrompt.kt b/apps/android/app/src/main/kotlin/com/codync/android/ReviewPrompt.kt
index 2c749b15..047a0294 100644
--- a/apps/android/app/src/main/kotlin/com/codync/android/ReviewPrompt.kt
+++ b/apps/android/app/src/main/kotlin/com/codync/android/ReviewPrompt.kt
@@ -9,6 +9,7 @@ import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
+import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.platform.LocalContext
import androidx.core.content.edit
@@ -23,6 +24,7 @@ import com.google.android.play.core.ktx.launchReview
import com.google.android.play.core.ktx.requestReview
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.delay
+import kotlinx.coroutines.launch
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
@@ -114,16 +116,20 @@ internal val AppState.settledForReview: Boolean
@Composable internal fun ReviewInvitationEffect(blocked: Boolean) {
val context = LocalContext.current
val token by ReviewPrompt.opportunity.collectAsState()
+ // `request` clears the opportunity, which restarts this effect, so Play's request runs outside it.
+ val scope = rememberCoroutineScope()
LaunchedEffect(token, blocked) {
val opportunity = token ?: return@LaunchedEffect
if (blocked) { ReviewPrompt.cancel(context, ReviewCancellation.Unavailable); return@LaunchedEffect }
delay(2_000)
val activity = context as? Activity ?: return@LaunchedEffect ReviewPrompt.cancel(context, ReviewCancellation.Unavailable)
if (!ReviewPrompt.request(context, opportunity)) return@LaunchedEffect
- try {
- val manager = ReviewManagerFactory.create(context)
- manager.launchReview(activity, manager.requestReview())
- } catch (cancelled: CancellationException) { throw cancelled }
- catch (error: Exception) { android.util.Log.i("Codync", "Review prompt unavailable: ${error.message}") }
+ scope.launch {
+ try {
+ val manager = ReviewManagerFactory.create(context)
+ manager.launchReview(activity, manager.requestReview())
+ } catch (cancelled: CancellationException) { throw cancelled }
+ catch (error: Exception) { android.util.Log.i("Codync", "Review prompt unavailable: ${error.message}") }
+ }
}
}
diff --git a/apps/android/app/src/main/kotlin/com/codync/android/WidgetRefreshWorker.kt b/apps/android/app/src/main/kotlin/com/codync/android/WidgetRefreshWorker.kt
index ebac5f25..7707060f 100644
--- a/apps/android/app/src/main/kotlin/com/codync/android/WidgetRefreshWorker.kt
+++ b/apps/android/app/src/main/kotlin/com/codync/android/WidgetRefreshWorker.kt
@@ -11,6 +11,7 @@ import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.withContext
import kotlinx.coroutines.withTimeout
+import kotlinx.coroutines.withTimeoutOrNull
import kotlinx.coroutines.TimeoutCancellationException
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
@@ -39,11 +40,11 @@ class WidgetRefreshWorker(context: Context, parameters: WorkerParameters) : Coro
if (computers.isEmpty()) return@withTimeout false
val usageId = computers.currentId(withContext(Dispatchers.IO) { local.lastComputer() })
val identity = withContext(Dispatchers.IO) { local.identity() }
- // Each computer at once; one that can't be reached keeps the bots it had (and isn't fresh).
+ // Each computer at once, each in its own 20 s; one that can't be reached keeps the bots it had (and isn't fresh).
val reads = coroutineScope {
computers.map { computer ->
async {
- try { read(computer, identity, computer.id == usageId) }
+ try { withTimeoutOrNull(20_000) { read(computer, identity, computer.id == usageId) } }
catch (cancelled: CancellationException) { throw cancelled }
catch (error: Exception) { android.util.Log.i("Codync", "Widget refresh couldn't read ${computer.id}: ${error.message}"); null }
}
diff --git a/apps/android/core/src/main/kotlin/com/codync/android/core/CustomIcon.kt b/apps/android/core/src/main/kotlin/com/codync/android/core/CustomIcon.kt
index 10a2483f..1916eb5f 100644
--- a/apps/android/core/src/main/kotlin/com/codync/android/core/CustomIcon.kt
+++ b/apps/android/core/src/main/kotlin/com/codync/android/core/CustomIcon.kt
@@ -11,5 +11,5 @@ fun decodeCustomIcons(value: JsonElement): Map<String, CustomIcon> = WireJson.de
/** Apply the current image snapshot, including removals, without replacing fresh bot metadata. */
fun List<Bot>.withCustomIcons(icons: Map<String, CustomIcon>): List<Bot> = map { it.copy(customIcon = icons["bot:${it.id}"]) }
-/** 128 normalized images plus the existing 512 KiB summary allowance. */
-const val MAX_WIDGET_FEED_BYTES = 128 * 65_558 + 512 * 1024
+/** A normalized image for each of the feed's 256 bots (every computer's), plus the 512 KiB summary allowance. */
+const val MAX_WIDGET_FEED_BYTES = 256 * 65_558 + 512 * 1024