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(apps): keep drafts and unsent messages when sign-in moves a phone's computers

leepokaie9325c779773
diff --git a/apps/android/app/src/androidTest/kotlin/com/codync/android/LocalStoreTest.kt b/apps/android/app/src/androidTest/kotlin/com/codync/android/LocalStoreTest.kt
index a58df914..187b64d9 100644
--- a/apps/android/app/src/androidTest/kotlin/com/codync/android/LocalStoreTest.kt
+++ b/apps/android/app/src/androidTest/kotlin/com/codync/android/LocalStoreTest.kt
@@ -4,7 +4,10 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import com.codync.android.core.Computer
import com.codync.android.core.DeviceIdentity
+import com.codync.android.core.OutgoingFile
+import com.codync.android.core.PendingSend
import com.codync.android.core.RelayCrypto
+import java.io.File
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.jsonObject
import kotlinx.serialization.json.jsonPrimitive
@@ -59,6 +62,30 @@ class LocalStoreTest {
} finally { signedOut.erase(); account.erase() }
}
+ @Test fun aNewAccountsDraftsAndQueuedMessagesKeepTheirFiles() {
+ val context = InstrumentationRegistry.getInstrumentation().targetContext
+ val scope = "test-${java.util.UUID.randomUUID()}"
+ val signedOut = LocalStore(context, "$scope-local")
+ val account = LocalStore(context, scope)
+ try {
+ signedOut.identity()
+ val mac = computer(1, "Mac mini")
+ signedOut.saveComputers(listOf(mac))
+ val photo = File(File(signedOut.directory, "outgoing").apply { mkdirs() }, java.util.UUID.randomUUID().toString()).apply { writeText("photo") }
+ val file = OutgoingFile(photo.path, "photo.jpg", photo.length())
+ DraftBook(signedOut.directory, mac.id).save(listOf(ComposerDraft("bot", "draft", listOf(file))))
+ MirrorDatabase(context, signedOut.directory, mac.id).use { it.save(PendingSend("queued", "bot", "queued", 1, files = listOf(file))) }
+ assertEquals(LocalStore.Adoption(1, MovedKeys.Moved), account.adopt(signedOut))
+ val draft = DraftBook(account.directory, mac.id).read().single().files.single()
+ val queued = MirrorDatabase(context, account.directory, mac.id).use { it.snapshot().pending.single().files.single() }
+ for (moved in listOf(draft, queued)) {
+ assertEquals(File(account.directory, "outgoing"), File(moved.path).parentFile)
+ assertEquals("photo", File(moved.path).readText())
+ }
+ assertFalse("the signed-out folder is gone", photo.exists())
+ } finally { signedOut.erase(); account.erase() }
+ }
+
@Test fun anAccountInUseKeepsItsKeyAndMergesTheComputers() {
val context = InstrumentationRegistry.getInstrumentation().targetContext
val scope = "test-${java.util.UUID.randomUUID()}"
diff --git a/apps/android/app/src/androidTest/kotlin/com/codync/android/OnboardingTest.kt b/apps/android/app/src/androidTest/kotlin/com/codync/android/OnboardingTest.kt
index 0ae72bec..d1129daa 100644
--- a/apps/android/app/src/androidTest/kotlin/com/codync/android/OnboardingTest.kt
+++ b/apps/android/app/src/androidTest/kotlin/com/codync/android/OnboardingTest.kt
@@ -24,6 +24,18 @@ class OnboardingTest {
compose.onNodeWithText("Get started").assertDoesNotExist()
}
+ @Test fun aFailedRestoreOffersTryAgainWhileSignInWaits() {
+ compose.mainClock.autoAdvance = false
+ val failed = AccountContext(loading = false,
+ account = AccountState(ready = false, configured = true, error = "Couldn't restore sign-in. Check your connection and retry."))
+ compose.setContent { Hosted { CodyncApp(failed, emptyMap(), viewModel()) } }
+ step()
+ // Below the fold: scrolling would wait on a clock this test holds still.
+ compose.onNodeWithText("Couldn't restore sign-in. Check your connection and retry.").assertExists()
+ compose.onNodeWithContentDescription("Try again").assertIsEnabled()
+ compose.onNodeWithText("Continue with Apple").assertIsNotEnabled()
+ }
+
@Test fun welcomeLeadsToInstallAndBackReturnsToWelcome() {
// The welcome crew never stops moving: step the clock by hand so the test can settle.
compose.mainClock.autoAdvance = false
diff --git a/apps/android/app/src/main/kotlin/com/codync/android/AttachmentFiles.kt b/apps/android/app/src/main/kotlin/com/codync/android/AttachmentFiles.kt
index 4a133e11..af06d399 100644
--- a/apps/android/app/src/main/kotlin/com/codync/android/AttachmentFiles.kt
+++ b/apps/android/app/src/main/kotlin/com/codync/android/AttachmentFiles.kt
@@ -17,7 +17,7 @@ import kotlin.coroutines.coroutineContext
/** Copies provider streams into this account's private storage before it owns a send. */
class AttachmentFiles(private val context: Context, private val directory: File) {
- private val outgoing = File(directory, "outgoing").apply { mkdirs() }
+ private val outgoing = outgoingFolder(directory).apply { mkdirs() }
private val downloads = File(directory, "attachments").apply { mkdirs() }
suspend fun import(uri: Uri): OutgoingFile = withContext(Dispatchers.IO) {
@@ -65,8 +65,7 @@ class AttachmentFiles(private val context: Context, private val directory: File)
}
fun discard(file: OutgoingFile) {
- val path = File(file.path)
- if (path.parentFile?.canonicalFile == outgoing.canonicalFile) path.delete()
+ if (inOutgoing(directory, file.path)) File(file.path).delete()
}
fun retainPending(files: List<OutgoingFile>) {
val paths = files.map { File(it.path).canonicalPath }.toSet()
@@ -107,6 +106,14 @@ class AttachmentFiles(private val context: Context, private val directory: File)
}
companion object {
+ /** Where account folder [directory] keeps the files its drafts and queued messages send. */
+ fun outgoingFolder(directory: File) = File(directory, "outgoing")
+ fun inOutgoing(directory: File, path: String) = File(path).canonicalFile.parentFile == outgoingFolder(directory).canonicalFile
+
+ /** [file] saved in account folder [from], pointed at its copy in [to] (`LocalStore.adopt`); others stay as they are. */
+ fun moved(file: OutgoingFile, from: File, to: File): OutgoingFile =
+ if (inOutgoing(from, file.path)) file.copy(path = File(outgoingFolder(to), File(file.path).name).path) else file
+
fun cleanName(value: String): String {
val name = value.substringAfterLast('/').substringAfterLast('\\').trim().trimStart('.').filter { !it.isISOControl() }
val usable = name.ifBlank { "file" }
diff --git a/apps/android/app/src/main/kotlin/com/codync/android/DraftBook.kt b/apps/android/app/src/main/kotlin/com/codync/android/DraftBook.kt
index a0c69568..a946b714 100644
--- a/apps/android/app/src/main/kotlin/com/codync/android/DraftBook.kt
+++ b/apps/android/app/src/main/kotlin/com/codync/android/DraftBook.kt
@@ -22,15 +22,19 @@ data class ComposerDraft(val botId: String, val text: String = "",
class DraftBook(private val directory: File, computerId: String) {
private val file = bookFile(directory, computerId)
- @Synchronized fun read(): List<ComposerDraft> {
+ @Synchronized fun read(): List<ComposerDraft> = decode().also { validate(it) }
+
+ /** A book [LocalStore.adopt] copied from account folder [from]: its attachments name this folder's copies. */
+ @Synchronized fun relocate(from: File) =
+ save(decode().map { draft -> draft.copy(files = draft.files.map { AttachmentFiles.moved(it, from, directory) }) })
+
+ private fun decode(): List<ComposerDraft> {
if (!file.baseFile.exists()) return emptyList()
require(file.baseFile.length() <= MAX_BYTES) { "The saved drafts are too large." }
// A book saved before 2.20.1 may hold thread drafts (a `threadId`): only each chat's own stays.
- val drafts = WireJson.parseToJsonElement(file.readFully().toString(Charsets.UTF_8)).jsonArray
+ return WireJson.parseToJsonElement(file.readFully().toString(Charsets.UTF_8)).jsonArray
.filter { (it.jsonObject["threadId"] ?: JsonNull) == JsonNull }
.map { WireJson.decodeFromJsonElement<ComposerDraft>(it) }
- validate(drafts)
- return drafts
}
/** A crash between pending-send commit and draft removal cannot offer the same draft twice. */
@@ -54,7 +58,6 @@ class DraftBook(private val directory: File, computerId: String) {
fun validate(drafts: Collection<ComposerDraft>, checkPaths: Boolean = true) {
require(drafts.size <= 64) { "Too many drafts. Send or clear an older draft first." }
require(drafts.map { it.botId }.distinct().size == drafts.size) { "The saved drafts contain duplicate conversations." }
- val outgoing = if (checkPaths) File(directory, "outgoing").canonicalFile else null
for (draft in drafts) {
require(draft.botId.isNotBlank() && draft.botId.length <= 128)
require(UUID.fromString(draft.nonce).toString() == draft.nonce) { "A saved draft has an invalid message ID." }
@@ -62,7 +65,7 @@ class DraftBook(private val directory: File, computerId: String) {
require(draft.files.size <= 20) { "Choose at most 20 files for one message." }
for (attachment in draft.files) {
require(attachment.size in 0..MAX_FILE_BYTES && attachment.name.isNotBlank())
- if (checkPaths) require(File(attachment.path).canonicalFile.parentFile == outgoing) { "A draft attachment belongs to another account." }
+ if (checkPaths) require(AttachmentFiles.inOutgoing(directory, attachment.path)) { "A draft attachment belongs to another account." }
}
}
}
diff --git a/apps/android/app/src/main/kotlin/com/codync/android/LocalStore.kt b/apps/android/app/src/main/kotlin/com/codync/android/LocalStore.kt
index 913d8881..a34f2c9d 100644
--- a/apps/android/app/src/main/kotlin/com/codync/android/LocalStore.kt
+++ b/apps/android/app/src/main/kotlin/com/codync/android/LocalStore.kt
@@ -17,7 +17,7 @@ import javax.crypto.spec.GCMParameterSpec
import kotlinx.serialization.json.Json
/** Account-scoped, atomic storage excluded from both backup and device transfer. */
-class LocalStore(context: Context, val contextId: String = "local") {
+class LocalStore(private val context: Context, val contextId: String = "local") {
private val scopeId = MessageDigest.getInstance("SHA-256").digest(contextId.toByteArray())
.joinToString("") { "%02x".format(it) }
val referenceId = referenceId(contextId)
@@ -84,6 +84,11 @@ class LocalStore(context: Context, val contextId: String = "local") {
for (file in from.directory.listFiles().orEmpty().filter { !it.name.startsWith("identity") }) {
file.copyRecursively(File(directory, file.name), overwrite = true)
}
+ // Drafts and queued messages name their files by full path: point them at the copies here.
+ for (computer in from.computers()) {
+ DraftBook(directory, computer.id).relocate(from.directory)
+ MirrorDatabase.relocate(context, directory, computer.id, from.directory)
+ }
true
} catch (error: Exception) {
android.util.Log.w("Codync", "Couldn't move the signed-out device key", error)
diff --git a/apps/android/app/src/main/kotlin/com/codync/android/MirrorDatabase.kt b/apps/android/app/src/main/kotlin/com/codync/android/MirrorDatabase.kt
index df30d14f..66100847 100644
--- a/apps/android/app/src/main/kotlin/com/codync/android/MirrorDatabase.kt
+++ b/apps/android/app/src/main/kotlin/com/codync/android/MirrorDatabase.kt
@@ -26,6 +26,10 @@ class MirrorDatabase(context: Context, directory: File, computerId: String) :
}
/** Deletes a computer's mirror with its journal files, once it's closed. */
fun delete(directory: File, computerId: String) { SQLiteDatabase.deleteDatabase(file(directory, computerId)) }
+ /** A mirror [LocalStore.adopt] copied from account folder [from]: its queued messages name this folder's copies of their files. */
+ fun relocate(context: Context, directory: File, computerId: String, from: File) {
+ if (file(directory, computerId).exists()) MirrorDatabase(context, directory, computerId).use { it.relocate(from, directory) }
+ }
}
override fun onCreate(db: SQLiteDatabase) {
@@ -87,7 +91,7 @@ class MirrorDatabase(context: Context, directory: File, computerId: String) :
rows(db, "SELECT payload FROM bots WHERE deleted=0") { WireJson.decodeFromString<Bot>(it) }
.map { it.copy(customIcon = icons["bot:${it.id}"]) },
rows(db, "SELECT payload FROM entries ORDER BY seq") { WireJson.decodeFromString<Entry>(it) },
- rows(db, "SELECT payload FROM pending ORDER BY created") { WireJson.decodeFromString<PendingSend>(it) },
+ pending(db, "ORDER BY created"),
meta(db, "rev")?.toLong() ?: 0,
meta(db, "usage")?.let { WireJson.parseToJsonElement(it).jsonObject } ?: JsonObject(emptyMap()),
meta(db, "screen")?.let { WireJson.parseToJsonElement(it).jsonObject },
@@ -156,9 +160,11 @@ class MirrorDatabase(context: Context, directory: File, computerId: String) :
}
@Synchronized fun discard(nonce: String) = transaction { it.delete("pending", "nonce=?", arrayOf(nonce)) }
@Synchronized fun recoverInterrupted() = transaction { db ->
- rows(db, "SELECT payload FROM pending") { WireJson.decodeFromString<PendingSend>(it) }
- .filter { it.status == SendStatus.Sending }.forEach { writePending(db, it.copy(status = SendStatus.Failed,
- error = "Sending was interrupted. Retry uses the same message ID.")) }
+ pending(db).filter { it.status == SendStatus.Sending }.forEach { writePending(db, it.copy(status = SendStatus.Failed,
+ error = "Sending was interrupted. Retry uses the same message ID.")) }
+ }
+ @Synchronized private fun relocate(from: File, to: File) = transaction { db ->
+ pending(db).forEach { writePending(db, it.copy(files = it.files.map { file -> AttachmentFiles.moved(file, from, to) })) }
}
@Synchronized fun historyComplete(botId: String): Boolean = readableDatabase.rawQuery(
"SELECT 1 FROM history WHERE lane=?", arrayOf(botId)).use { it.moveToFirst() }
@@ -174,8 +180,7 @@ class MirrorDatabase(context: Context, directory: File, computerId: String) :
}, SQLiteDatabase.CONFLICT_REPLACE) != -1L) { "Couldn't save the bot update." }
if (bot.deleted) {
db.delete("entries", "bot_id=?", arrayOf(bot.id))
- rows(db, "SELECT payload FROM pending") { WireJson.decodeFromString<PendingSend>(it) }
- .filter { it.botId == bot.id }.forEach { db.delete("pending", "nonce=?", arrayOf(it.nonce)) }
+ pending(db).filter { it.botId == bot.id }.forEach { db.delete("pending", "nonce=?", arrayOf(it.nonce)) }
db.delete("history", "lane=?", arrayOf(bot.id))
}
}
@@ -211,6 +216,8 @@ class MirrorDatabase(context: Context, directory: File, computerId: String) :
"Couldn't save the conversation checkpoint."
}
}
+ private fun pending(db: SQLiteDatabase, order: String = "") =
+ rows(db, "SELECT payload FROM pending $order") { WireJson.decodeFromString<PendingSend>(it) }
private fun <T> rows(db: SQLiteDatabase, query: String, decode: (String) -> T): List<T> = db.rawQuery(query, null).use {
buildList { while (it.moveToNext()) add(decode(it.getString(0))) }
}
diff --git a/apps/android/app/src/main/kotlin/com/codync/android/WelcomeView.kt b/apps/android/app/src/main/kotlin/com/codync/android/WelcomeView.kt
index 9b7ca77e..54c6895c 100644
--- a/apps/android/app/src/main/kotlin/com/codync/android/WelcomeView.kt
+++ b/apps/android/app/src/main/kotlin/com/codync/android/WelcomeView.kt
@@ -90,7 +90,13 @@ import kotlin.math.sin
.replace("{count}", signedOutComputers.toString()),
Modifier.fillMaxWidth().padding(bottom = 4.dp), style = Type.footnote, color = Palette.secondary)
if (state.account.configured) SignInButtons(state, store) else WideButton("Get started", action = start)
- state.account.error?.let { Text(it, style = Type.footnote, color = Palette.danger) }
+ // Restoring sign-in failed (the only account error): Clerk retries on its own with a backoff of up to a minute; Try again asks now.
+ state.account.error?.let {
+ Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(8.dp)) {
+ Text(it, Modifier.weight(1f, fill = false), style = Type.footnote, color = Palette.danger)
+ IconButton("Try again", "arrow.clockwise") { store.retryAccounts() }
+ }
+ }
}
}
}
diff --git a/apps/ios/App/AccountSession.swift b/apps/ios/App/AccountSession.swift
index d16a9257..409693bd 100644
--- a/apps/ios/App/AccountSession.swift
+++ b/apps/ios/App/AccountSession.swift
@@ -47,6 +47,19 @@ final class AccountSession {
}
return isReady
}
+ /// Clerk gave up restoring (launched offline, an outage) and tries again only when the app comes back to the
+ /// foreground, so the welcome offers `retryRestore()`. Clears itself once Clerk loads.
+ var restoreFailed: Bool { restoreGaveUp && !isReady }
+ private var restoreGaveUp = false
+
+ /// Clerk's launch refresh again: the environment and the client it restores sign-in from.
+ func retryRestore() async {
+ guard let clerk, restoreFailed else { return }
+ restoreGaveUp = false
+ _ = try? await clerk.refreshEnvironment()
+ _ = try? await clerk.refreshClient()
+ restoreGaveUp = !isReady
+ }
/// The Codync cloud (accounts and the encrypted relay); nil in builds without one.
let cloudURL: URL?
var isSignedIn: Bool { userID != nil }
@@ -74,6 +87,8 @@ final class AccountSession {
telemetryEnabled: false,
redirectConfig: .init(redirectUrl: "\(scheme)://callback", callbackUrlScheme: scheme)
))
+ // Clerk's own launch refresh tries three times within a few seconds, then only logs.
+ Task { restoreGaveUp = !(await waitUntilReady(timeout: .seconds(10))) }
if key.hasPrefix("pk_test_"), let ticket = env["CODYNC_DEV_SIGN_IN_TICKET"], !ticket.isEmpty {
Task { await signInForDevelopment(ticket: ticket) }
}
diff --git a/apps/ios/Kit/Sources/CodyncKit/Client/SharedStore.swift b/apps/ios/Kit/Sources/CodyncKit/Client/SharedStore.swift
index 3a3165cd..3e15fa96 100644
--- a/apps/ios/Kit/Sources/CodyncKit/Client/SharedStore.swift
+++ b/apps/ios/Kit/Sources/CodyncKit/Client/SharedStore.swift
@@ -114,12 +114,15 @@ public enum SharedStore {
DeviceIdentity.delete(context: self)
do { try ActivityIconCache.erase(context: id) }
catch { Logger(subsystem: "com.pokai.Codync", category: "CustomIcon").error("Cannot erase activity icons: \(error.localizedDescription)") }
+ for file in mirrorCaches() { try? FileManager.default.removeItem(at: file) }
+ }
+
+ /// This context's mirror caches (`BotStore.saveCache`): `codync-mirror-<app>-<id>-<computer>.json`.
+ fileprivate func mirrorCaches() -> [URL] {
let caches = URL.cachesDirectory
- let marker = "-\(id)-"
- for file in (try? FileManager.default.contentsOfDirectory(atPath: caches.path())) ?? []
- where file.hasPrefix("codync-mirror-") && file.contains(marker) {
- try? FileManager.default.removeItem(at: caches.appending(path: file))
- }
+ return ((try? FileManager.default.contentsOfDirectory(atPath: caches.path())) ?? [])
+ .filter { $0.hasPrefix("codync-mirror-") && $0.contains("-\(id)-") }
+ .map { caches.appending(path: $0) }
}
}
}
@@ -150,6 +153,12 @@ public extension SharedStore.Context {
return merge(moving)
}
for name in Self.names { defaults.set(local.defaults.object(forKey: local.key(name)), forKey: key(name)) }
+ // Unsent and failed messages live only in the mirror caches: they come along rather than go with `erase()`.
+ for file in local.mirrorCaches() {
+ let name = file.lastPathComponent
+ guard let marker = name.range(of: "-\(local.id)-") else { continue }
+ try? FileManager.default.moveItem(at: file, to: file.deletingLastPathComponent().appending(path: name.replacingCharacters(in: marker, with: "-\(id)-")))
+ }
return Adoption(computers: moving.count, keys: .moved)
}
return merge(moving)
diff --git a/apps/ios/Kit/Tests/CodyncKitTests/SignedOutAdoptionTests.swift b/apps/ios/Kit/Tests/CodyncKitTests/SignedOutAdoptionTests.swift
index adb010ef..0a4dc6d3 100644
--- a/apps/ios/Kit/Tests/CodyncKitTests/SignedOutAdoptionTests.swift
+++ b/apps/ios/Kit/Tests/CodyncKitTests/SignedOutAdoptionTests.swift
@@ -20,10 +20,15 @@ import Testing
let key = try DeviceIdentity.load(context: local)
local.computers = [v.computer]
local.composerDrafts = [v.computer.id: ["b1": "draft"]]
+ let cache = URL.cachesDirectory.appending(path: "codync-mirror-tests-\(local.id)-\(v.computer.id).json")
+ try Data("unsent".utf8).write(to: cache)
#expect(account.adopt(from: local) == .init(computers: 1, keys: .moved))
#expect(account.computers == [v.computer])
#expect(account.composerDrafts[v.computer.id]?["b1"] == "draft")
+ let movedCache = URL.cachesDirectory.appending(path: "codync-mirror-tests-\(account.id)-\(v.computer.id).json")
+ #expect(try Data(contentsOf: movedCache) == Data("unsent".utf8), "unsent messages come along")
+ #expect(!FileManager.default.fileExists(atPath: cache.path()))
let moved = try DeviceIdentity.load(context: account)
#expect(moved.publicKey == key.publicKey, "hosts see the same device")
#expect(moved.pushKey == key.pushKey, "push keeps opening")
diff --git a/apps/ios/Views/WelcomeView.swift b/apps/ios/Views/WelcomeView.swift
index e9b79812..4c83da5a 100644
--- a/apps/ios/Views/WelcomeView.swift
+++ b/apps/ios/Views/WelcomeView.swift
@@ -83,7 +83,17 @@ struct WelcomeView: View {
Text(message).font(.footnote).foregroundStyle(Palette.danger)
.transition(.opacity)
}
+ if account.restoreFailed {
+ HStack(spacing: 8) {
+ Text(L10n.tr("Couldn't restore sign-in. Check your connection and retry."))
+ .font(.footnote).foregroundStyle(Palette.danger)
+ .fixedSize(horizontal: false, vertical: true)
+ IconButton("Try again", systemImage: "arrow.clockwise") { Task { await account.retryRestore() } }
+ }
+ .transition(.opacity)
+ }
}
+ .animation(Motion.fade, value: account.restoreFailed)
.rise(beat >= 4)
}
.padding(.horizontal, 24)
diff --git a/docs/plans/require-sign-in.md b/docs/plans/require-sign-in.md
index 9b527c18..5ac82e79 100644
--- a/docs/plans/require-sign-in.md
+++ b/docs/plans/require-sign-in.md
@@ -64,6 +64,7 @@ The two calls are best effort, with a short timeout each. Signing out never fail
| --- | --- | --- |
| Configured | Restoring (`isReady == false`) | The launch splash. The last active context stays loaded, as `AppStore.init` already does, so an offline launch keeps working |
| Configured | Ready, signed out | The sign-in screen |
+| Configured | Restore failed (offline launch, Clerk outage) | With no last account context: the sign-in screen with its buttons disabled, "Couldn't restore sign-in" and a Try again button (Android: `AccountStore.retryAccounts` → `Clerk.reinitialize`, sooner than Clerk's own retry, which backs off to a minute; iPhone, where Clerk retries only on returning to the foreground: `AccountSession.retryRestore`, shown once Clerk isn't loaded 10 seconds after launch). The desktop instead stays "restoring" and retries every 30 seconds |
| Configured | Signed in | Today's flow: pairing when there's no computer, else the tabs |
| Not configured | — | Today's flow, signed-out context |
@@ -102,14 +103,14 @@ After either case the signed-out context is erased, and when computers moved an
- `SharedStore.Context.adopt(from:)` in the Kit:
- Moves the Keychain items `com.pokai.Codync.device-key` / `push-key` from account `local` to the context id.
- Moves the `UserDefaults` names in `Context.names` to their `account.<id>.` keys.
- - Drops `ActivityIconCache` and the `codync-mirror-local-*` caches, which rebuild.
+ - Drops `ActivityIconCache`, which rebuilds. When the keys move, the signed-out mirror caches are renamed into the account's, since they hold the messages not yet sent; otherwise they go.
- The Kit's test bundle has no Keychain entitlement, so its tests keep keys in memory (`Keychain.memory`, debug builds only).
- Unit tests in `CodyncKitTests` cover both cases.
**Android**
- `LocalStore.adopt(from)`:
- The identity is sealed with a per-scope Keystore alias and AAD, so the seeds are decrypted with the old key and sealed again under the new scope.
- - Every other file in the folder is copied.
+ - Every other file in the folder is copied. Drafts and queued messages name their attachments by full path, so after the copy they're pointed at the new folder's `outgoing/` (`AttachmentFiles.moved`, `DraftBook.relocate`, `MirrorDatabase.relocate`).
- In the merge case only `computers.json` merges.
- Unit tests cover both cases.