CI & Build / Build now, or wait for Android? (push) Successful in 2s
Android / Build, or is the channel already serving this? (push) Successful in 2s
CI & Build / Python lint (push) Successful in 2s
Android / Core and FFI clippy and tests (push) Skipped
Android / Kotlin + Rust (APK) (push) Skipped
Android / Build the server image (push) Skipped
Desktop (Tauri) / Build, or is the channel already serving this? (push) Successful in 2s
CI & Build / Web typecheck and unit tests (push) Successful in 10s
CI & Build / Python tests (push) Successful in 13s
CI & Build / integration (push) Successful in 1m40s
CI & Build / Build & push image (push) Successful in 35s
Desktop (Tauri) / Web tests, clippy, Rust tests and rustfmt (push) Successful in 2m20s
Desktop (Tauri) / Windows installer (cross-compiled) (push) Successful in 2m36s
Desktop (Tauri) / Tauri desktop (Linux) (push) Successful in 3m21s
Desktop (Tauri) / Update manifest (push) Successful in 3s
Milestone 546 "Bring the repo to the comment standard (rule 32) and compose defaults (rule 198)", step #6222 "Comment standard sweep: web client (frontend/)". Comments, docstrings and template notes across frontend/ now say what the code does and the non-obvious why as present-tense facts. Issue, task, note, milestone and family-idea references are gone, along with narration of what used to happen: the titles index's wiki-link origin and its once-per-session load (#5165), the card-controls overlap a phone showed (task 2697), the M7 and M10.9 labels, and the card unification behind the reminders lens (task 1913). Hazards stay as facts, among them LEAVE_MS matching the editor's leave duration, the Android client twin that must not be widened, and keeping leavers in flow in the multi-column masonry. 62 files, comments only: a comment-stripping diff of every changed file against HEAD is identical. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
98 lines
3.7 KiB
TypeScript
98 lines
3.7 KiB
TypeScript
import { defineStore } from "pinia";
|
|
import { ref } from "vue";
|
|
import { repo } from "../adapters";
|
|
import { isDesktop, onReminderDue } from "../desktop/bridge";
|
|
import router from "../router";
|
|
import { useUiStore } from "./ui";
|
|
import type { Note } from "./notes";
|
|
|
|
// Reminder delivery. In a browser it is foreground only, with no Web Push or service
|
|
// worker: while the tab is open, poll for due reminders and surface each once as a
|
|
// toast (and, if the user opted in, a page-context OS notification).
|
|
//
|
|
// The desktop doesn't poll here. Its Rust worker reads the local store, decides what
|
|
// is due, raises the system notification itself when the window isn't in front, and
|
|
// tells this page so it can show the toast. In WebKitGTK the page's `Notification`
|
|
// goes nowhere and its timer stops with the window.
|
|
const POLL_MS = 45_000;
|
|
const RECENT_MS = 15 * 60 * 1000; // on first load, only announce reminders due this recently
|
|
|
|
export const useReminderStore = defineStore("reminders", () => {
|
|
const desktop = isDesktop();
|
|
// The desktop raises its own system notifications; there is nothing to opt into.
|
|
const osSupported = !desktop && typeof Notification !== "undefined";
|
|
const osEnabled = ref(osSupported && Notification.permission === "granted");
|
|
// note id → the remind_at we already fired, so each occurrence notifies at most once.
|
|
const notified = new Map<string, string>();
|
|
let timer: ReturnType<typeof setInterval> | undefined;
|
|
// The desktop's subscription to its reminder worker, held as the promise so stop()
|
|
// can undo one whose registration hasn't finished yet.
|
|
let listening: Promise<() => void> | undefined;
|
|
let primed = false;
|
|
|
|
// Single owner of the reminders endpoint — the RemindersView reads its list through
|
|
// this too, so the URL + response shape live in one place.
|
|
async function fetchReminders(): Promise<Note[]> {
|
|
return repo.notes.reminders();
|
|
}
|
|
|
|
/** Show the in-app toast for a due reminder; returns the title it showed. */
|
|
function toast(id: string, displayTitle: string): string {
|
|
const title = displayTitle || "Reminder";
|
|
useUiStore().showToast(`⏰ ${title}`, {
|
|
label: "Open",
|
|
run: () => void router.push({ path: "/", query: { open: id } }),
|
|
});
|
|
return title;
|
|
}
|
|
|
|
async function check(): Promise<void> {
|
|
let notes: Note[];
|
|
try {
|
|
notes = await fetchReminders();
|
|
} catch {
|
|
return;
|
|
}
|
|
const now = Date.now();
|
|
for (const n of notes) {
|
|
if (!n.remind_at) continue;
|
|
const due = Date.parse(n.remind_at);
|
|
if (due > now || notified.get(n.id) === n.remind_at) continue;
|
|
notified.set(n.id, n.remind_at);
|
|
// Silently prime a stale backlog on first load; only announce recently-due ones.
|
|
if (!primed && now - due > RECENT_MS) continue;
|
|
const title = toast(n.id, n.display_title);
|
|
if (osEnabled.value) {
|
|
try {
|
|
new Notification("Inkwell reminder", { body: title });
|
|
} catch {
|
|
/* notifications unavailable — the toast still fired */
|
|
}
|
|
}
|
|
}
|
|
primed = true;
|
|
}
|
|
|
|
function start(): void {
|
|
if (desktop) {
|
|
if (!listening) listening = onReminderDue((r) => void toast(r.id, r.title));
|
|
return;
|
|
}
|
|
if (timer) return;
|
|
void check();
|
|
timer = setInterval(() => void check(), POLL_MS);
|
|
}
|
|
function stop(): void {
|
|
if (timer) clearInterval(timer);
|
|
timer = undefined;
|
|
void listening?.then((off) => off());
|
|
listening = undefined;
|
|
}
|
|
async function enableOs(): Promise<void> {
|
|
if (!osSupported) return;
|
|
osEnabled.value = (await Notification.requestPermission()) === "granted";
|
|
}
|
|
|
|
return { osSupported, osEnabled, start, stop, enableOs, fetchReminders };
|
|
});
|