messagelist: add `debug()` statements

Set `global.DEBUG_MESSAGELIST = true` to enable
master
Richard de Boer 2023-08-17 13:34:26 +02:00
parent f67d9eb85f
commit c9ba8997b6
No known key found for this signature in database
1 changed files with 23 additions and 1 deletions

View File

@ -24,6 +24,9 @@
RIGHT = 1, LEFT = -1, // swipe directions RIGHT = 1, LEFT = -1, // swipe directions
UP = -1, DOWN = 1; // updown directions UP = -1, DOWN = 1; // updown directions
const Layout = require("Layout"); const Layout = require("Layout");
const debug = function() {
if (global.DEBUG_MESSAGELIST) console.log.apply(console, ['messagelist:'].concat(arguments));
}
const settings = () => require("messagegui").settings(); const settings = () => require("messagegui").settings();
const fontTiny = "6x8"; // fixed size, don't use this for important things const fontTiny = "6x8"; // fixed size, don't use this for important things
@ -45,6 +48,7 @@
/// List of all our messages /// List of all our messages
let MESSAGES; let MESSAGES;
const saveMessages = function() { const saveMessages = function() {
debug('saveMessages()');
const noSave = ["alarm", "call", "music"]; // assume these are outdated once we close the app const noSave = ["alarm", "call", "music"]; // assume these are outdated once we close the app
noSave.forEach(id => remove({id: id})); noSave.forEach(id => remove({id: id}));
require("messages").write(MESSAGES require("messages").write(MESSAGES
@ -56,6 +60,7 @@
); );
}; };
const uiRemove = function() { const uiRemove = function() {
debug('uiRemove()');
if (musicTimeout) clearTimeout(musicTimeout); if (musicTimeout) clearTimeout(musicTimeout);
layout = undefined; layout = undefined;
Bangle.removeListener("message", onMessage); Bangle.removeListener("message", onMessage);
@ -85,6 +90,7 @@
} }
const setUI = function(options, cb) { const setUI = function(options, cb) {
debug('setUI(', options, cb?'<callback>':cb)
delete Bangle.uiRemove; // don't clear out things when switching UI within the app delete Bangle.uiRemove; // don't clear out things when switching UI within the app
options = Object.assign({mode:"custom", remove: () => uiRemove()}, options); options = Object.assign({mode:"custom", remove: () => uiRemove()}, options);
// If options={} assume we still want `remove` to be called when leaving via fast load (so we must have 'mode:custom') // If options={} assume we still want `remove` to be called when leaving via fast load (so we must have 'mode:custom')
@ -111,6 +117,7 @@
}; };
const onMessage = function(type, msg) { const onMessage = function(type, msg) {
debug(`onMessage(${type}`, msg);
if (msg.handled) return; if (msg.handled) return;
msg.handled = true; msg.handled = true;
switch(type) { switch(type) {
@ -135,6 +142,7 @@
Bangle.on("message", onMessage); Bangle.on("message", onMessage);
const onCall = function(msg) { const onCall = function(msg) {
debug('onCall(', msg);
if (msg.t==="remove") { if (msg.t==="remove") {
call = undefined; call = undefined;
return exitScreen("call"); return exitScreen("call");
@ -145,6 +153,7 @@
showCall(); showCall();
}; };
const onAlarm = function(msg) { const onAlarm = function(msg) {
debug('onAlarm(', msg);
if (msg.t==="remove") { if (msg.t==="remove") {
alarm = undefined; alarm = undefined;
return exitScreen("alarm"); return exitScreen("alarm");
@ -155,6 +164,7 @@
}; };
let musicTimeout; let musicTimeout;
const onMusic = function(msg) { const onMusic = function(msg) {
debug('onMusic(', msg);
const hadMusic = !!music; const hadMusic = !!music;
if (musicTimeout) clearTimeout(musicTimeout); if (musicTimeout) clearTimeout(musicTimeout);
musicTimeout = undefined; musicTimeout = undefined;
@ -184,6 +194,7 @@
} }
}; };
const onMap = function(msg) { const onMap = function(msg) {
debug('onMap(', msg);
const hadMap = !!map; const hadMap = !!map;
if (msg.t==="remove") { if (msg.t==="remove") {
map = undefined; map = undefined;
@ -196,6 +207,7 @@
else if (active==="main" && !hadMap) showMain(); // refresh menu: add "Map" entry else if (active==="main" && !hadMap) showMain(); // refresh menu: add "Map" entry
}; };
const onText = function(msg) { const onText = function(msg) {
debug('onText(', msg);
require("messages").apply(msg, MESSAGES); require("messages").apply(msg, MESSAGES);
const mIdx = MESSAGES.findIndex(m => m.id===msg.id); const mIdx = MESSAGES.findIndex(m => m.id===msg.id);
if (!MESSAGES[mIdx]) if (back==="messages") back = undefined; if (!MESSAGES[mIdx]) if (back==="messages") back = undefined;
@ -237,6 +249,7 @@
}; };
const showMap = function() { const showMap = function() {
debug('showMap()');
setActive("map"); setActive("map");
delete map.new; delete map.new;
let m, distance, street, target, eta; let m, distance, street, target, eta;
@ -319,6 +332,7 @@
else Bangle.musicControl(action); else Bangle.musicControl(action);
}; };
const showMusic = function() { const showMusic = function() {
debug('showMusic()', music);
if (active!==music) setActive("music"); if (active!==music) setActive("music");
if (!music) music = {track: "<unknown>", artist: "<unknown>", album: "", state: "pause"}; if (!music) music = {track: "<unknown>", artist: "<unknown>", album: "", state: "pause"};
delete music.new; delete music.new;
@ -442,12 +456,14 @@
let layout; let layout;
const clearStuff = function() { const clearStuff = function() {
debug('clearStuff()');
delete Bangle.appRect; delete Bangle.appRect;
layout = undefined; layout = undefined;
setUI(); setUI();
g.reset().clearRect(Bangle.appRect); g.reset().clearRect(Bangle.appRect);
}; };
const setActive = function(screen, args) { const setActive = function(screen, args) {
debug(`setActive(${screen}`, args);
clearStuff(); clearStuff();
if (active && screen!==active) back = active; if (active && screen!==active) back = active;
if (screen==="messages") messageNum = args; if (screen==="messages") messageNum = args;
@ -476,6 +492,7 @@
} }
}; };
const showMain = function() { const showMain = function() {
debug('showMain()');
setActive("main"); setActive("main");
let grid = {"": {title:/*LANG*/"Messages", align: 0, back: load}}; let grid = {"": {title:/*LANG*/"Messages", align: 0, back: load}};
if (call) grid[/*LANG*/"Incoming Call"] = {icon: "Phone", cb: showCall}; if (call) grid[/*LANG*/"Incoming Call"] = {icon: "Phone", cb: showCall};
@ -640,6 +657,7 @@
}; };
const showSettings = function() { const showSettings = function() {
debug('showSettings()');
setActive("settings"); setActive("settings");
eval(require("Storage").read("messagelist.settings.js"))(() => { eval(require("Storage").read("messagelist.settings.js"))(() => {
setFont(); setFont();
@ -647,6 +665,7 @@
}); });
}; };
const showCall = function() { const showCall = function() {
debug('showCall()');
setActive("call"); setActive("call");
delete call.new; delete call.new;
Bangle.setLocked(false); Bangle.setLocked(false);
@ -722,6 +741,7 @@
}); });
}; };
const showAlarm = function() { const showAlarm = function() {
debug('showAlarm()');
// dismissing alarms doesn't seem to work, so this is simple */ // dismissing alarms doesn't seem to work, so this is simple */
setActive("alarm"); setActive("alarm");
delete alarm.new; delete alarm.new;
@ -830,6 +850,7 @@
); );
}; };
const showMessage = function(num, bottom) { const showMessage = function(num, bottom) {
debug(`showMessage(${num}, ${!!bottom})`);
if (num<0) num = 0; if (num<0) num = 0;
if (!num) num = 0; // no number: show first if (!num) num = 0; // no number: show first
if (num>=MESSAGES.length) num = MESSAGES.length-1; if (num>=MESSAGES.length) num = MESSAGES.length-1;
@ -1133,6 +1154,7 @@
* Stop auto-unload timeout and buzzing, remove listeners for this function * Stop auto-unload timeout and buzzing, remove listeners for this function
*/ */
const clearUnreadStuff = function() { const clearUnreadStuff = function() {
debug('clearUnreadStuff()');
require("messages").stopBuzz(); require("messages").stopBuzz();
if (unreadTimeout) clearTimeout(unreadTimeout); if (unreadTimeout) clearTimeout(unreadTimeout);
unreadTimeout = undefined; unreadTimeout = undefined;
@ -1208,4 +1230,4 @@
// stop buzzing, auto-close timeout on input // stop buzzing, auto-close timeout on input
["touch", "drag", "swipe"].forEach(l => Bangle.on(l, clearUnreadStuff)); ["touch", "drag", "swipe"].forEach(l => Bangle.on(l, clearUnreadStuff));
(B2 ? [BTN1] : [BTN1, BTN2, BTN3]).forEach(b => watches.push(setWatch(clearUnreadStuff, b, false))); (B2 ? [BTN1] : [BTN1, BTN2, BTN3]).forEach(b => watches.push(setWatch(clearUnreadStuff, b, false)));
} }