feat(electron): add tray menu settings (#11437)

fix AF-2447
This commit is contained in:
pengx17
2025-04-03 15:56:52 +00:00
parent 0aeb3041b5
commit 8ce10e6d0a
19 changed files with 330 additions and 150 deletions

View File

@@ -38,4 +38,11 @@ export class WorkspaceDialogService extends Service {
})
);
}
closeAll() {
const dialogs = this.dialogs$.value;
dialogs.forEach(dialog => {
this.close(dialog.id);
});
}
}

View File

@@ -9,6 +9,7 @@ import { CurrentUserDBEditorSettingProvider } from './impls/user-db';
import { EditorSettingProvider } from './provider/editor-setting-provider';
import { EditorSettingService } from './services/editor-setting';
import { SpellCheckSettingService } from './services/spell-check-setting';
import { TraySettingService } from './services/tray-settings';
export type { FontFamily } from './schema';
export { EditorSettingSchema, fontStyleOptions } from './schema';
export { EditorSettingService } from './services/editor-setting';
@@ -30,3 +31,7 @@ export function configureSpellCheckSettingModule(framework: Framework) {
DesktopApiService,
]);
}
export function configureTraySettingModule(framework: Framework) {
framework.service(TraySettingService, [GlobalStateService]);
}

View File

@@ -0,0 +1,28 @@
import type {
MenubarStateKey,
MenubarStateSchema,
} from '@affine/electron/main/shared-state-schema';
import { LiveData, Service } from '@toeverything/infra';
import type { GlobalStateService } from '../../storage';
const MENUBAR_SETTING_KEY: typeof MenubarStateKey = 'menubarState';
export class TraySettingService extends Service {
constructor(private readonly globalStateService: GlobalStateService) {
super();
}
setting$ = LiveData.from(
this.globalStateService.globalState.watch<MenubarStateSchema>(
MENUBAR_SETTING_KEY
),
null
).map(v => v ?? { enabled: true });
setEnabled(enabled: boolean) {
this.globalStateService.globalState.set(MENUBAR_SETTING_KEY, {
enabled,
});
}
}