reflow settings restoration and progressive saves

This commit is contained in:
Stewart Allen 2020-11-15 22:12:45 -05:00
commit f2672adcb7
2 changed files with 69 additions and 54 deletions

View file

@ -571,8 +571,10 @@
if (!cp.hasOwnProperty(k)) continue;
np[k] = cp[k];
}
s.cproc[API.mode.get()] = name;
s.cproc[mode] = name;
s.devproc[s.device.deviceName] = name;
API.conf.save();
API.conf.update();
API.event.settings();
}
});
@ -1933,27 +1935,6 @@
}
});
let current = settings(),
control = current.controller;
platform.deselect();
CATALOG.addFileListener(updateCatalog);
SPACE.view.setZoom(control.reverseZoom, control.zoomSpeed);
SPACE.platform.setZOff(0.2);
// restore UI state from settings
UI.showOrigin.checked = control.showOrigin;
UI.showRulers.checked = control.showRulers;
UI.showSpeeds.checked = control.showSpeeds;
UI.freeLayout.checked = control.freeLayout;
UI.autoLayout.checked = control.autoLayout;
UI.alignTop.checked = control.alignTop;
UI.reverseZoom.checked = control.reverseZoom;
UI.decimate.checked = control.decimate;
lineTypeSave();
detailSave();
updateFPS();
// load script extensions
if (SETUP.s) SETUP.s.forEach(function(lib) {
let scr = DOC.createElement('script');
@ -1991,32 +1972,62 @@
console.log({octoprint:ohost});
}
// optional set-and-lock mode (hides mode menu)
let SETMODE = SETUP.mode ? SETUP.mode[0] : null;
// bind this to UI so main can call it on settings import
UI.sync = function() {
const current = settings();
const control = current.controller;
const process = settings.process;
// optional set-and-lock device (hides device menu)
let DEVNAME = SETUP.dev ? SETUP.dev[0] : null;
platform.deselect();
CATALOG.addFileListener(updateCatalog);
SPACE.view.setZoom(control.reverseZoom, control.zoomSpeed);
SPACE.platform.setZOff(0.2);
// setup default mode and enable mode locking, if set
API.mode.set(SETMODE || STARTMODE || current.mode, SETMODE);
// restore UI state from settings
UI.showOrigin.checked = control.showOrigin;
UI.showRulers.checked = control.showRulers;
UI.showSpeeds.checked = control.showSpeeds;
UI.freeLayout.checked = control.freeLayout;
UI.autoLayout.checked = control.autoLayout;
UI.alignTop.checked = control.alignTop;
UI.reverseZoom.checked = control.reverseZoom;
UI.decimate.checked = control.decimate;
lineTypeSave();
detailSave();
updateFPS();
// update everything dependent on the platform size
platform.update_size();
// optional set-and-lock mode (hides mode menu)
let SETMODE = SETUP.mode ? SETUP.mode[0] : null;
// restore expert setting preference
API.mode.set_expert(control.expert);
// optional set-and-lock device (hides device menu)
let DEVNAME = SETUP.dev ? SETUP.dev[0] : null;
// setup tab visibility watcher
// DOC.addEventListener('visibilitychange', function() { document.title = document.hidden });
// setup default mode and enable mode locking, if set
API.mode.set(SETMODE || STARTMODE || current.mode, SETMODE);
// fill device list
updateDeviceList();
// restore expert setting preference
API.mode.set_expert(control.expert);
// ensure settings has gcode
selectDevice(DEVNAME || API.device.get(), DEVNAME);
// fill device list
updateDeviceList();
// ensure field data propagation
API.conf.update();
// ensure settings has gcode
selectDevice(DEVNAME || API.device.get(), DEVNAME);
// update ui fields from settings
API.view.update_fields();
// default to ARRANGE view mode
API.view.set(VIEWS.ARRANGE);
// add ability to override
API.show.controls(API.feature.controls);
// update everything dependent on the platform size
platform.update_size();
};
UI.sync();
// load settings provided in url hash
loadSettingsFromServer();
@ -2029,12 +2040,6 @@
API.event.alerts(true);
};
// default to ARRANGE view mode
API.view.set(VIEWS.ARRANGE);
// add ability to override
API.show.controls(API.feature.controls);
// enable modal hiding
$('mod-x').onclick = API.modal.hide;

View file

@ -32,7 +32,6 @@
VIEWS = CONF.VIEWS,
clone = Object.clone,
settings = clone(CONF.template),
// settingsDefault = clone(settings),
// ---------------
Widget = kiri.Widget,
newWidget = kiri.newWidget,
@ -1465,16 +1464,17 @@
updateSettingsFromFields(device.extruders[device.internal]);
}
API.conf.save();
// platform.update_stock();
$('mode-device').innerText = settings.device.deviceName;
$('mode-profile').innerText = settings.process.processName;
}
function saveSettings() {
let view = SPACE.view.save();
const view = SPACE.view.save();
if (view.left || view.up) {
settings.controller.view = view;
}
const mode = settings.mode, name = settings.process.processName;
settings.sproc[mode][name] = settings.process;
settings.device.bedRound = UI.deviceRound.checked;
settings.device.originCenter = UI.deviceOrigin.checked;
SDB.setItem('ws-settings', JSON.stringify(settings));
@ -1491,6 +1491,7 @@
return;
}
}
if (LOCAL) console.log('import',data);
let isSettings = (data.settings && data.version && data.time);
let isDevice = (data.device && data.version && data.time);
if (!isSettings && !isDevice) {
@ -1501,8 +1502,12 @@
function doit() {
if (isSettings) {
settings = CONF.normalize(data.settings);
API.conf.save();
API.space.reload();
SDB.setItem('ws-settings', JSON.stringify(settings));
if (LOCAL) console.log('settings',Object.clone(settings));
restoreSettings();
restoreWorkspace(() => {
UI.sync();
}, true);
}
if (isDevice) {
if (settings.devices[data.device]) {
@ -1657,7 +1662,12 @@
}
SPACE.scene.freeze(fz);
if (skip_widget_load) return;
if (skip_widget_load) {
if (ondone) {
ondone();
}
return;
}
// remove any widgets from platform
forAllWidgets(function(widget) {