save pak settings

This commit is contained in:
Devaev Maxim 2021-07-14 16:26:56 +03:00
parent 0f3f85ac58
commit c903f60f85
2 changed files with 23 additions and 7 deletions

View File

@ -74,6 +74,15 @@ export function Hid(__getResolution) {
window.addEventListener("pagehide", __releaseAll); window.addEventListener("pagehide", __releaseAll);
window.addEventListener("blur", __releaseAll); window.addEventListener("blur", __releaseAll);
$("hid-pak-ask-switch").checked = parseInt(tools.storage.get("hid.pak.ask", "1"));
tools.setOnClick($("hid-pak-ask-switch"), function() {
tools.storage.set("hid.pak.ask", ($("hid-pak-ask-switch").checked ? 1 : 0));
}, false);
$("hid-pak-keymap-selector").addEventListener("change", function() {
tools.storage.set("hid.pak.keymap", $("hid-pak-keymap-selector").value);
});
tools.setOnClick($("hid-pak-button"), __clickPasteAsKeysButton); tools.setOnClick($("hid-pak-button"), __clickPasteAsKeysButton);
tools.setOnClick($("hid-connect-switch"), __clickConnectSwitch); tools.setOnClick($("hid-connect-switch"), __clickConnectSwitch);
tools.setOnClick($("hid-reset-button"), __clickResetButton); tools.setOnClick($("hid-reset-button"), __clickResetButton);
@ -163,9 +172,10 @@ export function Hid(__getResolution) {
}; };
self.setKeymaps = function(state) { self.setKeymaps = function(state) {
let selected = tools.storage.get("hid.pak.keymap", state.keymaps["default"]);
let html = ""; let html = "";
for (let variant of state.keymaps.available) { for (let variant of state.keymaps.available) {
html += `<option value=${variant} ${variant === state.keymaps.default ? "selected" : ""}>${variant}</option>`; html += `<option value=${variant} ${variant === selected ? "selected" : ""}>${variant}</option>`;
} }
$("hid-pak-keymap-selector").innerHTML = html; $("hid-pak-keymap-selector").innerHTML = html;
}; };

View File

@ -88,21 +88,27 @@ export var tools = new function() {
return (matches ? decodeURIComponent(matches[1]) : ""); return (matches ? decodeURIComponent(matches[1]) : "");
}; };
this.setOnClick = function(el, callback) { this.setOnClick = function(el, callback, prevent_default=true) {
el.onclick = el.ontouchend = function(event) { el.onclick = el.ontouchend = function(event) {
if (prevent_default) {
event.preventDefault(); event.preventDefault();
}
callback(); callback();
}; };
}; };
this.setOnDown = function(el, callback) { this.setOnDown = function(el, callback, prevent_default=true) {
el.onmousedown = el.ontouchstart = function(event) { el.onmousedown = el.ontouchstart = function(event) {
if (prevent_default) {
event.preventDefault(); event.preventDefault();
}
callback(); callback();
}; };
}; };
this.setOnUp = function(el, callback) { this.setOnUp = function(el, callback, prevent_default=true) {
el.onmouseup = el.ontouchend = function(event) { el.onmouseup = el.ontouchend = function(event) {
if (prevent_default) {
event.preventDefault(); event.preventDefault();
}
callback(); callback();
}; };
}; };