add discrete device export/import
This commit is contained in:
parent
e8dda00da3
commit
50ea6cb11a
5 changed files with 62 additions and 6 deletions
|
|
@ -466,6 +466,21 @@
|
|||
}).request("/data/"+ settings().id + "/" + settings().ver, set);
|
||||
}
|
||||
|
||||
function deviceExport(exp, name) {
|
||||
name = (name || "kiridev")
|
||||
.toLowerCase()
|
||||
.replace(/ /g,'_')
|
||||
.replace(/\./g,'_');
|
||||
UC.prompt("Export Device Filename", name).then(name => {
|
||||
if (name) {
|
||||
let blob = new Blob([exp], {type: "octet/stream"}),
|
||||
url = WIN.URL.createObjectURL(blob);
|
||||
$('mod-any').innerHTML = `<a id="sexport" href="${url}" download="${name}.b64">x</a>`;
|
||||
$('sexport').click();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function profileExport() {
|
||||
UC.prompt("Export Profile Filename", "kiriconf").then(name => {
|
||||
if (name) {
|
||||
|
|
@ -640,6 +655,7 @@
|
|||
UI.deviceSave.disabled = !local;
|
||||
UI.deviceDelete.disabled = !local;
|
||||
UI.deviceAdd.disabled = dev.noclone;
|
||||
UI.deviceExport.disabled = !local;
|
||||
|
||||
API.view.update_fields();
|
||||
platform.update_size();
|
||||
|
|
@ -714,6 +730,15 @@
|
|||
removeLocalDevice(getSelectedDevice());
|
||||
showDevices();
|
||||
};
|
||||
UI.deviceExport.onclick = function() {
|
||||
let exp = btoa(JSON.stringify({
|
||||
version: KIRI.version,
|
||||
device: selected,
|
||||
code: devs[selected],
|
||||
time: Date.now()
|
||||
}));
|
||||
deviceExport(exp, selected);
|
||||
};
|
||||
|
||||
UI.deviceAll.onclick = function() {
|
||||
API.show.favorites(false);
|
||||
|
|
@ -1195,6 +1220,7 @@
|
|||
deviceList: $('device-list'),
|
||||
deviceAdd: $('device-add'),
|
||||
deviceDelete: $('device-del'),
|
||||
deviceExport: $('device-exp'),
|
||||
deviceSave: $('device-save'),
|
||||
deviceFavorites: $('device-favorites'),
|
||||
deviceAll: $('device-all'),
|
||||
|
|
|
|||
|
|
@ -1533,18 +1533,39 @@
|
|||
return;
|
||||
}
|
||||
}
|
||||
if (!(data.settings && data.version && data.time)) {
|
||||
UC.alert('invalid settings format');
|
||||
let isSettings = (data.settings && data.version && data.time);
|
||||
let isDevice = (data.device && data.version && data.time);
|
||||
if (!isSettings && !isDevice) {
|
||||
UC.alert('invalid settings or device format');
|
||||
console.log('data',data);
|
||||
return;
|
||||
}
|
||||
function doit() {
|
||||
settings = CONF.normalize(data.settings);
|
||||
API.conf.save();
|
||||
API.space.reload();
|
||||
if (isSettings) {
|
||||
settings = CONF.normalize(data.settings);
|
||||
API.conf.save();
|
||||
API.space.reload();
|
||||
}
|
||||
if (isDevice) {
|
||||
if (settings.devices[data.device]) {
|
||||
UC.confirm(`Replace device ${data.device}?`).then(yes => {
|
||||
if (yes) {
|
||||
settings.devices[data.device] = data.code;
|
||||
API.show.devices();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
settings.devices[data.device] = data.code;
|
||||
API.show.devices();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ask) {
|
||||
UC.confirm(`Import settings made in Kiri:Moto version ${data.version} on<br>${new Date(data.time)}?`).then((yes) => {
|
||||
let prompt = `Import settings made in Kiri:Moto version ${data.version} on<br>${new Date(data.time)}?`;
|
||||
if (isDevice) {
|
||||
prompt = `Import device "${data.device}"?`;
|
||||
}
|
||||
UC.confirm(prompt).then((yes) => {
|
||||
if (yes) doit();
|
||||
});
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Reference in a new issue