iOS calendar integration

This commit is contained in:
James Babcock committed 2026-09-19 20:52:36 -07:00
1 parent 50431c7c6f
commit 32063e57cd
18 files changed
+646 -37

No files matched your search

+15 -7
View File
@@ -1,5 +1,5 @@
import { ensureCalendarPermission, hasCalendarPermission } from "../../g2/android-permissions";
import { invalidateCalendarCache } from "../../native/calendar";
import { ensureCalendarPermission, hasCalendarPermission } from "../../native/calendar-permissions";
import { invalidateCalendarCache, onCalendarChanged } from "../../native/calendar";
import { makeImageWindowIcon, windowIcon } from "../../ui/shell/chrome-layer";
import { CalendarLayer } from "./calendar";
import { renderCalendarDateIcon } from "./calendar-icon";
@@ -14,25 +14,27 @@ export const CALENDAR_WINDOW_ID = "calendar";
export const CALENDAR_SURFACE_ID = "window:calendar";
/**
* The Calendar app: a single screen listing upcoming events from the Android
* Calendar provider. If calendar permission is missing it shows a prompt and
* The Calendar app: a single screen listing upcoming events from the phone's
* calendars. If calendar permission is missing it shows a prompt and
* fires the system permission dialog (on launch and on any tap); once granted
* it re-renders with the event list.
*/
export function createCalendarAppWindow(options: InProcessAppOptions): InProcessWindow {
let requesting = false;
let app: InProcessWindow;
let unsubscribe = () => {};
let tick: ReturnType<typeof setInterval> | null = null;
const requestPermission = () => {
if (requesting || hasCalendarPermission()) return;
requesting = true;
void ensureCalendarPermission().then((granted) => {
requesting = false;
if (granted) {
invalidateCalendarCache();
app.requestRender();
}
});
}).catch(error => console.warn("Calendar permission failed", error))
.finally(() => { requesting = false; });
};
app = createInProcessWindow({
@@ -48,9 +50,15 @@ export function createCalendarAppWindow(options: InProcessAppOptions): InProcess
submitFrame: options.submitFrame,
setSurfaceVisible: options.setSurfaceVisible,
removeSurface: options.removeSurface,
onClosed: options.onClosed,
onClosed: () => {
unsubscribe();
if (tick !== null) clearInterval(tick);
options.onClosed();
},
});
unsubscribe = onCalendarChanged(app.requestRender);
tick = setInterval(app.requestRender, 30_000);
// Prompt immediately on launch so the user doesn't have to discover the tap.
requestPermission();
return app;
+5 -3
View File
@@ -2,10 +2,10 @@ import { getDefaultSmallFont } from "../../graphics/ui-fonts";
import { GrayImage, type UiFont } from "../../graphics/image";
import { wrapText, truncateText } from "../../graphics/textwrap";
import { clamp } from "../../util/numeric-util";
import { readUpcomingEvents, type CalendarEvent } from "../../native/calendar";
import { getCalendarReadState, readUpcomingEvents, type CalendarEvent } from "../../native/calendar";
import { timeFormatSetting } from "../../ui/dashboard-settings";
import { GESTURE_CLICK, type InputEvent } from "../../ui/gestures";
import { hasCalendarPermission } from "../../g2/android-permissions";
import { hasCalendarPermission } from "../../native/calendar-permissions";
import { type Layer, type LayerContext } from "../../ui/layers";
import { lineStep } from "../../ui/metrics";
@@ -58,7 +58,9 @@ export class CalendarLayer implements Layer {
const events = readUpcomingEvents(MAX_EVENTS);
if (!events.length) {
image.drawText(font, TITLE_X, TITLE_Y, "Calendar", 220);
image.drawText(font, 24, 72, "No upcoming events.", 190);
const state = getCalendarReadState();
image.drawText(font, 24, 72, state === "loading" ? "Loading calendar..."
: state === "error" ? "Calendar unavailable. Try again shortly." : "No upcoming events.", 190);
return image;
}
@@ -1,8 +1,8 @@
import { type GrayImage, type UiFont } from "../../../graphics/image";
import { truncateText } from "../../../graphics/textwrap";
import { getDefaultMediumFont, getDefaultSmallFont } from "../../../graphics/ui-fonts";
import { hasCalendarPermission } from "../../../g2/android-permissions";
import { readUpcomingEvents, type CalendarEvent } from "../../../native/calendar";
import { hasCalendarPermission } from "../../../native/calendar-permissions";
import { getCalendarReadState, onCalendarChanged, readUpcomingEvents, type CalendarEvent } from "../../../native/calendar";
import { lineStep } from "../../../ui/metrics";
import { dayHeaderLabel, formatEventTime } from "../../calendar/calendar";
import { type GlanceWidget } from "../widget";
@@ -22,14 +22,19 @@ const HOUR_MS = 60 * MINUTE_MS;
*/
export class CalendarWidget implements GlanceWidget {
private tick: ReturnType<typeof setInterval> | null = null;
private unsubscribe: (() => void) | null = null;
start(requestRender: () => void): void {
this.stop();
this.unsubscribe = onCalendarChanged(requestRender);
this.tick = setInterval(requestRender, MINUTE_MS);
}
stop(): void {
if (this.tick !== null) clearInterval(this.tick);
this.tick = null;
this.unsubscribe?.();
this.unsubscribe = null;
}
paint(image: GrayImage): void {
@@ -50,7 +55,9 @@ export class CalendarWidget implements GlanceWidget {
const events = readUpcomingEvents().filter((event) => event.endMs > nowMs);
if (!events.length) {
image.drawText(small, PAD, PAD, "Calendar", 150);
image.drawText(small, PAD, PAD + step + 4, "No upcoming events", 140);
const state = getCalendarReadState();
image.drawText(small, PAD, PAD + step + 4, state === "loading" ? "Loading calendar..."
: state === "error" ? "Calendar unavailable" : "No upcoming events", 140);
return;
}
-1
View File
@@ -3,7 +3,6 @@ const unavailable: Record<string, string> = {
music: 'Media-player integration is not available on iOS yet.',
transcribe: 'Voice capture and transcription are not available on iOS yet.',
microphones: 'Glasses microphone capture is not available on iOS yet.',
calendar: 'Calendar access is not available on iOS yet.',
}
export function iosAppUnavailableReason(appId: string): string | null {
return unavailable[appId] ?? null