feat(electron): spellcheck setting (#8730)

fix AF-1647
This commit is contained in:
pengx17
2024-11-11 13:03:33 +00:00
parent b3749246f6
commit 35f3fc7b5d
12 changed files with 172 additions and 65 deletions
@@ -15,7 +15,7 @@ type SettingItem<T> = {
readonly value: T;
set: (value: T) => void;
// eslint-disable-next-line rxjs/finnish
$: T;
$: LiveData<T>;
};
export class EditorSetting extends Entity {
@@ -1,10 +1,15 @@
import { type Framework, GlobalState } from '@toeverything/infra';
import {
type Framework,
GlobalState,
GlobalStateService,
} from '@toeverything/infra';
import { UserDBService } from '../userspace';
import { EditorSetting } from './entities/editor-setting';
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';
export type { FontFamily } from './schema';
export { EditorSettingSchema, fontStyleOptions } from './schema';
export { EditorSettingService } from './services/editor-setting';
@@ -18,3 +23,7 @@ export function configureEditorSettingModule(framework: Framework) {
GlobalState,
]);
}
export function configureSpellCheckSettingModule(framework: Framework) {
framework.service(SpellCheckSettingService, [GlobalStateService]);
}
@@ -20,7 +20,6 @@ const AffineEditorSettingSchema = z.object({
fontFamily: z.enum(['Sans', 'Serif', 'Mono', 'Custom']).default('Sans'),
customFontFamily: z.string().default(''),
newDocDefaultMode: z.enum(['edgeless', 'page']).default('page'),
spellCheck: z.boolean().default(false),
fullWidthLayout: z.boolean().default(false),
displayDocInfo: z.boolean().default(true),
displayBiDirectionalLink: z.boolean().default(true),
@@ -0,0 +1,27 @@
import type {
SpellCheckStateKey,
SpellCheckStateSchema,
} from '@affine/electron/main/shared-state-schema';
import type { GlobalStateService } from '@toeverything/infra';
import { LiveData, Service } from '@toeverything/infra';
const SPELL_CHECK_SETTING_KEY: SpellCheckStateKey = 'spellCheckState';
export class SpellCheckSettingService extends Service {
constructor(private readonly globalStateService: GlobalStateService) {
super();
}
enabled$ = LiveData.from(
this.globalStateService.globalState.watch<
SpellCheckStateSchema | undefined
>(SPELL_CHECK_SETTING_KEY),
{ enabled: false }
);
setEnabled(enabled: boolean) {
this.globalStateService.globalState.set(SPELL_CHECK_SETTING_KEY, {
enabled,
});
}
}