forked from FOSS/BangleApps
commit
bd08b00d13
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"id": "widshipbell",
|
||||
"name": "Ship's bell Widget",
|
||||
"shortName": "Ship's bell",
|
||||
"version": "0.01",
|
||||
"description": "A widget that buzzes according to a nautical bell, one strike at 04:30, two strikes at 05:00, up to eight strikes at 08:00 and so on.",
|
||||
"icon": "widget.png",
|
||||
"type": "widget",
|
||||
"tags": "widget",
|
||||
"supports": ["BANGLEJS","BANGLEJS2"],
|
||||
"storage": [
|
||||
{"name":"widshipbell.wid.js","url":"widget.js"},
|
||||
{"name":"widshipbell.settings.js","url":"settings.js"}
|
||||
],
|
||||
"data": [{"name":"widshipbell.json"}]
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
(function(back) {
|
||||
var FILE = "widshipbell.json";
|
||||
// Load settings
|
||||
var settings = Object.assign({
|
||||
strength: 1,
|
||||
}, require('Storage').readJSON(FILE, true) || {});
|
||||
|
||||
function writeSettings() {
|
||||
require('Storage').writeJSON(FILE, settings);
|
||||
}
|
||||
|
||||
// Show the menu
|
||||
E.showMenu({
|
||||
"" : { "title" : "Ship's bell" },
|
||||
"< Back" : () => back(),
|
||||
'Strength': {
|
||||
value: settings.strength,
|
||||
min: 0, max: 2,
|
||||
format: v => ["Off", "Weak", "Strong"][v],
|
||||
onchange: v => {
|
||||
settings.strength = v;
|
||||
writeSettings();
|
||||
}
|
||||
},
|
||||
});
|
||||
})
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
(() => {
|
||||
const strength = Object.assign({
|
||||
strength: 1,
|
||||
}, require('Storage').readJSON("widshipbell.json", true) || {}).strength;
|
||||
|
||||
function replaceAll(target, search, replacement) {
|
||||
return target.split(search).join(replacement);
|
||||
}
|
||||
|
||||
function check() {
|
||||
const now = new Date();
|
||||
const currentMinute = now.getMinutes();
|
||||
const currentSecond = now.getSeconds();
|
||||
const etaMinute = 30-(currentMinute % 30);
|
||||
|
||||
if (etaMinute === 30 && currentSecond === 0) {
|
||||
const strikeHour = now.getHours() % 4;
|
||||
// buzz now
|
||||
let pattern='';
|
||||
if (strikeHour === 0 && currentMinute == 0) {
|
||||
pattern = '.. .. .. ..';
|
||||
} else if (strikeHour === 0 && currentMinute === 30) {
|
||||
pattern = '.';
|
||||
} else if (strikeHour === 1 && currentMinute === 0) {
|
||||
pattern = '..';
|
||||
} else if (strikeHour === 1 && currentMinute === 30) {
|
||||
pattern = '.. .';
|
||||
} else if (strikeHour === 2 && currentMinute === 0) {
|
||||
pattern = '.. ..';
|
||||
} else if (strikeHour === 2 && currentMinute === 30) {
|
||||
pattern = '.. .. .';
|
||||
} else if (strikeHour === 3 && currentMinute === 0) {
|
||||
pattern = '.. .. ..';
|
||||
} else if (strikeHour === 3 && currentMinute === 30) {
|
||||
pattern = '.. .. .. .';
|
||||
}
|
||||
pattern = replaceAll(pattern, ' ', ' '); // 4x pause
|
||||
pattern = replaceAll(pattern, '.', '. '); // pause between bells
|
||||
if (strength === 2) { // strong selected
|
||||
pattern = replaceAll(pattern, '.', ':');
|
||||
}
|
||||
require("buzz").pattern(pattern);
|
||||
}
|
||||
|
||||
const etaSecond = etaMinute*60-currentSecond;
|
||||
setTimeout(check, etaSecond*1000);
|
||||
}
|
||||
|
||||
if (strength !== 0) {
|
||||
check();
|
||||
}
|
||||
})();
|
Binary file not shown.
After Width: | Height: | Size: 1.3 KiB |
Loading…
Reference in New Issue