qmsched: add widget

pull/784/head
Richard de Boer 2021-08-11 01:10:03 +02:00
parent 1d649a58fd
commit b21d432cce
7 changed files with 45 additions and 6 deletions

View File

@ -3242,18 +3242,19 @@
] ]
}, },
{ "id": "qmsched", { "id": "qmsched",
"name": "Quiet Mode Schedule", "name": "Quiet Mode Schedule and Widget",
"shortName":"Quiet Mode", "shortName":"Quiet Mode",
"icon": "app.png", "icon": "app.png",
"version":"0.02", "version":"0.02",
"description": "Automatically turn Quiet Mode on or off at set times", "description": "Automatically turn Quiet Mode on or off at set times",
"readme": "README.md", "readme": "README.md",
"tags": "tool", "tags": "tool,widget",
"storage": [ "storage": [
{"name":"qmsched","url":"lib.js"}, {"name":"qmsched","url":"lib.js"},
{"name":"qmsched.app.js","url":"app.js"}, {"name":"qmsched.app.js","url":"app.js"},
{"name":"qmsched.boot.js","url":"boot.js"}, {"name":"qmsched.boot.js","url":"boot.js"},
{"name":"qmsched.img","url":"icon.js","evaluate":true} {"name":"qmsched.img","url":"icon.js","evaluate":true},
{"name":"qmsched.wid.js","url":"widget.js"}
], ],
"data": [ "data": [
{"name":"qmsched.json"} {"name":"qmsched.json"}

View File

@ -1,2 +1,3 @@
0.01: First version 0.01: First version
0.02: Simplify scheduling logic 0.02: Add widget

View File

@ -1,5 +1,9 @@
# Quiet Mode Schedule # Quiet Mode Schedule and Widget
Automatically turn Quiet Mode on or off at set times. Automatically turn Quiet Mode on or off at set times, and display a widget when enabled.
### Edit Schedule:
![Main menu](screenshot_main.png) ![Edit Schedule menu](screenshot_edit.png) ![Main menu](screenshot_main.png) ![Edit Schedule menu](screenshot_edit.png)
### Widget:
![Widget, quiet mode: silent](screenshot_widget_silent.png) ![Widget, quiet mode: alarms](screenshot_widget_alarms.png)

View File

@ -14,4 +14,5 @@ exports.setMode = function(mode) {
if (s.brightness && s.brightness!=1) Bangle.setLCDBrightness(s.brightness); if (s.brightness && s.brightness!=1) Bangle.setLCDBrightness(s.brightness);
} }
if (mode && s.qmTimeout) Bangle.setLCDTimeout(s.qmTimeout); if (mode && s.qmTimeout) Bangle.setLCDTimeout(s.qmTimeout);
if (typeof (WIDGETS)!=="undefined" && "qmsched" in WIDGETS) {WIDGETS["qmsched"].draw();}
}; };

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

32
apps/qmsched/widget.js Normal file
View File

@ -0,0 +1,32 @@
WIDGETS["qmsched"] = {
area: "tl", width: 24, draw: function() {
const mode = (require("Storage").readJSON("setting.json", 1) || {}).quiet|0;
if (mode===0) { // Off
if (this.width!==0) {
this.width = 0;
Bangle.drawWidgets();
}
return;
}
// not Off: make sure width is correct
if (this.width!==24) {
this.width = 24;
Bangle.drawWidgets();
return; // drawWidgets will call draw again
}
let x = this.x, y = this.y;
g.clearRect(x, y, x+23, y+23);
// quiet mode: draw dim red one-way-street sign
x = this.x+11;y = this.y+11; // center of widget
g.setColor(0.8, 0, 0).fillCircle(x, y, 8);
g.setColor(g.theme.bg).fillRect(x-6, y-2, x+6, y+2);
if (mode>1) {return;} // no alarms
// alarms still on: draw alarm icon in bottom-right corner
x = this.x+18;y = this.y+17; // center of alarm
g.setColor(1, 1, 0)
.fillCircle(x, y, 3) // alarm body
.fillRect(x-5, y+2, x+5, y+3) // bottom ridge
.fillRect(x-1, y-5, x+1, y+5).drawLine(x, y-6, x, y+6) // top+bottom
.drawLine(x+5, y-3, x+3, y-5).drawLine(x-5, y-3, x-3, y-5); // wriggles
},
};