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
Contacts: labels picked from Apple's own list
Yashwanth Kamireddi0943b3486e8c
diff --git a/.uiverify/contacts-labels.mjs b/.uiverify/contacts-labels.mjsnew file mode 100644index 0000000..303b78b--- /dev/null+++ b/.uiverify/contacts-labels.mjs@@ -0,0 +1,43 @@+// A detail's label is picked from Apple's own list, so the phone reads it as its own+// "work" or "mobile". Anything else is typed in as a custom label.+import { engine } from "./engine.mjs";+import { SERVICES, installStub } from "./stub.mjs";++const b = await engine.launch();+const ctx = await b.newContext({ viewport: { width: 1280, height: 820 } });+await ctx.addInitScript(installStub, { screen: "library", services: SERVICES, twoFactor: null,+ calendarFixture: false, notesFixture: false, contactsFixture: true, driveFixture: false, remindersFixture: false });+const page = await ctx.newPage();+await page.goto("http://localhost:4173", { waitUntil: "networkidle" });+await page.locator(".nav-item", { hasText: "Contacts" }).click();+await page.waitForTimeout(400);+await page.locator(".contact-row", { hasText: "Zoya" }).click();+await page.waitForTimeout(300);+let failures = 0;+const ok = (p, m) => { console.log(`${p ? "PASS" : "FAIL"} ${m}`); if (!p) failures++; };++await page.getByRole("button", { name: "Edit", exact: true }).click();+await page.waitForTimeout(200);+const first = page.getByLabel("Label for detail 1");+ok(/mobile/.test(await first.innerText()) && (await page.getByLabel("Custom label for detail 1").count()) === 0,+ "an existing \"mobile\" shows as Apple's own, not as a custom label");+await first.click();+const offered = await page.getByRole("option").allInnerTexts();+ok(["mobile", "iPhone", "Apple Watch", "work", "custom…"].every((x) => offered.some((o) => o.replace("✓", "").trim() === x)), `Apple's phone labels are offered ${JSON.stringify(offered)}`);+await page.getByRole("option", { name: "work", exact: true }).click();++const second = page.getByLabel("Label for detail 2");+await second.click();+await page.getByRole("option", { name: "custom…" }).click();+const typed = page.getByLabel("Custom label for detail 2");+ok((await typed.count()) === 1, "custom… opens a field to type a label in");+await typed.fill("gym");++await page.getByRole("button", { name: "Save" }).click();+await page.waitForTimeout(300);+const sent = await page.evaluate(() => (window.__contactSaves ?? []).at(-1));+// The save carries the card as edited first (and the one it began from after it).+const labels = (JSON.stringify(sent ?? {}).match(/"label":"[^"]*"/g) ?? []).slice(0, 2);+ok(JSON.stringify(labels) === JSON.stringify(['"label":"WORK"', '"label":"gym"']), `saved in Apple's spelling, and the custom one as typed ${JSON.stringify(labels)}`);+await b.close();+process.exitCode = failures === 0 ? 0 : 1;diff --git a/check.sh b/check.shindex 7766245..52ab7bd 100755--- a/check.sh+++ b/check.sh@@ -48,6 +48,7 @@ step "coming back" node .uiverify/resume.mjsstep "birthdays, holidays" node .uiverify/occasions.mjsstep "drive folders" node .uiverify/drive-nav.mjsstep "birthdays in contacts" node .uiverify/contact-birthday.mjs+step "contact labels" node .uiverify/contacts-labels.mjsstep "empty today" node .uiverify/reminders-empty.mjsstep "calendar keys" node .uiverify/calendar-keys.mjsstep "reminders instant" node .uiverify/reminders-instant.mjs@@ -78,6 +79,7 @@ step "notes tables" node .uiverify/notes-table.mjsstep "reminder menu" node .uiverify/reminders-context.mjsstep "notes media" node .uiverify/notes-media.mjsstep "webkit: tables" env ENGINE=webkit node .uiverify/notes-table.mjs+step "webkit: labels" env ENGINE=webkit node .uiverify/contacts-labels.mjsstep "webkit: row hover" env ENGINE=webkit node .uiverify/row-hover.mjsstep "webkit: fold" env ENGINE=webkit node .uiverify/sidebar-fold.mjsstep "reminder colours" node .uiverify/calendar-reminder-colour.mjsdiff --git a/src/screens/ContactsView.tsx b/src/screens/ContactsView.tsxindex a1ca338..4b69bff 100644--- a/src/screens/ContactsView.tsx+++ b/src/screens/ContactsView.tsx@@ -30,6 +30,21 @@ const KINDS = [{ value: "url", label: "link" },] as const;+/**+ * Apple's own labels for each kind of detail, as icloud.com's contact editor offers them+ * (contacts2 bundle). Stored in Apple's spelling, so a label picked here reads as the phone's+ * own "mobile" or "work" there, not as a custom label that happens to say the same thing.+ */+const LABELS: Record<string, string[]> = {+ phone: ["MOBILE", "IPHONE", "APPLE WATCH", "HOME", "WORK", "SCHOOL", "MAIN", "HOME FAX", "WORK FAX", "PAGER"],+ email: ["HOME", "WORK", "SCHOOL", "ICLOUD"],+ url: ["HOMEPAGE", "HOME", "WORK", "SCHOOL"],+};+const SHOWN: Record<string, string> = { IPHONE: "iPhone", "APPLE WATCH": "Apple Watch", ICLOUD: "iCloud" };+/** A label as Contacts writes it: Apple's names in their own case, anything else as typed. */+const labelText = (label: string) => SHOWN[label] ?? (label === label.toUpperCase() ? label.toLowerCase() : label);+const CUSTOM = "\u0000custom";+/*** A contact's picture where there is one, initials where there is not.*@@ -96,6 +111,8 @@ export function ContactsView() {const { revision } = useSync();/** The card being written, or null while simply looking. */const [draft, setDraft] = useState<Contact | null>(null);+ /** Details whose label is being typed rather than picked, by their place on the card. */+ const [customAt, setCustomAt] = useState<Set<number>>(() => new Set());/*** The card as the form opened it. Saving writes only what differs from it, over Apple's* card as it is then — so a change made on the phone while the form was open stays.@@ -104,6 +121,7 @@ export function ContactsView() {const edit = (c: Contact) => {draftBase.current = c;setDraft({ ...c });+ setCustomAt(new Set());};const [busy, setBusy] = useState(false);const [lists, setLists] = useState<ContactList[]>([]);@@ -673,13 +691,43 @@ export function ContactsView() {onChange={(kind) => editMethod(index, { kind })}options={KINDS.map((k) => ({ value: k.value, label: k.label }))}/>- <input- className="contact-method-label"- value={m.label ?? ""}- placeholder="label"- aria-label={`Label for detail ${index + 1}`}- onChange={(e) => editMethod(index, { label: e.target.value || null })}- />+ {(() => {+ const standard = LABELS[m.kind] ?? [];+ // Apple's names match whatever their case, so "mobile" is the phone's own.+ const match = standard.find((v) => v === m.label?.toUpperCase());+ const custom = customAt.has(index) || (m.label !== null && !match);+ return (+ <span className="contact-label-cell">+ <Picker+ label={`Label for detail ${index + 1}`}+ className="contact-label-pick"+ value={custom ? CUSTOM : (match ?? "")}+ onChange={(v) => {+ if (v === CUSTOM) {+ setCustomAt((was) => new Set(was).add(index));+ return;+ }+ setCustomAt((was) => { const next = new Set(was); next.delete(index); return next; });+ editMethod(index, { label: v || null });+ }}+ options={[+ ...(m.label === null && !custom ? [{ value: "", label: "no label" }] : []),+ ...standard.map((v) => ({ value: v, label: labelText(v) })),+ { value: CUSTOM, label: "custom…" },+ ]}+ />+ {custom && (+ <input+ className="contact-method-label"+ value={m.label ?? ""}+ placeholder="label"+ aria-label={`Custom label for detail ${index + 1}`}+ onChange={(e) => editMethod(index, { label: e.target.value || null })}+ />+ )}+ </span>+ );+ })()}<inputclassName="contact-method-value"value={m.value}@@ -691,12 +739,14 @@ export function ContactsView() {type="button"className="quiet danger"aria-label={`Remove detail ${index + 1}`}- onClick={() =>+ onClick={() => {setDraft({...draft,methods: draft.methods.filter((_, i) => i !== index),- })- }+ });+ // Places shift up by one; which were being typed is worked out again.+ setCustomAt(new Set());+ }}>✕</button>@@ -711,7 +761,7 @@ export function ContactsView() {onClick={() =>setDraft({...draft,- methods: [...draft.methods, { kind: "phone", label: null, value: "" }],+ methods: [...draft.methods, { kind: "phone", label: "MOBILE", value: "" }],})}>@@ -832,7 +882,7 @@ export function ContactsView() {<dl className="contact-methods">{open.methods.map((m, i) => (<div key={`${m.kind}-${i}`}>- <dt>{m.label?.toLowerCase() || KIND_LABEL[m.kind] || m.kind}</dt>+ <dt>{(m.label && labelText(m.label)) || KIND_LABEL[m.kind] || m.kind}</dt><dd>{m.kind === "email" ? (<a href={`mailto:${m.value}`}>{m.value}</a>diff --git a/src/styles/app.css b/src/styles/app.cssindex 269daa9..cc2a49b 100644--- a/src/styles/app.css+++ b/src/styles/app.css@@ -1485,12 +1485,14 @@/* Kind, label, value, remove — the shape of one line of a card. */.contact-method-rows li {display: grid;- grid-template-columns: 96px 88px minmax(0, 1fr) auto;+ grid-template-columns: 96px 112px minmax(0, 1fr) auto;gap: 6px;align-items: center;}-.contact-kind { width: 100%; }+.contact-kind, .contact-label-pick { width: 100%; }+/* Apple's label picked from a list; a custom one typed under it, in the same column. */+.contact-label-cell { display: flex; flex-direction: column; gap: 4px; min-width: 0; }/* ── Modal sheet ────────────────────────────────────────────────────────────────────────The Move dialog is the app's first modal, so this is the shape everything after it will