1
0
Fork 0

widlockunlock: setting for location

master
Rob Pilling 2023-02-25 21:56:34 +00:00
parent b19dd38dbb
commit c84d3fa2c0
4 changed files with 75 additions and 2 deletions

View File

@ -8,6 +8,7 @@
"tags": "widget,lock",
"supports": ["BANGLEJS","BANGLEJS2"],
"storage": [
{"name":"widlockunlock.wid.js","url":"widget.js"}
{"name":"widlockunlock.wid.js","url":"widget.js"},
{"name":"widlockunlock.settings.js","url":"settings.js"}
]
}

View File

@ -0,0 +1,29 @@
"use strict";
(function (back) {
var storage = require('Storage');
var filename = 'lockunlock.settings.json';
var settings = Object.assign(storage.readJSON(filename, true) || {}, { location: "tl" });
var save = function () {
return storage.writeJSON(filename, settings);
};
var locations = ["tl", "tr"];
var menu = {
'': { 'title': 'Lock/Unlock' },
'< Back': back,
'Location': {
value: (function () {
var i = locations.indexOf(settings.location);
return i < 0 ? 0 : i;
})(),
min: 0,
max: locations.length - 1,
wrap: true,
format: function (v) { return locations[v]; },
onchange: function (v) {
settings.location = locations[v];
save();
},
},
};
E.showMenu(menu);
});

View File

@ -0,0 +1,39 @@
((back: () => void) => {
type Location = "tl" | "tr";
type Settings = {
location: Location;
};
const storage = require('Storage');
const filename = 'lockunlock.settings.json';
const settings: Settings = Object.assign(
storage.readJSON(filename, true) || {},
{ location: "tl" }
);
const save = () =>
storage.writeJSON(filename, settings);
const locations: Array<Location> = [ "tl", "tr" ];
const menu = {
'': { 'title': 'Lock/Unlock' },
'< Back': back,
'Location': {
value: (() => {
const i = locations.indexOf(settings.location);
return i < 0 ? 0 : i;
})(),
min: 0,
max: locations.length - 1,
wrap: true,
format: (v: number) => locations[v]!,
onchange: (v: number) => {
settings.location = locations[v]!;
save();
},
},
};
E.showMenu(menu);
});

View File

@ -1,5 +1,9 @@
WIDGETS["lockunlock"] = {
area: "tl",
area: (() => {
const settings = require("Storage")
.readJSON("lockunlock.settings.json", true) || {};
return settings.location || "tl";
})(),
sortorder: 10,
width: 14,
draw: w => {