forked from Blendman974/faceclaw
iOS calendar integration
This commit is contained in:
1 parent
50431c7c6f
commit
32063e57cd
18 files changed
+646
-37
No files matched your search
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user