mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-24 09:52:49 +08:00
feat(core): move blocksuite flags to experimental features (#6113)
This commit is contained in:
@@ -1,10 +1,16 @@
|
||||
import { DebugLogger } from '@affine/debug';
|
||||
import { setupGlobal } from '@affine/env/global';
|
||||
import type { DocCollection } from '@blocksuite/store';
|
||||
import { atom } from 'jotai';
|
||||
import { atomWithStorage } from 'jotai/utils';
|
||||
import { atomEffect } from 'jotai-effect';
|
||||
|
||||
import { getCurrentStore } from './root-store';
|
||||
|
||||
setupGlobal();
|
||||
|
||||
const logger = new DebugLogger('affine:settings');
|
||||
|
||||
export type DateFormats =
|
||||
| 'MM/dd/YYYY'
|
||||
| 'dd/MM/YYYY'
|
||||
@@ -26,6 +32,7 @@ export type AppSetting = {
|
||||
autoCheckUpdate: boolean;
|
||||
autoDownloadUpdate: boolean;
|
||||
enableMultiView: boolean;
|
||||
editorFlags: Partial<Omit<BlockSuiteFlags, 'readonly'>>;
|
||||
};
|
||||
export const windowFrameStyleOptions: AppSetting['windowFrameStyle'][] = [
|
||||
'frameless',
|
||||
@@ -65,15 +72,35 @@ const appSettingBaseAtom = atomWithStorage<AppSetting>('affine-settings', {
|
||||
autoCheckUpdate: true,
|
||||
autoDownloadUpdate: true,
|
||||
enableMultiView: false,
|
||||
editorFlags: {},
|
||||
});
|
||||
|
||||
export function setupEditorFlags(docCollection: DocCollection) {
|
||||
const store = getCurrentStore();
|
||||
const syncEditorFlags = () => {
|
||||
try {
|
||||
const editorFlags = getCurrentStore().get(appSettingBaseAtom).editorFlags;
|
||||
Object.entries(editorFlags).forEach(([key, value]) => {
|
||||
docCollection.awarenessStore.setFlag(
|
||||
key as keyof BlockSuiteFlags,
|
||||
value
|
||||
);
|
||||
});
|
||||
} catch (err) {
|
||||
logger.error('syncEditorFlags', err);
|
||||
}
|
||||
};
|
||||
store.sub(appSettingBaseAtom, syncEditorFlags);
|
||||
syncEditorFlags();
|
||||
}
|
||||
|
||||
type SetStateAction<Value> = Value | ((prev: Value) => Value);
|
||||
|
||||
const appSettingEffect = atomEffect(get => {
|
||||
const settings = get(appSettingBaseAtom);
|
||||
// some values in settings should be synced into electron side
|
||||
if (environment.isDesktop) {
|
||||
console.log('set config', settings);
|
||||
logger.debug('sync settings to electron', settings);
|
||||
// this api type in @affine/electron-api, but it is circular dependency this package, use any here
|
||||
(window as any).apis?.updater
|
||||
.setConfig({
|
||||
|
||||
Reference in New Issue
Block a user