feat(core): move blocksuite flags to experimental features (#6113)

This commit is contained in:
Peng Xiao
2024-03-14 05:24:47 +00:00
parent dd9a253772
commit d2bad68b74
6 changed files with 84 additions and 33 deletions

View File

@@ -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({