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