From 29933cb4e8b930d3ad49109fc8931bc15b3de25d Mon Sep 17 00:00:00 2001 From: jla-42 <66872002+jla-42@users.noreply.github.com> Date: Wed, 13 Mar 2024 22:29:28 +0100 Subject: [PATCH] Add files via upload --- apps/slpquiet/ChangeLog | 2 +- apps/slpquiet/README.md | 27 +++++++++++++++++++ apps/slpquiet/app-icon.js | 1 + apps/slpquiet/app.js | 45 +++++++++++++++++++++++++++++++ apps/slpquiet/app.png | Bin 0 -> 2275 bytes apps/slpquiet/boot.js | 52 ++++++++++++++++++++++++++++++++++++ apps/slpquiet/metadata.json | 16 +++++++++++ apps/slpquiet/widget.js | 36 +++++++++++++++++++++++++ 8 files changed, 178 insertions(+), 1 deletion(-) create mode 100644 apps/slpquiet/README.md create mode 100644 apps/slpquiet/app-icon.js create mode 100644 apps/slpquiet/app.js create mode 100644 apps/slpquiet/app.png create mode 100644 apps/slpquiet/boot.js create mode 100644 apps/slpquiet/metadata.json create mode 100644 apps/slpquiet/widget.js diff --git a/apps/slpquiet/ChangeLog b/apps/slpquiet/ChangeLog index 8b1378917..5560f00bc 100644 --- a/apps/slpquiet/ChangeLog +++ b/apps/slpquiet/ChangeLog @@ -1 +1 @@ - +0.01: New App! diff --git a/apps/slpquiet/README.md b/apps/slpquiet/README.md new file mode 100644 index 000000000..a1f2e94e1 --- /dev/null +++ b/apps/slpquiet/README.md @@ -0,0 +1,27 @@ +# Sleep Quiet + +Set Quiet mode (or alarms only mode), when the sleep tracking app detects sleep (each 10 min evaluated) + +## Usage + +When activated, app disables all notifications / all except alarms when sleep detected. + +## Controls + +In the app you can activate / deactivate the functionality and define if all notifications / all except alarms are to be silenced. + +## Creator + +[jla-42](https://github.com/jla-42) + +## Note +The app is based upon the [sleeplog](https://github.com/espruino/BangleApps/tree/master/apps/sleeplog) app. + +It reuses the widget from [Quiet Mode Schedule and Widget](https://github.com/espruino/BangleApps/tree/master/apps/qmsched), as it does exactly what I needed, so why reinvent the wheel. + +## ToDos +-further code clean up + +-optimization of code (and check if needed) + +-feedback is always welcome diff --git a/apps/slpquiet/app-icon.js b/apps/slpquiet/app-icon.js new file mode 100644 index 000000000..0f0ece725 --- /dev/null +++ b/apps/slpquiet/app-icon.js @@ -0,0 +1 @@ +require("heatshrink").decompress(atob("mEw4UA///jc+tfUvk+Jf8AhWoBhUoBZWgBRMCwAvKHa5bTG5UqJ4OqBY+qBYJpIBYRpIBYRRIBYQAIBbJhJBYIBBktVAAVoBYmoj//AAXWBYsdC4d1BZVdGwILO0ALIAAWdBY+vIQILI04LBrojKAAoLyX40CBeUqBZD1HAH8AA=")) diff --git a/apps/slpquiet/app.js b/apps/slpquiet/app.js new file mode 100644 index 000000000..7ec02d676 --- /dev/null +++ b/apps/slpquiet/app.js @@ -0,0 +1,45 @@ +const SETTINGS_FILE = "quietSwitch.json"; +const storage = require("Storage"); +let settings = storage.readJSON('setting.json', 1); +let saved = storage.readJSON(SETTINGS_FILE, 1) || {}; + +// Main menu +var mainmenu = { +"" : { + "title" : "Quiet Switch" + }, + + "Quiet Switch" : { + value : saved.quietWhenSleep, + format : v => v?"On":"Off", + min:0,max:1,step:1, + onchange :v=>{ + saved.quietWhenSleep = v; + storage.writeJSON(SETTINGS_FILE,saved); + } + }, + "Quiet Mode" : { + value : saved.quietMode, + format : v => v?"Alerts":"Silent", + min:0,max:1,step:1, + onchange :v=>{ + saved.quietMode = v; + storage.writeJSON(SETTINGS_FILE,saved); + } + }, + "Exit" : function() {load();}, +}; + +// Actually display the menu +E.showMenu(mainmenu); + +// Function to fix time format +function fixTime(h, m) { + if (h.toString().length <2) { + h = "0" + h.toString(); + } + if (m.toString().length <2) { + m = "0" + m.toString(); + } + return h.toString() +":" + m.toString(); +} diff --git a/apps/slpquiet/app.png b/apps/slpquiet/app.png new file mode 100644 index 0000000000000000000000000000000000000000..c038d8a5d2bcc4224381efe9241e3edc24983c10 GIT binary patch literal 2275 zcmV<92pso`P)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGf5dZ)S5dnW>Uy%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ss5NxFumo6GGSRuviHnd5YX)L)-*f*0!$;=IuXU}U64)j}MgbBjECkRK5?F-GC@E8*&ROj;%Bw&T7@Q200sLwyrZw-`;M6-e0> zwj{iBE}r75GzI8s`le8Ml~jdG;2H|<7Q){(^H9M4et||qtIZcOp7}Y07;jjtD#noe z^0%D@0e2ynNM-Oev0uo`T%h1Lt1_%K&=M{p_;NUvhMt!1&3-GKOMxFrweUkoI0FQF zDU8E&>=D@Ij4UdKUxJ<2hhZ1_zl-{6jE6Klf6I4Kwi)ockOWcth|uh=`R(e{D*jcj zoIsyXlgp92RafL&f@A?k#cX&j@HQ;R=2?7~X|>ZHx(}wnVN~@6_BFuzV(~HZGBlwA zJFz%iLvDob1f~fiQYAdU=9_TNVOzoy$^lOdln4rbs(dJ8Q%gkALgTdN%$7iD!F|hj z`%YnD7a7zNE%+-ysS1#AVWbEWCN%pMkH#>(Y;yaw-jzfkp|7NTZp$m;wpk>~c6e(* z%o!^RcY|Ue!8RZ@*uV16kN^Z%7=qgpX7*=d=6-IU+L?X#SuEjz{^3_t2@-BTxEr|U zbzP;9@WtQ?>SE?^>XRkN0+UFj09~g=*S>PW`9Q8i{!Uj5UNJzQ6={t66c2PDq#U(w xpFqmHF5~ve_sL~k!a@V+<1fVm{Vo9j{{y6Xx8*7r14{q^002ovPDHLkV1jX@N16Zt literal 0 HcmV?d00001 diff --git a/apps/slpquiet/boot.js b/apps/slpquiet/boot.js new file mode 100644 index 000000000..a4eb3faeb --- /dev/null +++ b/apps/slpquiet/boot.js @@ -0,0 +1,52 @@ +// first ensure that the sleeplog trigger object is available (sleeplog is enabled) +if (typeof (global.sleeplog || {}).trigger === "object") { + // then add your parameters with the function to call as object into the trigger object + +sleeplog.trigger["quietMode"] = { + onChange: true, // false as default, if true call fn only on a status change + from: 0, // 0 as default, in ms, first time fn will be called + // to: 24*60*60*1000, // 24h as default, in ms, last time fn will be called + to: 0, + // reference time to from & to is rounded to full minutes + fn: function(data, thisTriggerEntry) { + aSettings = require('Storage').readJSON('quietSwitch.json', 1) || {}; + const DEFAULTS = { + 'quietWhenSleep': false, + 'quietMode': 1 + }; + Object.keys(DEFAULTS).forEach(k => { + if (aSettings[k] === undefined) aSettings[k] = DEFAULTS[k]; + }); + + if (aSettings && aSettings['quietWhenSleep']){ + console.log("the sleep status is: "+data.status); + quietMode = aSettings['quietMode']; + delete aSettings; + if ((data.status === 3 || data.status === 4) + && (data.prevStatus !== 3 && data.prevStatus !== 4 )) { + bSettings = require("Storage").readJSON('setting.json',true)||{}; + current = 0|bSettings.quiet; + console.log("quiet mode is:" + current); + if (current !== quietMode ){ + console.log("fallen asleep"); + bSettings.quiet = quietMode; + require("Storage").writeJSON("setting.json", bSettings); + } + delete bSettings; + } + if ((data.status === 2 || data.status === 1) + && (data.prevStatus !== 2 && data.prevStatus !== 1 )) { + bSettings = require("Storage").readJSON('setting.json',true)||{}; + current = 0|bSettings.quiet; + console.log("quiet mode is:" + current); + if (current !== 0 ){ + console.log("woken up"); + bSettings.quiet = 0; + require("Storage").writeJSON("setting.json", bSettings); + } + delete bSettings; + } + } + } + }; +} diff --git a/apps/slpquiet/metadata.json b/apps/slpquiet/metadata.json new file mode 100644 index 000000000..d1f763e68 --- /dev/null +++ b/apps/slpquiet/metadata.json @@ -0,0 +1,16 @@ +{ "id": "slpquiet", + "name": "Sleep Quiet (activate quiet mode when asleep)", + "shortName":"Sleep Quiet", + "version":"0.01", + "description": "Set Quiet mode (or alarms only mode), when the sleep tracking app detects sleep (each 10 min evaluated)", + "icon": "app.png", + "tags": "tool,widget", + "supports" : ["BANGLEJS2"], + "readme": "README.md", + "storage": [ + {"name":"slpquiet.app.js","url":"app.js"}, + {"name":"slpquiet.boot.js","url":"boot.js"}, + {"name":"slpquiet.img","url":"app-icon.js","evaluate":true}, + {"name":"slpquiet.wid.js","url":"widget.js"} + ] +} diff --git a/apps/slpquiet/widget.js b/apps/slpquiet/widget.js new file mode 100644 index 000000000..0ad3c776f --- /dev/null +++ b/apps/slpquiet/widget.js @@ -0,0 +1,36 @@ +(function() { + WIDGETS["qmsched"] = { + area: "tl", + width: ((require("Storage").readJSON("setting.json", 1) || {}).quiet|0) ? 24 : 0, + 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.reset().clearRect(x, y, x+23, y+23); + // quiet mode: draw red one-way-street sign (dim red on Bangle.js 1) + x = this.x+11;y = this.y+11; // center of widget + g.setColor(process.env.HWVERSION===2 ? 1 : 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 + }, + }; +})();