Native iCloud apps for Windows and Linux, built in Rust. Notes, Reminders, Calendar, Contacts, Drive and Photos, offline and in sync with your iPhone.
Rust apple-notesapple-reminderscloudkitcrdtdesktop-appicloudicloud-calendaricloud-driveicloud-notesicloud-photosiphonelinuxlinux-desktoplocal-firstoffline-firstprivacyrusttauritauri-appwindows
Settings: Appearance and First Day of Week reach every open window
Yashwanth Kamireddic9d1565d1da5
diff --git a/.uiverify/settings-windows.mjs b/.uiverify/settings-windows.mjsnew file mode 100644index 0000000..0a288de--- /dev/null+++ b/.uiverify/settings-windows.mjs@@ -0,0 +1,48 @@+// Settings applies in every window, not only the one it is open in: each app has a window of+// its own (Notes, Calendar, …), and one closed is kept hidden for ten minutes to come back.+// Appearance and First Day of Week chosen in the library window reach a Calendar window that is+// already open, at once.+//+// URL=http://localhost:4203 ENGINE=webkit node .uiverify/settings-windows.mjs+import { engine, engineName } from "./engine.mjs";+import { SERVICES, installStub, openScreen } from "./stub.mjs";+const URL = process.env.URL ?? "http://localhost:4173";+const b = await engine.launch();+let failures = 0;+const ok = (p, m) => { console.log(`${p ? "PASS" : "FAIL"} ${engineName} ${m}`); if (!p) failures++; };++const ctx = await b.newContext({ viewport: { width: 1280, height: 820 }, colorScheme: "light", locale: "en-US" });+await ctx.addInitScript(installStub, { screen: "library", services: SERVICES, twoFactor: null, calendarFixture: true });+const library = await ctx.newPage();+await library.goto(URL, { waitUntil: "networkidle" });+const calendar = await ctx.newPage();+calendar.on("pageerror", (e) => ok(false, `page error: ${e.message}`));+await calendar.goto(`${URL}/?app=calendar`, { waitUntil: "networkidle" });+await calendar.waitForTimeout(300);+if ((await calendar.getByRole("button", { name: "Month", exact: true }).count()) === 0) await openScreen(calendar, "Calendar");+await calendar.getByRole("button", { name: "Month", exact: true }).click();+await calendar.waitForTimeout(200);+const head = () => calendar.evaluate(() => document.querySelector(".cx-weekdays span")?.textContent);+ok((await head()) === "Sun", `the other window's month starts on the locale's Sunday [${await head()}]`);++await library.keyboard.press("Control+,");+await library.locator(".settings-title").waitFor();+await library.getByRole("button", { name: "Dark", exact: true }).click();+await calendar.waitForTimeout(300);+ok((await calendar.evaluate(() => document.documentElement.dataset.theme)) === "dark", "Dark chosen in Settings turns the other window dark too");++await library.getByRole("button", { name: /First Day of Week/ }).click();+await library.getByRole("option", { name: "Monday" }).click();+await calendar.waitForTimeout(300);+ok((await head()) === "Mon", `Monday chosen in Settings starts the other window's month on Monday [${await head()}]`);++await library.getByRole("button", { name: "Automatic", exact: true }).click();+await library.getByRole("button", { name: /First Day of Week/ }).click();+await library.getByRole("option", { name: /^Automatic/ }).click();+await calendar.waitForTimeout(300);+ok((await calendar.evaluate(() => document.documentElement.dataset.theme)) === undefined, "and Automatic follows the system there again");+ok((await head()) === "Sun", `as does the locale's first day [${await head()}]`);++await b.close();+console.log(failures ? `\n${failures} FAILED` : "\nall passed");+process.exit(failures ? 1 : 0);diff --git a/src/lib/theme.ts b/src/lib/theme.tsindex 0ceff82..e892478 100644--- a/src/lib/theme.ts+++ b/src/lib/theme.ts@@ -28,6 +28,17 @@ export function setTheme(theme: Theme) {applyTheme(theme);}+/**+ * The appearance chosen in another window: Settings lives in the library window, and each+ * app's own window (and one put away, hidden, to be shown again) kept the old appearance until+ * it was opened afresh. They share this computer's storage, which says when it changes.+ */+export function followTheme() {+ window.addEventListener("storage", (e) => {+ if (e.key === KEY || e.key === null) applyTheme(storedTheme());+ });+}+/*** The desktop's Increase Contrast, where the engine does not say it itself: on Linux the app* reads the Settings portal (appearance.rs) and the root is marked `data-contrast="more"`,diff --git a/src/main.tsx b/src/main.tsxindex 115843e..ceeb880 100644--- a/src/main.tsx+++ b/src/main.tsx@@ -10,13 +10,14 @@ import "./styles/calendar.css";import "./styles/notes.css";import "./styles/photos.css";import "./styles/a11y.css";-import { applyTheme, followContrast, storedTheme } from "./lib/theme";+import { applyTheme, followContrast, followTheme, storedTheme } from "./lib/theme";import { keepTinted } from "./lib/tint";import { fadeSheetsIn } from "./lib/fade";import { followClick } from "./lib/follow";// Before the first paint, so the window opens in the appearance chosen.applyTheme(storedTheme());+followTheme();followContrast();keepTinted();fadeSheetsIn();diff --git a/src/screens/calendar/model.ts b/src/screens/calendar/model.tsindex 5464b7e..d4e4bb2 100644--- a/src/screens/calendar/model.ts+++ b/src/screens/calendar/model.ts@@ -99,6 +99,12 @@ export function setWeekStart(choice: WeekStartChoice) {refreshWeek();}/** Calls `run` whenever the week changes; answers the way to stop. */+// The first day chosen in Settings, in the library window, reaches Calendar's own window too.+if (typeof window !== "undefined") {+ window.addEventListener("storage", (e) => {+ if (e.key === WEEK_KEY || e.key === null) refreshWeek();+ });+}export function onWeekChange(run: () => void): () => void {window.addEventListener(WEEK_CHANGED, run);return () => window.removeEventListener(WEEK_CHANGED, run);