From 81572aa960cea966f2ca2f6c0d26040f442f4822 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Quentin=20=E2=80=9CStorm1er=E2=80=9D=20Decaunes?= Date: Tue, 4 Jun 2019 09:37:03 +0000 Subject: [PATCH] See #19 Import Export presets v1. --- index.html | 38 +++++++++++++++++++++++++++++++++++++- js/methods.js | 2 +- js/preset.js | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 js/preset.js diff --git a/index.html b/index.html index 453745b..70fb84a 100644 --- a/index.html +++ b/index.html @@ -161,7 +161,17 @@

-
  • +
  • +
    +

    + + +

    +
  • @@ -232,6 +242,32 @@ + + + + + + + diff --git a/js/methods.js b/js/methods.js index 62ecf40..3783a0e 100644 --- a/js/methods.js +++ b/js/methods.js @@ -516,13 +516,13 @@ function updatePresetList() { content += `
  • ${presetName} - ${valueSummary} + ${valueSummary}
  • `; } diff --git a/js/preset.js b/js/preset.js new file mode 100644 index 0000000..ca4bfa5 --- /dev/null +++ b/js/preset.js @@ -0,0 +1,32 @@ +function preset_export() { + const modalTextArea = document.getElementById('modal-export-preset-textarea'); + const settings = require('electron-settings'); + var presets = settings.get('presets'); + + presets = JSON.stringify(presets); + modalTextArea.innerHTML = btoa(presets); +} + +function preset_import() { + const modalTextArea = document.getElementById('modal-import-preset-textarea'); + const settings = require('electron-settings'); + var currentPresets = settings.get('presets'); + var presetsToBeImported = atob(modalTextArea.value); + + try { + presetsToBeImported = JSON.parse(presetsToBeImported); + } catch (e) { + notification('danger', 'Unable to import presets, malformed data.'); + console.error(e); + return; + } + + var updatedPresets = Object.assign( + {}, + currentPresets, + presetsToBeImported + ); + settings.set('presets', updatedPresets); + updatePresetList(); + modalTextArea.innerText = ''; +}