- Add comprehensive Channels page with connection statistics and status display - Implement AddChannelDialog with type-specific connection flows: - QR code-based connection for WhatsApp/WeChat - Token-based connection for Telegram/Discord/Slack - Enhance channels store with addChannel, deleteChannel, and requestQrCode actions - Update electron-store usage to dynamic imports for ESM compatibility - Add channel connection instructions and documentation links
138 lines
2.8 KiB
TypeScript
138 lines
2.8 KiB
TypeScript
/**
|
|
* Persistent Storage
|
|
* Electron-store wrapper for application settings
|
|
*/
|
|
|
|
// Lazy-load electron-store (ESM module)
|
|
let settingsStoreInstance: any = null;
|
|
|
|
/**
|
|
* Application settings schema
|
|
*/
|
|
export interface AppSettings {
|
|
// General
|
|
theme: 'light' | 'dark' | 'system';
|
|
language: string;
|
|
startMinimized: boolean;
|
|
launchAtStartup: boolean;
|
|
|
|
// Gateway
|
|
gatewayAutoStart: boolean;
|
|
gatewayPort: number;
|
|
|
|
// Update
|
|
updateChannel: 'stable' | 'beta' | 'dev';
|
|
autoCheckUpdate: boolean;
|
|
autoDownloadUpdate: boolean;
|
|
skippedVersions: string[];
|
|
|
|
// UI State
|
|
sidebarCollapsed: boolean;
|
|
devModeUnlocked: boolean;
|
|
|
|
// Presets
|
|
selectedBundles: string[];
|
|
enabledSkills: string[];
|
|
disabledSkills: string[];
|
|
}
|
|
|
|
/**
|
|
* Default settings
|
|
*/
|
|
const defaults: AppSettings = {
|
|
// General
|
|
theme: 'system',
|
|
language: 'en',
|
|
startMinimized: false,
|
|
launchAtStartup: false,
|
|
|
|
// Gateway
|
|
gatewayAutoStart: true,
|
|
gatewayPort: 18789,
|
|
|
|
// Update
|
|
updateChannel: 'stable',
|
|
autoCheckUpdate: true,
|
|
autoDownloadUpdate: false,
|
|
skippedVersions: [],
|
|
|
|
// UI State
|
|
sidebarCollapsed: false,
|
|
devModeUnlocked: false,
|
|
|
|
// Presets
|
|
selectedBundles: ['productivity', 'developer'],
|
|
enabledSkills: [],
|
|
disabledSkills: [],
|
|
};
|
|
|
|
/**
|
|
* Get the settings store instance (lazy initialization)
|
|
*/
|
|
async function getSettingsStore() {
|
|
if (!settingsStoreInstance) {
|
|
const Store = (await import('electron-store')).default;
|
|
settingsStoreInstance = new Store<AppSettings>({
|
|
name: 'settings',
|
|
defaults,
|
|
});
|
|
}
|
|
return settingsStoreInstance;
|
|
}
|
|
|
|
/**
|
|
* Get a setting value
|
|
*/
|
|
export async function getSetting<K extends keyof AppSettings>(key: K): Promise<AppSettings[K]> {
|
|
const store = await getSettingsStore();
|
|
return store.get(key);
|
|
}
|
|
|
|
/**
|
|
* Set a setting value
|
|
*/
|
|
export async function setSetting<K extends keyof AppSettings>(
|
|
key: K,
|
|
value: AppSettings[K]
|
|
): Promise<void> {
|
|
const store = await getSettingsStore();
|
|
store.set(key, value);
|
|
}
|
|
|
|
/**
|
|
* Get all settings
|
|
*/
|
|
export async function getAllSettings(): Promise<AppSettings> {
|
|
const store = await getSettingsStore();
|
|
return store.store;
|
|
}
|
|
|
|
/**
|
|
* Reset settings to defaults
|
|
*/
|
|
export async function resetSettings(): Promise<void> {
|
|
const store = await getSettingsStore();
|
|
store.clear();
|
|
}
|
|
|
|
/**
|
|
* Export settings to JSON
|
|
*/
|
|
export async function exportSettings(): Promise<string> {
|
|
const store = await getSettingsStore();
|
|
return JSON.stringify(store.store, null, 2);
|
|
}
|
|
|
|
/**
|
|
* Import settings from JSON
|
|
*/
|
|
export async function importSettings(json: string): Promise<void> {
|
|
try {
|
|
const settings = JSON.parse(json);
|
|
const store = await getSettingsStore();
|
|
store.set(settings);
|
|
} catch (error) {
|
|
throw new Error('Invalid settings JSON');
|
|
}
|
|
}
|