36 lines
1.4 KiB
TypeScript
36 lines
1.4 KiB
TypeScript
import { STORAGE_KEYS } from '@/lib/constants'
|
|
|
|
/**
|
|
* 模块启停状态的统一读取入口。
|
|
*
|
|
* 真相仍是 appStore 持久化的 `appSettings.modules`,但独立窗口(托盘菜单、快速面板等)
|
|
* 以及主窗口挂载前的启动阶段拿不到 Pinia store,只能直接读 localStorage。
|
|
* 把解析逻辑收敛到这里,避免每个入口各写一份(字段/默认值不一致时就会出现
|
|
* “侧边栏隐藏了但标题栏还在”这类偏差)。
|
|
*/
|
|
|
|
/** 默认禁用模块(与各模块 `defaultEnabled` 保持一致;文件缺失时作为兜底) */
|
|
const DEFAULT_DISABLED = ['smarthome']
|
|
|
|
/** 读取已禁用模块集合 */
|
|
export function readDisabledModules(): Set<string> {
|
|
try {
|
|
const raw = localStorage.getItem(STORAGE_KEYS.appSettings)
|
|
if (!raw) return new Set(DEFAULT_DISABLED)
|
|
const parsed = JSON.parse(raw)
|
|
if (!Array.isArray(parsed.modules)) return new Set(DEFAULT_DISABLED)
|
|
const disabled = new Set<string>()
|
|
for (const m of parsed.modules) {
|
|
if (m && typeof m.id === 'string' && m.enabled === false) disabled.add(m.id)
|
|
}
|
|
return disabled
|
|
} catch {
|
|
return new Set(DEFAULT_DISABLED)
|
|
}
|
|
}
|
|
|
|
/** 模块是否启用(主窗口已初始化后应优先使用 appStore,此处用于启动早期 / 独立窗口) */
|
|
export function isModuleEnabled(id: string): boolean {
|
|
return !readDisabledModules().has(id)
|
|
}
|