Merge pull request #1070 from stephenPspackman/master

Make internal menu time out + small fixes
master
Gordon Williams 2021-12-13 10:12:27 +00:00 committed by GitHub
commit 44e4bb1d3d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 19 deletions

View File

@ -4714,7 +4714,7 @@
{ "id": "pooqroman", { "id": "pooqroman",
"name": "pooq Roman watch face", "name": "pooq Roman watch face",
"shortName":"pooq Roman", "shortName":"pooq Roman",
"version":"0.0.0", "version":"0.0.2",
"description": "A classic watch face with a certain dynamicity. Most amusing in 24h mode. Slide up to show more hands, down for less(!). By design does not support standard widgets, sorry!", "description": "A classic watch face with a certain dynamicity. Most amusing in 24h mode. Slide up to show more hands, down for less(!). By design does not support standard widgets, sorry!",
"icon": "app.png", "icon": "app.png",
"type": "clock", "type": "clock",

View File

@ -1,3 +1,4 @@
/* -*- mode: Javascript; c-basic-offset: 2; indent-tabs-mode: nil; coding: latin-1 -*- */
// pooqRoman // pooqRoman
// //
// Copyright (c) 2021 Stephen P Spackman // Copyright (c) 2021 Stephen P Spackman
@ -54,8 +55,9 @@ class Options {
this.id = this.constructor.id; this.id = this.constructor.id;
this.file = `${this.id}.json`; this.file = `${this.id}.json`;
this.backing = storage.readJSON(this.file, true) || {}; this.backing = storage.readJSON(this.file, true) || {};
this.defaults = this.constructor.defaults; Object.setPrototypeOf(this.backing, this.constructor.defaults);
Object.keys(this.defaults).forEach(k => this.bless(k)); this.reactivator = _ => this.active();
Object.keys(this.constructor.defaults).forEach(k => this.bless(k));
} }
writeBack(delay) { writeBack(delay) {
@ -71,29 +73,41 @@ class Options {
bless(k) { bless(k) {
Object.defineProperty(this, k, { Object.defineProperty(this, k, {
get: () => this.backing[k] == null ? this.defaults[k] : this.backing[k], get: () => this.backing[k],
set: v => { set: v => {
this.backing[k] = v; this.backing[k] = v;
// Ten second writeback delay, since the user will roll values up and down. // Ten second writeback delay, since the user will roll values up and down.
this.writeBack(10000); this.writeBack(10000);
} }
}); });
} }
showMenu(m) { showMenu(m) {
if (m instanceof Function) m = m();
if (m) { if (m) {
for (const k in m) if ('init' in m[k]) m[k].value = m[k].init(); for (const k in m) if ('init' in m[k]) m[k].value = m[k].init();
m[''].selected = -1; // Workaround for self-selection bug. m[''].selected = -1; // Workaround for self-selection bug.
Bangle.on('drag', this.reactivator);
this.active();
} else {
if (this.bored) clearTimeout(this.bored);
this.bored = null;
Bangle.removeListener('drag', this.reactivator);
this.emit('done');
} }
g.clear(true);
E.showMenu(m); E.showMenu(m);
} }
reset() { active() {
this.backing = {}; if (this.bored) clearTimeout(this.bored);
this.writeBack(0); this.bored = setTimeout(_ => this.showMenu(), 15000);
} }
interact() {this.showMenu(this.menu);} reset() {
this.backing = {__proto__: this.constructor.defaults};
this.writeBack(0);
}
} }
class RomanOptions extends Options { class RomanOptions extends Options {
@ -101,7 +115,7 @@ class RomanOptions extends Options {
super(); super();
this.menu = { this.menu = {
'': {title: '* face options *'}, '': {title: '* face options *'},
'< Back': _ => {this.showMenu(); this.emit('done');}, '< Back': _ => this.showMenu(),
Ticks: { Ticks: {
init: _ => this.resolution, init: _ => this.resolution,
min: 0, max: 3, min: 0, max: 3,
@ -124,9 +138,11 @@ class RomanOptions extends Options {
onchange: x => this.calendric = x, onchange: x => this.calendric = x,
format: x => ['none', 'day', 'date'][x] format: x => ['none', 'day', 'date'][x]
}, },
Defaults: _ => {this.reset();} Defaults: _ => {this.reset(); this.interact();}
}; };
} }
interact() {this.showMenu(this.menu);}
} }
RomanOptions.id = 'pooqroman'; RomanOptions.id = 'pooqroman';
@ -147,7 +163,7 @@ RomanOptions.defaults = {
hubFg: g.theme.fg, hubFg: g.theme.fg,
alarmFg: '#f00', alarmFg: '#f00',
timerFg: '#0f0', timerFg: '#0f0',
active: g.theme.fg2, activeFg: g.theme.fg2,
}; };
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
@ -434,7 +450,7 @@ class Sidebar {
} }
static gpsColour(o) { static gpsColour(o) {
const fix = Bangle.getGPSFix(); const fix = Bangle.getGPSFix();
return fix && fix.fix ? o.active : o.barFg; return fix && fix.fix ? o.activeFg : o.barFg;
} }
doPower() { doPower() {
const c = Bangle.isCharging(); const c = Bangle.isCharging();
@ -455,7 +471,7 @@ class Sidebar {
if (Bangle.isCompassOn()) { if (Bangle.isCompassOn()) {
const c = Bangle.getCompass(); const c = Bangle.getCompass();
const a = c && this.rate <= 1000; const a = c && this.rate <= 1000;
this.g.setColor(a ? this.options.active : this.options.barFg).drawImage( this.g.setColor(a ? this.options.activeFg : this.options.barFg).drawImage(
compassI, compassI,
this.x + 4 + imageWidth(compassI) / 2, this.x + 4 + imageWidth(compassI) / 2,
this.y + 4 + imageHeight(compassI) / 2, this.y + 4 + imageHeight(compassI) / 2,
@ -470,7 +486,7 @@ class Sidebar {
class Roman { class Roman {
constructor(g, events) { constructor(g, events) {
this.g = g; this.g = g;
this.state = {}; this.state = null;
const options = this.options = new RomanOptions(); const options = this.options = new RomanOptions();
this.events = events.loadFromSystem(this.options); this.events = events.loadFromSystem(this.options);
this.timescales = [1000, [1000, 60000], 60000, 3600000]; this.timescales = [1000, [1000, 60000], 60000, 3600000];
@ -480,7 +496,7 @@ class Roman {
this.seconds = Roman.hand(g, 1, 0.9, 60, _ => options.secondFg); this.seconds = Roman.hand(g, 1, 0.9, 60, _ => options.secondFg);
} }
reset() {this.state = {}; this.g.clear(true);} reset() {this.state = null;}
doIcons(which) {this.state.iconsOk = null;} doIcons(which) {this.state.iconsOk = null;}
@ -544,7 +560,7 @@ class Roman {
render(d, rate) { render(d, rate) {
const g = this.g; const g = this.g;
const state = this.state; const state = this.state || (g.clear(true), this.state = {});
const options = this.options; const options = this.options;
const events = this.events; const events = this.events;
events.clean(d, -39600000); // 11h events.clean(d, -39600000); // 11h
@ -654,8 +670,8 @@ class Clock {
drag: e => { drag: e => {
if (this.t0) { if (this.t0) {
if (e.b) { if (e.b) {
e.x > this.xN && (this.xN = e.x) || e.x > this.xX && (this.xX = e.x); e.x < this.xN && (this.xN = e.x) || e.x > this.xX && (this.xX = e.x);
e.y > this.yN && (this.yN = e.y) || e.y > this.yX && (this.xY = e.y); e.y < this.yN && (this.yN = e.y) || e.y > this.yX && (this.yX = e.y);
} else if (this.xX - this.xN < 20) { } else if (this.xX - this.xN < 20) {
if (e.y - this.e0.y < -50) { if (e.y - this.e0.y < -50) {
this.options.resolution > 0 && this.options.resolution--; this.options.resolution > 0 && this.options.resolution--;
@ -697,6 +713,7 @@ class Clock {
this.exception && clearTimeout(this.exception); this.exception && clearTimeout(this.exception);
this.interval && clearInterval(this.interval); this.interval && clearInterval(this.interval);
this.timeout = this.exception = this.interval = this.rate = null; this.timeout = this.exception = this.interval = this.rate = null;
this.face.reset(); // Cancel any ongoing background rendering
return this; return this;
} }