[sleeplogalarm] Correct hide + replace all `var`

master
storm64 2023-05-29 23:45:27 +02:00
parent f609e3e051
commit eab0e8c620
6 changed files with 32 additions and 28 deletions

View File

@ -2,3 +2,4 @@
0.02: Add "from Consec."-setting 0.02: Add "from Consec."-setting
0.03: Correct how to ignore last triggered alarm 0.03: Correct how to ignore last triggered alarm
0.04: Make "disable alarm" possible on next day; correct alarm filtering; improve settings 0.04: Make "disable alarm" possible on next day; correct alarm filtering; improve settings
0.041: Correct hide function + replace all `var` with `let`.

View File

@ -1,6 +1,6 @@
# Sleep Log Alarm # Sleep Log Alarm
This widget searches for active alarms and raises an own alarm event up to the defined time earlier, if in light sleep or awake phase. Optional the earlier alarm will only be triggered if comming from or in consecutive sleep. The settings of the earlier alarm can be adjusted and it is possible to filter the targeting alarms by time and message. By default the time of the targeting alarm is displayed inside the widget which can be adjusted, too. This widget searches for active alarms and raises an own alarm event up to the defined time earlier, if in light sleep or awake phase. Optional the earlier alarm will only be triggered if comming from or in consecutive sleep. The settings of the earlier alarm can be adjusted and it is possible to filter the targeting alarms by time and message. The widget is only displayed if an active alarm is detected. The time of the targeting alarm is displayed inside the widget, too. The time or the complete widget can be hidden in the options.
_This widget does not detect sleep on its own and can not create alarms. It requires the [sleeplog](/apps/?id=sleeplog) app and any alarm app that uses [sched](/apps/?id=sched) to be installed._ _This widget does not detect sleep on its own and can not create alarms. It requires the [sleeplog](/apps/?id=sleeplog) app and any alarm app that uses [sched](/apps/?id=sched) to be installed._
@ -30,7 +30,7 @@ _This widget does not detect sleep on its own and can not create alarms. It requ
- __msg includes__ | include only alarms including this string in msg - __msg includes__ | include only alarms including this string in msg
__""__ / ... __""__ / ...
- __Widget__ submenu - __Widget__ submenu
- __hide__ | completely hide the widget - __hide always__ | completely hide the widget
_on_ / __off__ _on_ / __off__
- __show time__ | show the time of the targeting alarm - __show time__ | show the time of the targeting alarm
__on__ / _off_ __on__ / _off_

View File

@ -1,5 +1,5 @@
// load library // load library
var sched = require("sched"); let sched = require("sched");
// find next active alarm in range // find next active alarm in range
function getNextAlarm(allAlarms, fo, withId) { function getNextAlarm(allAlarms, fo, withId) {
@ -10,7 +10,7 @@ function getNextAlarm(allAlarms, fo, withId) {
// return next active alarms in range, filter for // return next active alarms in range, filter for
// active && not timer && not own alarm && // active && not timer && not own alarm &&
// after from && before to && includes msg // after from && before to && includes msg
var ret = allAlarms.filter( let ret = allAlarms.filter(
a => a.on && !a.timer && a.id !== "sleeplog" && a => a.on && !a.timer && a.id !== "sleeplog" &&
a.t >= fo.from && a.t < fo.to && (!fo.msg || a.msg.includes(fo.msg)) a.t >= fo.from && a.t < fo.to && (!fo.msg || a.msg.includes(fo.msg))
).map(a => { // add time to alarm ).map(a => { // add time to alarm
@ -21,7 +21,7 @@ function getNextAlarm(allAlarms, fo, withId) {
).sort((a, b) => a.tTo - b.tTo); ).sort((a, b) => a.tTo - b.tTo);
// prevent triggering for an already triggered alarm again if available // prevent triggering for an already triggered alarm again if available
if (fo.lastDate) { if (fo.lastDate) {
var toLast = fo.lastDate - new Date().valueOf() + 1000; let toLast = fo.lastDate - new Date().valueOf() + 1000;
if (toLast > 0) ret = ret.filter(a => a.tTo > toLast); if (toLast > 0) ret = ret.filter(a => a.tTo > toLast);
} }
// return first entry // return first entry
@ -59,7 +59,7 @@ exports = {
if (typeof (global.sleeplog || {}).trigger !== "object") return; if (typeof (global.sleeplog || {}).trigger !== "object") return;
// read settings to calculate alarm range // read settings to calculate alarm range
var settings = exports.getSettings(); let settings = exports.getSettings();
// set the alarm time // set the alarm time
this.time = getNextAlarm(sched.getAlarms(), settings.filter).t; this.time = getNextAlarm(sched.getAlarms(), settings.filter).t;
@ -68,7 +68,7 @@ exports = {
if (!this.time) return; if (!this.time) return;
// set widget width if not hidden // set widget width if not hidden
if (!this.hidden) this.width = 8; if (!settings.hidden) this.width = 8;
// insert sleeplogalarm conditions and function // insert sleeplogalarm conditions and function
sleeplog.trigger.sleeplogalarm = { sleeplog.trigger.sleeplogalarm = {
@ -87,22 +87,22 @@ exports = {
// trigger function // trigger function
trigger: function() { trigger: function() {
// read settings // read settings
var settings = exports.getSettings(); let settings = exports.getSettings();
// read all alarms // read all alarms
var allAlarms = sched.getAlarms(); let allAlarms = sched.getAlarms();
// find first active alarm // find first active alarm
var alarm = getNextAlarm(sched.getAlarms(), settings.filter, settings.disableOnAlarm); let alarm = getNextAlarm(sched.getAlarms(), settings.filter, settings.disableOnAlarm);
// return if no alarm is found // return if no alarm is found
if (!alarm) return; if (!alarm) return;
// get now // get now
var now = new Date(); let now = new Date();
// get date of the alarm // get date of the alarm
var aDate = new Date(now + alarm.tTo); let aDate = new Date(now + alarm.tTo);
// disable earlier triggered alarm if set // disable earlier triggered alarm if set
if (settings.disableOnAlarm) { if (settings.disableOnAlarm) {

View File

@ -2,7 +2,7 @@
"id":"sleeplogalarm", "id":"sleeplogalarm",
"name":"Sleep Log Alarm", "name":"Sleep Log Alarm",
"shortName": "SleepLogAlarm", "shortName": "SleepLogAlarm",
"version": "0.04", "version": "0.041",
"description": "Enhance your morning and let your alarms wake you up when you are in light sleep.", "description": "Enhance your morning and let your alarms wake you up when you are in light sleep.",
"icon": "app.png", "icon": "app.png",
"type": "widget", "type": "widget",

View File

@ -1,6 +1,6 @@
(function(back) { (function(back) {
// read settings // read settings
var settings = require("sleeplogalarm").getSettings(); let settings = require("sleeplogalarm").getSettings();
// write change to storage // write change to storage
function writeSetting() { function writeSetting() {
@ -23,7 +23,7 @@
// show widget menu // show widget menu
function showFilterMenu() { function showFilterMenu() {
// set menu // set menu
var filterMenu = { let filterMenu = {
"": { "": {
title: "Filter Alarm" title: "Filter Alarm"
}, },
@ -64,22 +64,22 @@
}) })
} }
}; };
var menu = E.showMenu(filterMenu); let menu = E.showMenu(filterMenu);
} }
// show widget menu // show widget menu
function showWidMenu() { function showWidMenu() {
// define color values and names // define color values and names
var colName = ["red", "yellow", "green", "cyan", "blue", "magenta", "black", "white"]; let colName = ["red", "yellow", "green", "cyan", "blue", "magenta", "black", "white"];
var colVal = [63488, 65504, 2016, 2047, 31, 63519, 0, 65535]; let colVal = [63488, 65504, 2016, 2047, 31, 63519, 0, 65535];
// set menu // set menu
var widgetMenu = { let widgetMenu = {
"": { "": {
title: "Widget Settings" title: "Widget Settings"
}, },
/*LANG*/"< Back": () => showMain(9), /*LANG*/"< Back": () => showMain(9),
/*LANG*/"hide": { /*LANG*/"hide always": {
value: settings.wid.hide, value: settings.wid.hide,
onchange: v => { onchange: v => {
settings.wid.hide = v; settings.wid.hide = v;
@ -105,13 +105,13 @@
} }
} }
}; };
var menu = E.showMenu(widgetMenu); let menu = E.showMenu(widgetMenu);
} }
// show main menu // show main menu
function showMain(selected) { function showMain(selected) {
// set menu // set menu
var mainMenu = { let mainMenu = {
"": { "": {
title: "Sleep Log Alarm", title: "Sleep Log Alarm",
selected: selected selected: selected
@ -184,7 +184,7 @@
} }
} }
}; };
var menu = E.showMenu(mainMenu); let menu = E.showMenu(mainMenu);
} }
// draw main menu // draw main menu

View File

@ -10,10 +10,13 @@ if ((require("Storage").readJSON("sleeplogalarm.settings.json", true) || {enable
time: 0, time: 0,
earlier: settings.earlier, earlier: settings.earlier,
draw: function () { draw: function () {
// draw if width is set
if (this.width) {
// draw zzz // draw zzz
g.reset().setColor(settings.wid.color).drawImage(atob("BwoBD8SSSP4EEEDg"), this.x + 1, this.y); g.reset().setColor(settings.wid.color).drawImage(atob("BwoBD8SSSP4EEEDg"), this.x + 1, this.y);
// call function to draw the time of alarm if a alarm is found // call function to draw the time of alarm if a alarm is found
if (this.time) this.drawTime(this.time + 1); if (this.time) this.drawTime(this.time + 1);
}
}, },
drawTime: () => {}, drawTime: () => {},
reload: require("sleeplogalarm").widReload reload: require("sleeplogalarm").widReload