MCPcopy Create free account
hub / github.com/DTStack/molecule / SettingsService

Class SettingsService

src/services/settingsService.ts:90–189  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

88
89@singleton()
90export class SettingsService extends GlobalEvent implements ISettingsService {
91 protected settings: ISettings;
92 private readonly editorService: IEditorService;
93 private readonly colorThemeService: IColorThemeService;
94 private readonly localeService: ILocaleService;
95 private readonly builtinService: IBuiltinService;
96
97 constructor() {
98 super();
99 this.editorService = container.resolve(EditorService);
100 this.localeService = container.resolve(LocaleService);
101 this.colorThemeService = container.resolve(ColorThemeService);
102 this.builtinService = container.resolve(BuiltinService);
103 this.settings = this.getBuiltInSettings();
104 }
105
106 private getBuiltInSettings(): ISettings {
107 const editorOptions = this.editorService.getState().editorOptions;
108 const theme = this.colorThemeService.getColorTheme();
109 const locale = this.localeService.getCurrentLocale();
110 return new SettingsModel(theme.id, editorOptions!, locale?.id);
111 }
112
113 public getDefaultSettingsTab(): BuiltInSettingsTabType {
114 const { BuiltInSettingsTab } = this.builtinService.getModules();
115 return Object.assign({}, BuiltInSettingsTab);
116 }
117
118 public onChangeSettings(
119 callback: (tab: IEditorTab<BuiltInSettingsTabType>) => void
120 ): void {
121 this.subscribe(SettingsEvent.OnChange, callback);
122 }
123
124 public update(settings: ISettings): void {
125 this.applySettings(settings);
126 const oldSettings = cloneDeep(this.settings);
127 this.settings = mergeObjects(oldSettings, settings);
128 }
129
130 public append(settings: ISettings): void {
131 this.update(settings);
132 }
133
134 public getSettings(): ISettings {
135 const builtInSettings = this.getBuiltInSettings();
136 return Object.assign({}, this.settings, builtInSettings);
137 }
138
139 public applySettings(nextSettings: ISettings) {
140 const oldSettings = this.settings;
141 const { colorTheme, locale, editor }: ISettings = nextSettings;
142 if (colorTheme && colorTheme !== oldSettings.colorTheme) {
143 this.colorThemeService.setTheme(colorTheme);
144 }
145 if (locale && locale !== oldSettings.locale) {
146 this.localeService.setCurrentLocale(locale);
147 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected