MCPcopy Create free account
hub / github.com/Acode-Foundation/Acode / init

Method init

src/lib/settings.js:224–273  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

222 }
223
224 async init() {
225 if (this.#initialized) return;
226 this.settingsFile = Url.join(DATA_STORAGE, "settings.json");
227
228 this.#defaultSettings.appTheme = "system";
229 this.#defaultSettings.editorTheme = getSystemEditorTheme(
230 isDeviceDarkTheme(),
231 );
232
233 this.#initialized = true;
234
235 const fs = fsOperation(this.settingsFile);
236
237 if (!(await fs.exists())) {
238 await this.#save();
239 this.value = structuredClone(this.#defaultSettings);
240 this.#oldSettings = structuredClone(this.#defaultSettings);
241 this.value.lang = navigator.language || "en-us";
242 return;
243 }
244
245 const settings = helpers.parseJSON(await fs.readFile("utf8"));
246 if (settings) {
247 // make sure that all the settings are present
248 Object.keys(this.#defaultSettings).forEach((setting) => {
249 const value = settings[setting];
250 if (
251 value === undefined ||
252 typeof value !== typeof this.#defaultSettings[setting]
253 ) {
254 settings[setting] = this.#defaultSettings[setting];
255 }
256 });
257
258 this.value = structuredClone(settings);
259 this.#oldSettings = structuredClone(settings);
260 try {
261 themes.update(ThemeBuilder.fromJSON(this.value.customTheme));
262 } catch (error) {
263 themes.update(new ThemeBuilder("Custom").toJSON());
264 }
265
266 // Ensure pluginsDisabled exists
267 if (!this.value.pluginsDisabled) this.value.pluginsDisabled = {};
268
269 return;
270 }
271
272 await this.reset();
273 }
274
275 async #save() {
276 try {

Callers 3

onDeviceReadyFunction · 0.45
main.jsFile · 0.45
initFunction · 0.45

Calls 10

#saveMethod · 0.95
resetMethod · 0.95
getSystemEditorThemeFunction · 0.90
isDeviceDarkThemeFunction · 0.90
fsOperationFunction · 0.85
existsMethod · 0.65
readFileMethod · 0.45
updateMethod · 0.45
fromJSONMethod · 0.45
toJSONMethod · 0.45

Tested by

no test coverage detected