()
| 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 { |
no test coverage detected