mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-11 20:08:37 +00:00
feat(core): move enable ai to feature flag (#8195)
This commit is contained in:
@@ -5,6 +5,14 @@ const isDesktopEnvironment = environment.isElectron;
|
||||
const isCanaryBuild = runtimeConfig.appBuildType === 'canary';
|
||||
|
||||
export const AFFINE_FLAGS = {
|
||||
enable_ai: {
|
||||
category: 'affine',
|
||||
displayName: 'Enable AI',
|
||||
description: 'Enable or disable ALL AI features.',
|
||||
hide: true,
|
||||
configurable: true,
|
||||
defaultState: true,
|
||||
},
|
||||
enable_database_attachment_note: {
|
||||
category: 'blocksuite',
|
||||
bsFlag: 'enable_database_attachment_note',
|
||||
|
||||
@@ -29,12 +29,17 @@ export class Flags extends Entity {
|
||||
const configurable = flag.configurable ?? true;
|
||||
const defaultState =
|
||||
'defaultState' in flag ? flag.defaultState : undefined;
|
||||
const getValue = () => {
|
||||
return configurable
|
||||
? (this.globalState.get<boolean>(FLAG_PREFIX + flagKey) ??
|
||||
defaultState)
|
||||
: defaultState;
|
||||
};
|
||||
const item = {
|
||||
...flag,
|
||||
value: configurable
|
||||
? (this.globalState.get<boolean>(FLAG_PREFIX + flagKey) ??
|
||||
defaultState)
|
||||
: defaultState,
|
||||
get value() {
|
||||
return getValue();
|
||||
},
|
||||
set: (value: boolean) => {
|
||||
if (!configurable) {
|
||||
return;
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
import { distinctUntilChanged, skip } from 'rxjs';
|
||||
|
||||
import { OnEvent, Service } from '../../../framework';
|
||||
import { ApplicationStarted } from '../../lifecycle';
|
||||
import type { Workspace } from '../../workspace';
|
||||
import { WorkspaceInitialized } from '../../workspace/events';
|
||||
import { AFFINE_FLAGS } from '../constant';
|
||||
import { Flags, type FlagsExt } from '../entities/flags';
|
||||
|
||||
@OnEvent(WorkspaceInitialized, e => e.setupBlocksuiteEditorFlags)
|
||||
@OnEvent(ApplicationStarted, e => e.setupRestartListener)
|
||||
export class FeatureFlagService extends Service {
|
||||
flags = this.framework.createEntity(Flags) as FlagsExt;
|
||||
|
||||
@@ -18,4 +22,13 @@ export class FeatureFlagService extends Service {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setupRestartListener() {
|
||||
this.flags.enable_ai.$.pipe(distinctUntilChanged(), skip(1)).subscribe(
|
||||
() => {
|
||||
// when enable_ai flag changes, reload the page.
|
||||
window.location.reload();
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,10 @@ export type FlagInfo = {
|
||||
description?: string;
|
||||
configurable?: boolean;
|
||||
defaultState?: boolean; // default to open and not controlled by user
|
||||
/**
|
||||
* hide in the feature flag settings, but still can be controlled by the code
|
||||
*/
|
||||
hide?: boolean;
|
||||
feedbackType?: FeedbackType;
|
||||
feedbackLink?: string;
|
||||
} & (
|
||||
|
||||
Reference in New Issue
Block a user