widpedom: Fix daily goal, don't store settings in separate file
parent
4f7cbbb1b5
commit
a0fa104078
|
|
@ -786,7 +786,7 @@
|
||||||
{ "id": "widpedom",
|
{ "id": "widpedom",
|
||||||
"name": "Pedometer widget",
|
"name": "Pedometer widget",
|
||||||
"icon": "widget.png",
|
"icon": "widget.png",
|
||||||
"version":"0.09",
|
"version":"0.10",
|
||||||
"description": "Daily pedometer widget",
|
"description": "Daily pedometer widget",
|
||||||
"tags": "widget",
|
"tags": "widget",
|
||||||
"type":"widget",
|
"type":"widget",
|
||||||
|
|
|
||||||
|
|
@ -6,3 +6,4 @@
|
||||||
0.07: Tweaks for variable size widget system
|
0.07: Tweaks for variable size widget system
|
||||||
0.08: Ensure redrawing works with variable size widget system
|
0.08: Ensure redrawing works with variable size widget system
|
||||||
0.09: Add daily goal
|
0.09: Add daily goal
|
||||||
|
0.10: Fix daily goal, don't store settings in separate file
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
(function(back) {
|
(function(back) {
|
||||||
const SETTINGS_FILE = 'widpedom.settings.json'
|
const PEDOMFILE = "wpedom.json";
|
||||||
|
|
||||||
// initialize with default settings...
|
// initialize with default settings...
|
||||||
let s = {
|
let s = {
|
||||||
|
|
@ -9,13 +9,15 @@
|
||||||
// ...and overwrite them with any saved values
|
// ...and overwrite them with any saved values
|
||||||
// This way saved values are preserved if a new version adds more settings
|
// This way saved values are preserved if a new version adds more settings
|
||||||
const storage = require('Storage')
|
const storage = require('Storage')
|
||||||
const saved = storage.readJSON(SETTINGS_FILE, 1) || {}
|
const d = storage.readJSON(PEDOMFILE, 1) || {}
|
||||||
|
const saved = d.settings || {}
|
||||||
for (const key in saved) {
|
for (const key in saved) {
|
||||||
s[key] = saved[key]
|
s[key] = saved[key]
|
||||||
}
|
}
|
||||||
|
|
||||||
function save() {
|
function save() {
|
||||||
storage.write(SETTINGS_FILE, s)
|
d.settings = s
|
||||||
|
storage.write(PEDOMFILE, d)
|
||||||
WIDGETS['wpedom'].reload()
|
WIDGETS['wpedom'].reload()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
(() => {
|
(() => {
|
||||||
const PEDOMFILE = "wpedom.json"
|
const PEDOMFILE = "wpedom.json"
|
||||||
const SETTINGS_FILE = "widpedom.settings.json"
|
|
||||||
const DEFAULTS = {
|
const DEFAULTS = {
|
||||||
'goal': 10000,
|
'goal': 10000,
|
||||||
'progress': false,
|
'progress': false,
|
||||||
|
|
@ -16,7 +15,8 @@
|
||||||
let settings;
|
let settings;
|
||||||
|
|
||||||
function loadSettings() {
|
function loadSettings() {
|
||||||
settings = require('Storage').readJSON(SETTINGS_FILE, 1) || {};
|
const d = require('Storage').readJSON(PEDOMFILE, 1) || {};
|
||||||
|
settings = d.settings || {};
|
||||||
}
|
}
|
||||||
|
|
||||||
function setting(key) {
|
function setting(key) {
|
||||||
|
|
@ -25,7 +25,6 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function drawProgress(stps) {
|
function drawProgress(stps) {
|
||||||
if (setting('progress')) {
|
|
||||||
const width = 24, half = width/2;
|
const width = 24, half = width/2;
|
||||||
const goal = setting('goal'), left = Math.max(goal-stps,0);
|
const goal = setting('goal'), left = Math.max(goal-stps,0);
|
||||||
const c = left ? COLORS.progress : COLORS.done;
|
const c = left ? COLORS.progress : COLORS.done;
|
||||||
|
|
@ -51,7 +50,6 @@
|
||||||
g.setColor(0).fillPoly(p);
|
g.setColor(0).fillPoly(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// draw your widget
|
// draw your widget
|
||||||
function draw() {
|
function draw() {
|
||||||
|
|
@ -62,7 +60,7 @@
|
||||||
let stps = stp_today.toString();
|
let stps = stp_today.toString();
|
||||||
g.reset();
|
g.reset();
|
||||||
g.clearRect(this.x, this.y, this.x + width, this.y + 23); // erase background
|
g.clearRect(this.x, this.y, this.x + width, this.y + 23); // erase background
|
||||||
drawProgress(stps);
|
if (setting('progress')){ drawProgress.call(this, stps); }
|
||||||
g.setColor(COLORS.white);
|
g.setColor(COLORS.white);
|
||||||
if (stps.length > 3){
|
if (stps.length > 3){
|
||||||
stps = stps.slice(0,-3) + "," + stps.slice(-3);
|
stps = stps.slice(0,-3) + "," + stps.slice(-3);
|
||||||
|
|
@ -104,9 +102,11 @@
|
||||||
});
|
});
|
||||||
// When unloading, save state
|
// When unloading, save state
|
||||||
E.on('kill', () => {
|
E.on('kill', () => {
|
||||||
|
if (!settings) { loadSettings() }
|
||||||
let d = {
|
let d = {
|
||||||
lastUpdate : lastUpdate.toISOString(),
|
lastUpdate : lastUpdate.toISOString(),
|
||||||
stepsToday : stp_today
|
stepsToday : stp_today,
|
||||||
|
settings : settings,
|
||||||
};
|
};
|
||||||
require("Storage").write(PEDOMFILE,d);
|
require("Storage").write(PEDOMFILE,d);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue