forked from Blendman974/faceclaw
23 lines
976 B
TypeScript
23 lines
976 B
TypeScript
import { Utils } from "@nativescript/core";
|
|
import { hasCalendarPermission } from "./calendar-permissions";
|
|
|
|
declare const com: any;
|
|
|
|
export type CalendarSource = { id: string; name: string; accountName: string; accountType: string };
|
|
|
|
/** Android calendar IDs survive renames and distinguish equal display names. */
|
|
export function readAvailableCalendars(): CalendarSource[] {
|
|
if (!global.isAndroid || !hasCalendarPermission()) return [];
|
|
try {
|
|
const context = Utils.android.getApplicationContext();
|
|
if (!context) return [];
|
|
const parsed = JSON.parse(String(com.faceclaw.app.FaceclawCalendarProvider.getCalendarsJson(context)));
|
|
if (!Array.isArray(parsed)) return [];
|
|
return parsed.filter(row => row && typeof row.id === "string" && /^\d+$/.test(row.id))
|
|
.map(row => ({ id: row.id, name: String(row.name ?? ""),
|
|
accountName: String(row.accountName ?? ""), accountType: String(row.accountType ?? "") }));
|
|
} catch {
|
|
return [];
|
|
}
|
|
}
|