mirror of
https://git.undefined-dev.fr/Blendman974/faceclaw.git
synced 2026-11-19 21:03:09 +00:00
45 lines
1.5 KiB
TypeScript
45 lines
1.5 KiB
TypeScript
import { Dialogs, Utils } from "@nativescript/core";
|
|
|
|
declare const FaceclawCalendar: any;
|
|
|
|
export function hasCalendarPermission(): boolean {
|
|
return FaceclawCalendar.shared().hasPermission();
|
|
}
|
|
|
|
let pending: Promise<boolean> | null = null;
|
|
|
|
export function ensureCalendarPermission(): Promise<boolean> {
|
|
if (hasCalendarPermission()) return Promise.resolve(true);
|
|
if (!pending) pending = requestPermission().finally(() => { pending = null; });
|
|
return pending;
|
|
}
|
|
|
|
async function requestPermission(): Promise<boolean> {
|
|
const calendar = FaceclawCalendar.shared();
|
|
const status = String(calendar.permissionStatus());
|
|
if (status === "denied") {
|
|
const open = await Dialogs.confirm({
|
|
title: "Calendar Access",
|
|
message: "Allow calendar access in Settings to display your events on the glasses. On iOS 17 or later, choose Full Access.",
|
|
okButtonText: "Open Settings",
|
|
cancelButtonText: "Cancel",
|
|
});
|
|
if (open) Utils.openUrl("app-settings:");
|
|
return false;
|
|
}
|
|
if (status === "restricted") {
|
|
await Dialogs.alert({
|
|
title: "Calendar Access Restricted",
|
|
message: "Calendar access is restricted on this iPhone. Check Screen Time or device management settings.",
|
|
okButtonText: "OK",
|
|
});
|
|
return false;
|
|
}
|
|
return new Promise<boolean>((resolve, reject) => {
|
|
calendar.requestPermission((granted: boolean, error: string | null) => {
|
|
if (error) reject(new Error(String(error)));
|
|
else resolve(granted);
|
|
});
|
|
});
|
|
}
|