()
| 276 | }) |
| 277 | |
| 278 | function tryLoadOldSettings() { |
| 279 | console.log("Loading old user settings") |
| 280 | // load v1 auto-save.js settings |
| 281 | var old_map = { |
| 282 | guidance_scale_slider: "guidance_scale", |
| 283 | prompt_strength_slider: "prompt_strength", |
| 284 | } |
| 285 | var settings_key_v1 = "user_settings" |
| 286 | var saved_settings_text = localStorage.getItem(settings_key_v1) |
| 287 | if (saved_settings_text) { |
| 288 | var saved_settings = JSON.parse(saved_settings_text) |
| 289 | Object.keys(saved_settings.should_save).forEach((key) => { |
| 290 | key = key in old_map ? old_map[key] : key |
| 291 | if (!(key in SETTINGS)) return |
| 292 | SETTINGS[key].ignore = !saved_settings.should_save[key] |
| 293 | }) |
| 294 | Object.keys(saved_settings.values).forEach((key) => { |
| 295 | key = key in old_map ? old_map[key] : key |
| 296 | if (!(key in SETTINGS)) return |
| 297 | var setting = SETTINGS[key] |
| 298 | if (!setting.ignore) { |
| 299 | setting.value = saved_settings.values[key] |
| 300 | setSetting(setting.element, setting.value) |
| 301 | } |
| 302 | }) |
| 303 | localStorage.removeItem(settings_key_v1) |
| 304 | } |
| 305 | |
| 306 | // load old individually stored items |
| 307 | var individual_settings_map = { |
| 308 | // maps old localStorage-key to new SETTINGS-key |
| 309 | soundEnabled: "sound_toggle", |
| 310 | saveToDisk: "save_to_disk", |
| 311 | useCPU: "use_cpu", |
| 312 | diskPath: "diskPath", |
| 313 | useFaceCorrection: "use_face_correction", |
| 314 | useUpscaling: "use_upscale", |
| 315 | showOnlyFilteredImage: "show_only_filtered_image", |
| 316 | streamImageProgress: "stream_image_progress", |
| 317 | outputFormat: "output_format", |
| 318 | autoSaveSettings: "auto_save_settings", |
| 319 | } |
| 320 | Object.keys(individual_settings_map).forEach((localStorageKey) => { |
| 321 | var localStorageValue = localStorage.getItem(localStorageKey) |
| 322 | if (localStorageValue !== null) { |
| 323 | let key = individual_settings_map[localStorageKey] |
| 324 | var setting = SETTINGS[key] |
| 325 | if (!setting) { |
| 326 | console.warn(`Attempted to map old setting ${key}, but no setting found`) |
| 327 | return null |
| 328 | } |
| 329 | if ( |
| 330 | setting.element.type == "checkbox" && |
| 331 | (typeof localStorageValue === "string" || localStorageValue instanceof String) |
| 332 | ) { |
| 333 | localStorageValue = localStorageValue == "true" |
| 334 | } |
| 335 | setting.value = localStorageValue |
no test coverage detected