From 4801edd1b4f2cd8e8e202d9ae4bf805c3bd47e7e Mon Sep 17 00:00:00 2001 From: Miodec Date: Mon, 17 May 2021 16:03:12 +0100 Subject: [PATCH] added import export settings to the command line --- src/js/commandline-lists.js | 27 +++++++++++++++++++++++++++ src/js/config.js | 6 +++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/js/commandline-lists.js b/src/js/commandline-lists.js index a07256def..a82a4ded3 100644 --- a/src/js/commandline-lists.js +++ b/src/js/commandline-lists.js @@ -16,6 +16,7 @@ import * as TagController from "./tag-controller"; import * as PresetController from "./preset-controller"; import * as Commandline from "./commandline"; import * as CustomText from "./custom-text"; +import * as Settings from "./settings"; export let current = []; @@ -2009,6 +2010,32 @@ export let defaultCommands = { Commandline.show(); }, }, + { + id: "importSettingsJSON", + display: "Import settings JSON", + input: true, + exec: (input) => { + try { + UpdateConfig.apply(JSON.parse(input)); + UpdateConfig.saveToLocalStorage(); + Settings.update(); + Notifications.add("Done",1); + } catch (e) { + Notifications.add( + "An error occured while importing settings: " + e, + -1 + ); + } + }, + }, + { + id: "exportSettingsJSON", + display: "Export settings JSON", + input: true, + defaultValue:"", + exec: (input) => { + }, + }, ], }; diff --git a/src/js/config.js b/src/js/config.js index 3b8e76247..0fc1284f2 100644 --- a/src/js/config.js +++ b/src/js/config.js @@ -144,7 +144,11 @@ export async function saveToLocalStorage(noDbCheck = false) { // }); let save = config; delete save.resultFilters; - window.localStorage.setItem("config", JSON.stringify(save)); + let stringified = JSON.stringify(save); + window.localStorage.setItem("config", stringified); + CommandlineLists.defaultCommands.list.filter( + (command) => command.id == "exportSettingsJSON" + )[0].defaultValue = stringified; // restartCount = 0; if (!noDbCheck) await DB.saveConfig(save); }