desktop: syncs on its own — at launch, soon after an edit, every few minutes and on focus
Android / Build, or is the channel already serving this? (push) Successful in 5s
CI & Build / Build now, or wait for Android? (push) Successful in 2s
CI & Build / Python lint (push) Successful in 2s
CI & Build / Web typecheck and unit tests (push) Successful in 13s
CI & Build / Python tests (push) Successful in 14s
Desktop (Tauri) / Build, or is the channel already serving this? (push) Successful in 2s
CI & Build / integration (push) Successful in 47s
CI & Build / Build & push image (push) Skipped
Desktop (Tauri) / Web tests, clippy, Rust tests and rustfmt (push) Successful in 3m8s
Desktop (Tauri) / Windows installer (cross-compiled) (push) Successful in 2m53s
Desktop (Tauri) / Tauri desktop (Linux) (push) Successful in 4m47s
Desktop (Tauri) / Update manifest (push) Successful in 6s
Android / Kotlin + Rust (APK) (push) Successful in 11m34s
Android / Build, or is the channel already serving this? (push) Successful in 5s
CI & Build / Build now, or wait for Android? (push) Successful in 2s
CI & Build / Python lint (push) Successful in 2s
CI & Build / Web typecheck and unit tests (push) Successful in 13s
CI & Build / Python tests (push) Successful in 14s
Desktop (Tauri) / Build, or is the channel already serving this? (push) Successful in 2s
CI & Build / integration (push) Successful in 47s
CI & Build / Build & push image (push) Skipped
Desktop (Tauri) / Web tests, clippy, Rust tests and rustfmt (push) Successful in 3m8s
Desktop (Tauri) / Windows installer (cross-compiled) (push) Successful in 2m53s
Desktop (Tauri) / Tauri desktop (Linux) (push) Successful in 4m47s
Desktop (Tauri) / Update manifest (push) Successful in 6s
Android / Kotlin + Rust (APK) (push) Successful in 11m34s
Until now the only caller of the sync engine was the "Sync now" button. A worker thread now owns every cycle (the button's included, so two never overlap): - launch: one cycle as the app opens; - edit: every 10s it reads a fingerprint of the pending set and sends when that moved. A fingerprint rather than "anything pending", because a rejected change stays pending and would otherwise be resent every tick forever; - timer: a pull every 5 minutes with nothing to send; - focus: at most once per 30s. Failed automatic cycles back off (doubling from 10s to 5 minutes). A panicking cycle counts as a failed one rather than ending the thread. Every cycle is emitted as inkwell://synced: the board reloads when the pull changed something, and the Sync screen shows the last automatic failure. No final push on quit; the launch cycle sends whatever was left. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -157,6 +157,38 @@ export interface LinkInput {
|
||||
name?: string;
|
||||
}
|
||||
|
||||
/** What started a sync cycle (autosync.rs). */
|
||||
export type SyncTrigger = "launch" | "edit" | "timer" | "focus" | "manual";
|
||||
|
||||
/**
|
||||
* The most recent cycle, automatic or not. The desktop syncs on its own (at launch,
|
||||
* soon after an edit, every few minutes and on focus), so most cycles have no
|
||||
* button press to report back to — this is how the screen hears about them.
|
||||
*/
|
||||
export interface LastCycle {
|
||||
at_ms: number;
|
||||
trigger: SyncTrigger;
|
||||
ok: boolean;
|
||||
error: string | null;
|
||||
/** Whether the pull changed anything this device shows. */
|
||||
changed: boolean;
|
||||
outcome: SyncOutcome | null;
|
||||
}
|
||||
|
||||
/** Fired at every window after each cycle, with a LastCycle as the payload. */
|
||||
const SYNCED_EVENT = "inkwell://synced";
|
||||
|
||||
/**
|
||||
* Run `handler` after every sync cycle. Returns an unlisten function, or a no-op
|
||||
* where there is no event API (the web build) — nothing syncs in the background
|
||||
* there, so there is nothing to hear.
|
||||
*/
|
||||
export async function onSynced(handler: (cycle: LastCycle) => void): Promise<() => void> {
|
||||
const events = window.__TAURI__?.event;
|
||||
if (!events) return () => {};
|
||||
return events.listen<LastCycle>(SYNCED_EVENT, (e) => handler(e.payload));
|
||||
}
|
||||
|
||||
export const sync = {
|
||||
/** Ask who's at an address without committing to anything. */
|
||||
probe: (url: string) => invoke<ProbeResult>("sync_probe", { url }),
|
||||
@@ -169,6 +201,8 @@ export const sync = {
|
||||
* without pushing first overwrites unsent local edits.
|
||||
*/
|
||||
now: () => invoke<SyncOutcome>("sync_now"),
|
||||
/** The last cycle, or null before the first one. */
|
||||
last: () => invoke<LastCycle | null>("sync_last"),
|
||||
hasPending: () => invoke<boolean>("sync_has_pending"),
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user