22 lines
1.2 KiB
JavaScript
22 lines
1.2 KiB
JavaScript
import { z } from 'zod';
|
|||
|
|
|
||
|
|
// These names are shared by native IPC guards and the trusted browser chrome.
|
||
|
|
// Hiding a section removes access, rather than only changing its presentation.
|
||
|
|
export const SETTINGS_SECTIONS = Object.freeze(['appearance', 'library', 'ai', 'passwords', 'documentScan', 'agents']);
|
||
|
|
const sections = z.array(z.enum(SETTINGS_SECTIONS)).max(SETTINGS_SECTIONS.length).refine(items => new Set(items).size === items.length, 'Settings sections must be unique');
|
||
|
|
export const ManagedSettingsSchema = z.object({
|
||
|
|
visible: z.boolean().default(true),
|
||
|
|
hiddenSections: sections.default([]),
|
||
|
|
lockedSections: sections.default([]),
|
||
|
|
appearance: z.object({
|
||
|
|
mode: z.enum(['system', 'light', 'dark']).default('system'),
|
||
|
|
accent: z.enum(['blue', 'teal', 'violet']).default('blue'),
|
||
|
|
tabMode: z.enum(['separate', 'compact']).default('separate')
|
||
|
|
}).strict().prefault({})
|
||
|
|
}).strict().prefault({});
|
||
|
|
|
||
|
|
export function settingsSectionAllowed(policy, section) {
|
||
|
|
if (!SETTINGS_SECTIONS.includes(section)) return false;
|
||
|
|
const settings = ManagedSettingsSchema.safeParse(policy?.browser?.settings);
|
||
|
|
return settings.success && settings.data.visible && !settings.data.hiddenSections.includes(section) && !settings.data.lockedSections.includes(section);
|
||
|
|
}
|