sleeplog: Fix logfile disabling, add status icons

Update app.js
 - adjust label position to improve readability on light themes
 - add icons to display service states
Update ChangeLog
 - compact old and add new changes
Update lib.js
 - fix logfile correction in `setEnabled(...)` to make disable logging possible
 - simplify logfile checks
Update README.md
 - add icons of the service states
Update settings.js
 - fix error on reading a non string logfile value
Add icons: disabled.png, nolog.png and powersaving.png
master
storm64 2022-02-16 12:52:00 +01:00
parent a4b695f8e6
commit a110a30ad5
8 changed files with 45 additions and 15 deletions

View File

@ -1,4 +1,18 @@
0.01: New App!
0.02: Fix crash on start #1423
0.03: Added power saving mode, move all read/write log actions into lib/module
0.04: Fix #1445, display loading info while calculating sleep data
0.04: Fix #1445, display loading info, add icons to display service states
Update app.js
- adjust label position to improve readability on light themes
- add icons to display service states
Update ChangeLog
- compact old and add new changes
Update lib.js
- fix logfile correction in `setEnabled(...)` to make disable logging possible
- simplify logfile checks
Update README.md
- add icons of the service states
Update settings.js
- fix error on reading a non string logfile value
Add icons: disabled.png, nolog.png and powersaving.png

View File

@ -49,6 +49,7 @@ also provides a power saving mode using the built in movement calculation. The i
* __Power Saving__
_on_ / __off__
En-/Disable power saving mode. _Saves battery, but might decrease accurracy._
In the app the following icon on the right indicates that power saving mode is enabled: ![](powersaving.png)
* __Max Move__ | maximal movement threshold
(only available when on power saving mode)
_50_ / _51_ / _..._ / __100__ / _..._ / _200_
@ -65,10 +66,12 @@ also provides a power saving mode using the built in movement calculation. The i
* __Enabled__
__on__ / _off_
En-/Disable the service (all background activities). _Saves the most battery, but might make this app useless._
In the app the following icon on the left indicates that the service is disabled: ![](disabled.png)
* __Logfile__
__default__ / _off_
En-/Disable logging by setting the logfile to _sleeplog.log_ / _undefined_.
If the logfile has been customized it is displayed with _custom_.
In the app the following icon on the left indicates that logging is disabled: ![](nolog.png)
---
### Global Object and Module Functions

View File

@ -64,7 +64,7 @@ function drawLog(topY, viewUntil) {
for (var x = 0; x < hours; x++) {
g.fillRect(x * stepwidth, y + 2, x * stepwidth, y + 4);
g.setFontAlign(-1, -1).setFont("6x8")
.drawString((startHour + x) % 24, x * stepwidth, y + 6);
.drawString((startHour + x) % 24, x * stepwidth + 1, y + 6);
}
// define variables for sleep calculation
@ -143,7 +143,7 @@ function drawAnalysis(toDate) {
// draw log graphs and read outputs
drawLog(110, toDate).forEach(
(value, index) => outputs[index] += value);
drawLog(145, Date(toDate.valueOf() - 432E5)).forEach(
drawLog(144, Date(toDate.valueOf() - 432E5)).forEach(
(value, index) => outputs[index] += value);
// draw outputs
@ -176,12 +176,22 @@ function drawNightTo(prevDays) {
// clear heading area
g.clearRect(0, 24, width, 70);
// display service statuses: service, loggging and powersaving
g.setColor(global.sleeplog && sleeplog.enabled && sleeplog.logfile ? sleeplog.powersaving ? 2016 : g.theme.bg : 63488);
g.fillRect(0, 30, width, 66).reset();
// display service states: service, loggging and powersaving
if (!sleeplog.enabled) {
// draw disabled service icon
g.setColor(1, 0, 0)
.drawImage(atob("FBSBAAH4AH/gH/+D//w/n8f5/nud7znP85z/f+/3/v8/z/P895+efGPj4Hw//8H/+Af+AB+A"), 2, 36);
} else if (!sleeplog.logfile) {
// draw disabled log icon
g.reset().drawImage(atob("EA6BAM//z/8AAAAAz//P/wAAAADP/8//AAAAAM//z/8="), 4, 40)
.setColor(1, 0, 0).fillPoly([2, 38, 4, 36, 22, 54, 20, 56]);
}
// draw power saving icon
if (sleeplog.powersaving) g.setColor(0, 1, 0)
.drawImage(atob("FBSBAAAAcAD/AH/wP/4P/+H//h//4//+fv/nj/7x/88//Of/jH/4j/8I/+Af+AH+AD8AA4AA"), width - 22, 36);
// draw headline
g.setFont("12x20").setFontAlign(0, -1);
g.reset().setFont("12x20").setFontAlign(0, -1);
g.drawString("Night to " + require('locale').dow(toDate, 1) + "\n" +
require('locale').date(toDate, 1), center, 30);
@ -195,7 +205,7 @@ function drawNightTo(prevDays) {
// calculate and draw analysis after timeout for faster feedback
if (ATID) ATID = clearTimeout(ATID);
ATID = setTimeout(drawAnalysis, 50, toDate);
ATID = setTimeout(drawAnalysis, 100, toDate);
}
// define function to draw and setup UI

BIN
apps/sleeplog/disabled.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.5 KiB

View File

@ -5,8 +5,8 @@ exports = {
if (typeof global.sleeplog !== "object") return;
// set default logfile
logfile = (typeof logfile === "string" && logfile.endsWith(".log")) ? logfile :
logfile === false ? undefined : "sleeplog.log";
if ((typeof logfile !== "string" || !logfile.endsWith(".log")) &&
logfile !== false) logfile = "sleeplog.log";
// stop if enabled
if (global.sleeplog.enabled) global.sleeplog.stop();
@ -40,8 +40,9 @@ exports = {
// - string // additional information
readLog: function(logfile, since, until) {
// check/set logfile
logfile = typeof logfile === "string" && logfile.endsWith(".log") ? logfile :
(global.sleeplog || {}).logfile || "sleeplog.log";
if (typeof logfile !== "string" || !logfile.endsWith(".log")) {
logfile = (global.sleeplog || {}).logfile || "sleeplog.log";
}
// check if since is in the future
if (since > Date()) return [];
@ -73,8 +74,10 @@ exports = {
// replace log with input if at least one entry like above is inside another array
writeLog: function(logfile, input) {
// check/set logfile
logfile = typeof logfile === "string" && logfile.endsWith(".log") ? logfile :
(global.sleeplog || {}).logfile || "sleeplog.log";
if (typeof logfile !== "string" || !logfile.endsWith(".log")) {
if (!global.sleeplog || sleeplog.logfile === false) return;
logfile = sleeplog.logfile || "sleeplog.log";
}
// check if input is an array
if (typeof input !== "object" || typeof input.length !== "number") return;

BIN
apps/sleeplog/nolog.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.5 KiB

View File

@ -127,7 +127,7 @@
}
},
"Logfile ": {
value: settings.logfile === "sleeplog.log" ? true : settings.logfile.endsWith(".log") ? "custom" : false,
value: settings.logfile === "sleeplog.log" ? true : (settings.logfile || "").endsWith(".log") ? "custom" : false,
format: v => v === true ? "default" : v ? "custom" : "off",
onchange: function(v) {
if (v !== "custom") {