minor partial state fixes

This commit is contained in:
Maxim Devaev 2024-11-04 18:06:16 +02:00
parent d93639ba8d
commit 7ef2e16b51
7 changed files with 85 additions and 75 deletions

View File

@ -394,7 +394,7 @@
<td>Connect main USB to Server:</td>
<td align="right">
<div class="switch-box">
<input class="__gpio-switch-__v3_usb_breaker__ gpio-switch" disabled type="checkbox" id="__gpio-switch-__v3_usb_breaker__" data-channel="__v3_usb_breaker__" data-confirm-off="Turning off this switch will disconnect the main USB&lt;br&gt;from the server. Are you sure you want to continue?">
<input class="__gpio-switch-__v3_usb_breaker__ gpio-switch" disabled type="checkbox" id="__gpio-switch-__v3_usb_breaker__" data-channel="__v3_usb_breaker__" data-confirm-off="Turning off this switch will disconnect the main USB from the server. Are you sure you want to continue?">
<label for="__gpio-switch-__v3_usb_breaker__"><span class="switch-inner"></span><span class="switch"></span></label>
</div>
</td>

View File

@ -122,7 +122,7 @@ li(id="system-dropdown" class="right")
+menu_switch_notable("hid-mute-switch", "Mute HID input events", true, false)
tr(id="v3-usb-breaker" class="feature-disabled")
+menu_switch_notable_gpio("__v3_usb_breaker__", "Connect main USB to Server",
"Turning off this switch will disconnect the main USB<br>from the server. Are you sure you want to continue?")
"Turning off this switch will disconnect the main USB from the server. Are you sure you want to continue?")
tr(id="v4-locator" class="feature-disabled")
+menu_switch_notable_gpio("__v4_locator__", "Enable locator LED")
tr

View File

@ -53,30 +53,33 @@ export function Atx(__recorder) {
__state = {"leds": {}};
}
if (state.enabled !== undefined) {
tools.feature.setEnabled($("atx-dropdown"), state.enabled);
__state.enabled = state.enabled;
tools.feature.setEnabled($("atx-dropdown"), __state.enabled);
}
if (__state.enabled !== undefined) {
if (state.busy !== undefined) {
__updateButtons(!state.busy);
__state.busy = state.busy;
__updateButtons(!__state.busy);
}
if (state.leds !== undefined) {
__state.leds = state.leds;
}
if (state.busy !== undefined || state.leds !== undefined) {
let busy = __state.busy;
let leds = __state.leds;
$("atx-power-led").className = (busy ? "led-yellow" : (leds.power ? "led-green" : "led-gray"));
$("atx-hdd-led").className = (leds.hdd ? "led-red" : "led-gray");
__updateLeds(__state.leds.power, __state.leds.hdd, __state.busy);
}
}
} else {
__state = null;
__updateLeds(false, false, false);
__updateButtons(false);
}
};
var __updateLeds = function(power, hdd, busy) {
$("atx-power-led").className = (busy ? "led-yellow" : (power ? "led-green" : "led-gray"));
$("atx-hdd-led").className = (hdd ? "led-red" : "led-gray");
};
var __updateButtons = function(enabled) {
for (let id of ["atx-power-button", "atx-power-button-long", "atx-reset-button"]) {
tools.el.setEnabled($(id), enabled);

View File

@ -38,14 +38,20 @@ export function Gpio(__recorder) {
self.setState = function(state) {
if (state) {
if (state.model) {
__applyModel(state.model);
if (state.model !== undefined) {
__has_model = true;
__updateModel(state.model);
}
if (__has_model && state.state !== undefined) {
if (state.state.inputs !== undefined) {
__updateInputs(state.state.inputs);
}
if (state.state.outputs !== undefined) {
__updateOutputs(state.state.outputs);
}
if (__has_model && state.state) {
__applyState(state.state);
}
} else {
__has_model = false;
for (let el of $$("__gpio-led")) {
__setLedState(el, false);
}
@ -54,33 +60,31 @@ export function Gpio(__recorder) {
tools.el.setEnabled(el, false);
}
}
__has_model = false;
}
};
var __applyState = function(state) {
if (state.inputs) {
for (let ch in state.inputs) {
var __updateInputs = function(inputs) {
for (let ch in inputs) {
for (let el of $$(`__gpio-led-${ch}`)) {
__setLedState(el, state.inputs[ch].state);
__setLedState(el, inputs[ch].state);
}
}
}
if (state.outputs) {
for (let ch in state.outputs) {
};
var __updateOutputs = function(outputs) {
for (let ch in outputs) {
for (let type of ["switch", "button"]) {
for (let el of $$(`__gpio-${type}-${ch}`)) {
tools.el.setEnabled(el, state.outputs[ch].online && !state.outputs[ch].busy);
tools.el.setEnabled(el, (outputs[ch].online && !outputs[ch].busy));
}
}
for (let el of $$(`__gpio-switch-${ch}`)) {
el.checked = state.outputs[ch].state;
}
el.checked = outputs[ch].state;
}
}
};
var __applyModel = function(model) {
var __updateModel = function(model) {
tools.feature.setEnabled($("gpio-dropdown"), model.view.table.length);
if (model.view.table.length) {
let title = [];

View File

@ -66,12 +66,11 @@ export function Msd() {
self.setState = function(state) {
if (state) {
if (!__state) {
__state = {};
__state.storage = {};
__state = {"storage": {}};
}
if (state.enabled !== undefined) {
tools.feature.setEnabled($("msd-dropdown"), state.enabled);
__state.enabled = state.enabled;
tools.feature.setEnabled($("msd-dropdown"), __state.enabled);
}
if (__state.enabled !== undefined) {
if (state.online !== undefined) {
@ -80,32 +79,28 @@ export function Msd() {
if (state.busy !== undefined) {
__state.busy = state.busy;
}
if (state.drive !== undefined || (state.storage && state.storage.images !== undefined)) {
let drive = (state.drive !== undefined ? state.drive : __state.drive);
let images = (
state.storage && state.storage.images !== undefined
? state.storage.images
: __state.storage && __state.storage.images !== undefined
? __state.storage.images
: null
);
if (drive && images) {
__updateImageSelector(drive, images);
if (state.drive) { // Null on offline, ignore
__state.drive = state.drive;
}
__state.drive = drive;
__state.storage.images = images;
}
if (state.storage && state.storage.parts !== undefined) {
__updateParts(state.storage.parts);
if (state.storage) { // Null on offline, ignore
if (state.storage.parts !== undefined) {
__state.storage.parts = state.storage.parts;
__updateParts(__state.storage.parts);
}
if (state.storage && state.storage.uploading !== undefined) {
__updateUploading(state.storage.uploading);
if (state.storage.uploading !== undefined) {
__state.storage.uploading = state.storage.uploading;
__updateUploading(__state.storage.uploading);
}
if (state.storage && state.storage.downloading !== undefined) {
if (state.storage.downloading !== undefined) {
__state.storage.downloading = state.storage.downloading;
}
if (state.storage.images !== undefined) {
__state.storage.images = state.storage.images;
}
}
if (state.drive || (state.storage && state.storage.images !== undefined)) {
__updateImageSelector(__state.drive, __state.storage.images);
}
}
} else {
__state = null;
@ -403,12 +398,14 @@ export function Msd() {
let file = tools.input.getFile(el);
if (file) {
$("msd-new-url").value = "";
if (__state && __state.storage && __state.storage.parts) {
let part = __state.storage.parts[$("msd-new-part-selector").value];
if (file.size > part.size) {
if (part && (file.size > part.size)) {
wm.error(`The new image is too big for the Mass Storage partition.<br>Maximum: ${tools.formatSize(part.size)}`);
el.value = "";
}
}
}
__refreshControls();
};

View File

@ -76,20 +76,26 @@ export function Ocr(__getGeometry) {
if (state) {
if (state.enabled !== undefined) {
__enabled = (state.enabled && !tools.browser.is_mobile);
tools.feature.setEnabled($("stream-ocr"), __enabled);
$("stream-ocr-led").className = (__enabled ? "led-gray" : "hidden");
}
if (__enabled && state.langs !== undefined) {
__updateLangs(state.langs);
}
} else {
__enabled = false;
tools.feature.setEnabled($("stream-ocr"), false);
$("stream-ocr-led").className = "hidden";
}
if (__enabled) {
};
var __updateLangs = function(langs) {
let el = $("stream-ocr-lang-selector");
el.options.length = 0;
for (let lang of state.langs.available) {
for (let lang of langs.available) {
tools.selector.addOption(el, lang, lang);
}
el.value = tools.storage.get("stream.ocr.lang", state.langs["default"]);
}
tools.feature.setEnabled($("stream-ocr"), __enabled);
$("stream-ocr-led").className = (__enabled ? "led-gray" : "hidden");
el.value = tools.storage.get("stream.ocr.lang", langs["default"]);
};
var __startSelection = function(event) {

View File

@ -138,17 +138,17 @@ export function Streamer() {
if (!__state) {
__state = {};
}
if (state.features) {
if (state.features !== undefined) {
__state.features = state.features;
__state.limits = state.limits; // Following together with features
}
if (__state.features && state.streamer !== undefined) {
__setControlsEnabled(!!state.streamer);
if (__state.features !== undefined && state.streamer !== undefined) {
__state.streamer = state.streamer;
__setControlsEnabled(!!state.streamer);
}
} else {
__setControlsEnabled(false);
__state = null;
__setControlsEnabled(false);
}
let visible = wm.isWindowVisible($("stream-window"));
__applyState((visible && __state && __state.features) ? state : null);