ryzen-controller/js/preset.js
Quentin “Storm1er” Decaunes 81572aa960 See #19 Import Export presets v1.
2019-06-04 12:39:23 +02:00

33 lines
932 B
JavaScript

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 = '';
}