feat: add gateway management features and settings
- Implemented new API routes for handling logs and settings related to the gateway. - Added a new Gateway section in the General Settings panel to manage gateway status and auto-start options. - Introduced a state management hook for gateway settings, including status, logs, and auto-start functionality. - Updated configuration service to include gateway auto-start setting. - Enhanced internationalization support for new gateway-related messages. - Refactored existing settings store to accommodate new gateway settings. - Cleaned up code and improved logging functionality.
This commit is contained in:
@@ -6,7 +6,11 @@ import { debounce } from '@runtime/lib/utils'
|
||||
import logManager from '@electron/service/logger'
|
||||
import { getUserDataDir } from '@electron/utils/paths'
|
||||
|
||||
const DEFAULT_CONFIG: IConfig = {
|
||||
type AppConfig = IConfig & {
|
||||
[CONFIG_KEYS.GATEWAY_AUTO_START]: boolean;
|
||||
};
|
||||
|
||||
const DEFAULT_CONFIG: AppConfig = {
|
||||
[CONFIG_KEYS.THEME_MODE]: 'system',
|
||||
[CONFIG_KEYS.PRIMARY_COLOR]: '#BB5BE7',
|
||||
[CONFIG_KEYS.LANGUAGE]: 'zh',
|
||||
@@ -17,14 +21,15 @@ const DEFAULT_CONFIG: IConfig = {
|
||||
[CONFIG_KEYS.SELECTED_CHANNELS]: [],
|
||||
[CONFIG_KEYS.IMAGE_CACHE]: [],
|
||||
[CONFIG_KEYS.TASK_LIST]: [],
|
||||
[CONFIG_KEYS.GATEWAY_AUTO_START]: true,
|
||||
}
|
||||
|
||||
export class ConfigService {
|
||||
private static _instance: ConfigService;
|
||||
private _store: any;
|
||||
private _defaultConfig: IConfig = DEFAULT_CONFIG;
|
||||
private _defaultConfig: AppConfig = DEFAULT_CONFIG;
|
||||
|
||||
private _listeners: Array<(config: IConfig) => void> = [];
|
||||
private _listeners: Array<(config: AppConfig) => void> = [];
|
||||
|
||||
|
||||
private constructor() {
|
||||
@@ -34,7 +39,7 @@ export class ConfigService {
|
||||
public async init() {
|
||||
if (this._store) return;
|
||||
const { default: Store } = await import('electron-store');
|
||||
this._store = new Store<IConfig>({
|
||||
this._store = new Store<AppConfig>({
|
||||
name: 'config',
|
||||
cwd: getUserDataDir(),
|
||||
defaults: DEFAULT_CONFIG,
|
||||
@@ -74,7 +79,7 @@ export class ConfigService {
|
||||
this._listeners.forEach(listener => listener({ ...this._store.store }));
|
||||
}
|
||||
|
||||
public getConfig(): IConfig {
|
||||
public getConfig(): AppConfig {
|
||||
if (!this._store) {
|
||||
return { ...this._defaultConfig };
|
||||
}
|
||||
@@ -98,7 +103,7 @@ export class ConfigService {
|
||||
autoSave && this._notifyListeners();
|
||||
}
|
||||
|
||||
public update(updates: Partial<IConfig>, autoSave: boolean = true): void {
|
||||
public update(updates: Partial<AppConfig>, autoSave: boolean = true): void {
|
||||
this._ensureStore();
|
||||
(Object.keys(updates) as ConfigKeys[]).forEach((key) => {
|
||||
this._store.set(key, updates[key]);
|
||||
@@ -115,7 +120,7 @@ export class ConfigService {
|
||||
this._notifyListeners();
|
||||
}
|
||||
|
||||
public onConfigChange(listener: ((config: IConfig) => void)): () => void {
|
||||
public onConfigChange(listener: ((config: AppConfig) => void)): () => void {
|
||||
this._listeners.push(listener);
|
||||
|
||||
return () => this._listeners = this._listeners.filter(l => l !== listener);
|
||||
|
||||
Reference in New Issue
Block a user