mirror of
https://git.undefined-dev.fr/Blendman974/faceclaw.git
synced 2026-11-19 21:03:09 +00:00
20 lines
878 B
TypeScript
20 lines
878 B
TypeScript
import { getStringSetting, setStringSetting } from "./settings-store";
|
|
|
|
export const CALENDAR_SELECTION_KEY = "calendar.selectedIds";
|
|
/** null means all calendars (including future ones); [] explicitly means none. */
|
|
export function readCalendarSelection(): string[] | null {
|
|
try {
|
|
const value = JSON.parse(getStringSetting(CALENDAR_SELECTION_KEY, "null"));
|
|
if (value === null) return null;
|
|
if (!Array.isArray(value) || !value.every(id => typeof id === "string" && /^\d+$/.test(id))) return null;
|
|
return Array.from(new Set<string>(value));
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
export function setCalendarSelection(ids: readonly string[] | null): void {
|
|
if (ids !== null && !ids.every(id => /^\d+$/.test(id))) throw new Error("Invalid calendar ID");
|
|
setStringSetting(CALENDAR_SELECTION_KEY, JSON.stringify(ids === null ? null : Array.from(new Set(ids))));
|
|
}
|