Merge pull request #3025 from rigrig/switchclock

switchclock: new app: Clock Switcher
pull/3031/head
Gordon Williams 2023-09-25 10:45:45 +01:00 committed by GitHub
commit 0c432e80e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 52 additions and 0 deletions

View File

@ -0,0 +1,14 @@
# Clock Switcher
This switches the default clock.
The idea is that you can use this app in combination with e.g. the
[Pattern Launcher](?q=ptlaunch) as a quick toggle, instead of navigating through
the settings menu.
## Usage
Load the app to switch to your next installed clock.
## Creator
Richard de Boer (rigrig)

23
apps/clockswitch/app.js Normal file
View File

@ -0,0 +1,23 @@
const storage = require('Storage');
const clocks = storage.list(/\.info$/)
.map(app => {
const a=storage.readJSON(app, 1);
return (a && a.type == "clock") ? a : undefined;
})
.filter(app => app) // filter out any undefined apps
.sort((a, b) => a.sortorder - b.sortorder)
.map(app => app.src);
if (clocks.length<1) {
E.showAlert(/*LANG*/"No clocks found!", "Clock Switcher")
.then(load);
} else if (clocks.length<2) {
E.showAlert(/*LANG*/"Nothing to do:\nOnly one clock installed!", "Clock Switcher")
.then(load);
} else {
let settings = storage.readJSON('setting.json',true)||{clock:null};
const old = clocks.indexOf(settings.clock),
next = (old+1)%clocks.length;
settings.clock = clocks[next];
storage.writeJSON('setting.json', settings);
setTimeout(load, 100); // storage.writeJSON needs some time to complete
}

1
apps/clockswitch/icon.js Normal file
View File

@ -0,0 +1 @@
require("heatshrink").decompress(atob("mEwxH+AClhCyoAYsIwuF4IwtF4Qxqw2GF4mG1YsqAAeF1eyAAIteFhAvHGLeGwouLR4IuEGDJcGwooBAweH6/X6wwGGKtbKownB640C1gGCAAQwZLgotDF4WG6wuFMZAuVw2yEgqLCABIuD1eGF6eGExYwLw4bCF1BuCDgWFdaGFRgwAJlb0HJogvPdQoAKq0AlYJG1YwDRr+sgEAL4wABwxgNF4ZeSqwLIMAYvNwpebAAOFSBgMCw7sQLxSQORwZLKLw4OLSBlbBgWyLznX2RfPLqBeM6/WcQYvZldbrYvN64jDF7rRNF7qPDGBqPLd6YxDGBTvQPpowQ1YvLGAeHF54wDlYMIwwvPwovQGAIuJ6+FdxSQF1YwRABKONF4mGF7aONAANbMDpeDRxRgFsOyFy+yP4gvLMAiRX6yNDwouMGDYuELxyRGwySS2QuUMAr0SdQguSGA+G1gtMLgguUGAQxFwuH1aWE2QsBwoQEFyzEHAB+FFzAwCMQoALFrRiRwwtefI5mCQwIslAH4A/AFw"))

BIN
apps/clockswitch/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

@ -0,0 +1,14 @@
{ "id": "clockswitch",
"name": "Clock Switcher",
"shortName":"Switch Clock",
"version":"0.01",
"description": "Switch to the next installed clock",
"icon": "icon.png",
"tags": "tool",
"supports": ["BANGLEJS","BANGLEJS2"],
"readme": "README.md",
"storage": [
{"name":"clockswitch.app.js","url":"app.js"},
{"name":"clockswitch.img","url":"icon.js","evaluate":true}
]
}