fix going back to clock when there is a single message and it is removed

master
Bryan 2024-08-11 14:40:00 -06:00
parent 136c73a85f
commit fddf64fff2
1 changed files with 48 additions and 46 deletions

View File

@ -57,7 +57,6 @@ const clearTimeouts = function() {
}; };
const showNoMessages = function() { const showNoMessages = function() {
g.reset().clear(); g.reset().clear();
g.setFont("12x20").setFontAlign(0,0); g.setFont("12x20").setFontAlign(0,0);
g.drawString("No Messages!", Bangle.appRect.x + (Bangle.appRect.w / 2), Bangle.appRect.y + (Bangle.appRect.h / 2)); g.drawString("No Messages!", Bangle.appRect.x + (Bangle.appRect.w / 2), Bangle.appRect.y + (Bangle.appRect.h / 2));
@ -67,39 +66,42 @@ const showNoMessages = function() {
btn: _e => goBack(), btn: _e => goBack(),
remove: cleanup remove: cleanup
}); });
goBack();
}; };
const showMusic = function(music) { const showMusic = function() {
active = "music"; active = "music";
Bangle.setUI({ Bangle.setUI({
mode: "custom", mode: "custom",
btn: _e => goBack() btn: _e => goBack(),
remove: cleanup remove: cleanup
}); });
}; };
const showMap = function(map) { const showMap = function() {
active = "map"; active = "map";
Bangle.setUI({ Bangle.setUI({
mode: "custom", mode: "custom",
btn: _e => goBack() btn: _e => goBack(),
remove: cleanup remove: cleanup
}); });
}; };
const showAlarm = function(alarm) { const showAlarm = function() {
active = "alarm"; active = "alarm";
Bangle.setUI({ Bangle.setUI({
mode: "custom", mode: "custom",
btn: _e => goBack() btn: _e => goBack(),
remove: cleanup remove: cleanup
}); });
}; };
const showCall = function(call) { const showCall = function() {
if (!call) return goBack();
const incomingImg = require("heatshrink").decompress(atob("j0ewIQNgwDCnEAh0B4EAvEOgEB+F//kP4P/+E/weAgH+g8Agf4CQMH8EYgEfEYU8AYV4AQIhBAYMD8ADBg4vBgEPzwDBj/+AYM/AYV//ADCC4X/EwQiCABo=")); const incomingImg = require("heatshrink").decompress(atob("j0ewIQNgwDCnEAh0B4EAvEOgEB+F//kP4P/+E/weAgH+g8Agf4CQMH8EYgEfEYU8AYV4AQIhBAYMD8ADBg4vBgEPzwDBj/+AYM/AYV//ADCC4X/EwQiCABo="));
const outgoingImg = require("heatshrink").decompress(atob("j0ewIRO4ACBgeAh0Ag8AvEAh0B+F//kP4P/+E/wASB/0AjkD/EA8EH8EDgEfEwU8AYQhBgAhBFwXgAYMHGwUPzwDBj4mBgE/AYV/FQIDBC4X/EwQiCABoA==")); const outgoingImg = require("heatshrink").decompress(atob("j0ewIRO4ACBgeAh0Ag8AvEAh0B+F//kP4P/+E/wASB/0AjkD/EA8EH8EDgEfEwU8AYQhBgAhBFwXgAYMHGwUPzwDBj4mBgE/AYV/FQIDBC4X/EwQiCABoA=="));
const ringingImg = require("heatshrink").decompress(atob("mUywIlimAFEhgFEgYSF4AWEAIYWBAIYWBAIcAsAYBgOAgEYCwQJBBwIWBHIXAA4YSC4EGAoICCDwQ8DAQUgAQMQVtsD///AoU/AoIGCv5BBh/4gF+B4UfwF4Dgd4nAFDg8cB4P/8EA9gFC/wgBBwIzBwEDSQaOB+BzCRAM8SQSQBDAKSCTAPADwMAGoPwh4eBg+An0/SQX/jv/TwUH/wlBAAQkBADwA=")); const ringingImg = require("heatshrink").decompress(atob("mUywIlimAFEhgFEgYSF4AWEAIYWBAIYWBAIcAsAYBgOAgEYCwQJBBwIWBHIXAA4YSC4EGAoICCDwQ8DAQUgAQMQVtsD///AoU/AoIGCv5BBh/4gF+B4UfwF4Dgd4nAFDg8cB4P/8EA9gFC/wgBBwIzBwEDSQaOB+BzCRAM8SQSQBDAKSCTAPADwMAGoPwh4eBg+An0/SQX/jv/TwUH/wlBAAQkBADwA="));
@ -139,7 +141,7 @@ const showCall = function(call) {
if (cmd === "end") { if (cmd === "end") {
console.log("end"); console.log("end");
if (timeouts.timer) clearTimeout(timeouts.timer); if (timeouts["timer"]) clearTimeout(timeouts["timer"]);
let elapsedString = Bangle.elapsedString; let elapsedString = Bangle.elapsedString;
delete Bangle.elapsedString; delete Bangle.elapsedString;
g.setColor(g.theme.fg).setFont("6x15:2").setFontAlign(0, -1); g.setColor(g.theme.fg).setFont("6x15:2").setFontAlign(0, -1);
@ -195,7 +197,7 @@ const showCall = function(call) {
swipeAnimation(); swipeAnimation();
}); });
animate.then(() => { animate.then(() => {
if (timeouts.timer) clearTimeout(timeouts["timer"]); if (timeouts["timer"]) clearTimeout(timeouts["timer"]);
Bangle.messageResponse(msg, false); Bangle.messageResponse(msg, false);
goBack(); goBack();
}); });
@ -214,12 +216,11 @@ const showCall = function(call) {
swipeAnimation(); swipeAnimation();
}); });
animate.then(() => { animate.then(() => {
if (timeouts.timer) clearTimeout(timeouts["timer"]); if (timeouts["timer"]) clearTimeout(timeouts["timer"]);
Bangle.messageResponse(msg, true); Bangle.messageResponse(msg, true);
goBack(); goBack();
}); });
}; };
Bangle.setUI({ Bangle.setUI({
mode: "custom", mode: "custom",
touch: () => {if (buzzing) return require("messages").stopBuzz()}, touch: () => {if (buzzing) return require("messages").stopBuzz()},
@ -230,8 +231,8 @@ const showCall = function(call) {
}; };
const showText = function(messageNum) { const showText = function(messageNum) {
g.reset().clear();
if (!Bangle.MESSAGES.length) return goBack(); // no messages if (!Bangle.MESSAGES.length) return goBack(); // no messages
g.reset().clear();
setBusy(); // busy until everything is set up setBusy(); // busy until everything is set up
//let showAll = false; //let showAll = false;
if (messageNum === undefined) {messageNum = 0;} //showAll = true;} if (messageNum === undefined) {messageNum = 0;} //showAll = true;}
@ -340,9 +341,9 @@ const showText = function(messageNum) {
const toNext = function(removeCurrent) { const toNext = function(removeCurrent) {
if (removeCurrent == undefined) removeCurrent = false; if (removeCurrent == undefined) removeCurrent = false;
if (timeouts.animID){ if (timeouts["animID"]){
clearTimeout(timeouts.animID); clearTimeout(timeouts["animID"]);
timeouts.animID = undefined; timeouts["animID"] = undefined;
} }
firstTouch = true; firstTouch = true;
return new Promise((resolve, _reject) => { return new Promise((resolve, _reject) => {
@ -375,9 +376,9 @@ const showText = function(messageNum) {
const toPrev = function(removeCurrent) { const toPrev = function(removeCurrent) {
if (removeCurrent == undefined) removeCurrent = false; if (removeCurrent == undefined) removeCurrent = false;
if (timeouts.animID){ if (timeouts["animID"]){
clearTimeout(timeouts.animID); clearTimeout(timeouts["animID"]);
timeouts.animID = undefined; timeouts["animID"] = undefined;
} }
firstTouch = true; firstTouch = true;
return new Promise((resolve, _reject) => { return new Promise((resolve, _reject) => {
@ -425,9 +426,9 @@ const showText = function(messageNum) {
}; };
const animateToLeft = function() { const animateToLeft = function() {
if (timeouts.animID) { if (timeouts["animID"]) {
clearTimeout(timeouts.animID); clearTimeout(timeouts["animID"]);
timeouts.animID = undefined; timeouts["animID"] = undefined;
} }
let multiplier = 1; let multiplier = 1;
const endX = Bangle.appRect.x - Bangle.appRect.w; //+ (Bangle.appRect.w / 2); const endX = Bangle.appRect.x - Bangle.appRect.w; //+ (Bangle.appRect.w / 2);
@ -450,9 +451,9 @@ const showText = function(messageNum) {
}; };
const animateToRight = function() { const animateToRight = function() {
if (timeouts.animID) { if (timeouts["animID"]) {
clearTimeout(timeouts.animID); clearTimeout(timeouts["animID"]);
timeouts.animID = undefined; timeouts["animID"] = undefined;
} }
let multiplier = 1; let multiplier = 1;
const endX = Bangle.appRect.x2; // - (Bangle.appRect.w / 2); const endX = Bangle.appRect.x2; // - (Bangle.appRect.w / 2);
@ -601,6 +602,10 @@ const showText = function(messageNum) {
msgBoxes[messageNum].scroll(e.dy); msgBoxes[messageNum].scroll(e.dy);
}; };
msgBoxes[messageNum].draw();
drawFooter();
idle = true;
checkForNewMessages();
Bangle.setUI({ Bangle.setUI({
mode: "custom", mode: "custom",
drag: e => dragHandler(e), drag: e => dragHandler(e),
@ -608,20 +613,16 @@ const showText = function(messageNum) {
btn: _e => goBack(), btn: _e => goBack(),
remove: cleanup remove: cleanup
}); });
}; // showText
msgBoxes[messageNum].draw();
drawFooter();
idle = true;
checkForNewMessages();
}; // function showText
// Check for new messages, wait until there is no interaction for `idleTime` ms // Check for new messages, wait until there is no interaction for `idleTime` ms
const checkForNewMessages = function(idleTime) { const checkForNewMessages = function(idleTime) {
idleTime = idleTime ?? 3000; // how much time without interaction before we are considered idle idleTime = idleTime ?? 250; // how much time without interaction before we are considered idle
idle = false; idle = false;
if (timeouts.idleTimer) clearTimeout(timeouts.idleTimer); if (timeouts["idleTimer"]) clearTimeout(timeouts["idleTimer"]);
timeouts["idleTimer"] = setTimeout(() => { timeouts["idleTimer"] = setTimeout(() => {
if (haveNewMessage) { if (haveNewMessage) {
if (!Bangle.MESSAGES.length) return goBack();
haveNewMessage = false; haveNewMessage = false;
let idx = Bangle.MESSAGES.findIndex(m => !m.handled); let idx = Bangle.MESSAGES.findIndex(m => !m.handled);
if (idx >= 0) { if (idx >= 0) {
@ -639,8 +640,8 @@ const checkForNewMessages = function(idleTime) {
const setBusy = function() { const setBusy = function() {
idle = false; idle = false;
if (timeouts.idleTimer) clearTimeout(timeouts.idleTimer); if (timeouts["idleTimer"]) clearTimeout(timeouts["idleTimer"]);
timeouts.idleTimer = undefined; timeouts["idleTimer"] = undefined;
}; };
const goBack = function(timedOut) { const goBack = function(timedOut) {
@ -655,7 +656,8 @@ const goBack = function(timedOut) {
if (!timedOut) Bangle.MESSAGES.forEach((m) => {if (!m.new) m.show = false;}); if (!timedOut) Bangle.MESSAGES.forEach((m) => {if (!m.new) m.show = false;});
require("messages").write(Bangle.MESSAGES); require("messages").write(Bangle.MESSAGES);
cleanup = _cleanup; cleanup = _cleanup;
Bangle.load(); cleanup();
Bangle.showClock();
} }
//console.log("backTo = ", backTo); //console.log("backTo = ", backTo);
switch (backTo) { switch (backTo) {
@ -669,21 +671,21 @@ const goBack = function(timedOut) {
else return showText(0); else return showText(0);
} }
} }
}; // function goBack }; // goBack
const newMessage = (type, msg) => { const newMessage = (type, msg) => {
filterMessages(); filterMessages();
// if (!previous.includes(active) && type != active) previous.push(active);
switch (type) { switch (type) {
case "text": case "text":
if (msg.t === "remove") { if (msg.t === "remove") {
let idx = Bangle.MESSAGES.findIndex(m => m.id === msg.id); let idx = Bangle.MESSAGES.findIndex(m => m.id === msg.id);
if (idx >= 0) Bangle.MESSAGES.splice(idx, 1); // remove 'remove' from Bangle.MESSAGES // if (idx >= 0) Bangle.MESSAGES.splice(idx, 1); // remove 'remove' from Bangle.MESSAGES
idx = Bangle.MESSAGES.findIndex(m => m.id === msg.id && m.t !== "remove"); // idx = Bangle.MESSAGES.findIndex(m => m.id === msg.id && m.t !== "remove");
if (active === "text" && buzzing && idx === msgIdx) require("messages").stopBuzz(); // if the message being viewed is removed stop buzzing
Bangle.MESSAGES = Bangle.MESSAGES.filter(m => m.id != msg.id); Bangle.MESSAGES = Bangle.MESSAGES.filter(m => m.id != msg.id);
if (active === "text" && buzzing && idx === msgIdx) require("messages").stopBuzz(); // if the message being viewed is removed stop buzzing
require("messages").write(Bangle.MESSAGES); // write removal to flash require("messages").write(Bangle.MESSAGES); // write removal to flash
if (active === "text") { if (active === "text") {
//if (!Bangle.MESSAGES.length) goBack();
if (idle) showText(msgIdx); // we are idle so updated messages right away if (idle) showText(msgIdx); // we are idle so updated messages right away
else haveNewMessage = true; // otherwise set new message flag and wait until idle else haveNewMessage = true; // otherwise set new message flag and wait until idle
} }
@ -704,7 +706,7 @@ const newMessage = (type, msg) => {
break; break;
case "call": case "call":
if (call && call.t === "remove") {call = undefined; goBack();} //if (call && call.t === "remove") {call = undefined; goBack();}
if (call) {setActive("call"); showCall(call);} if (call) {setActive("call"); showCall(call);}
break; break;
case "alarm": case "alarm":
@ -733,10 +735,10 @@ const filterMessages = function() {
}; };
const showMessage = function() { const showMessage = function() {
if (call) {setActive("call"); return showCall(call);} if (call) {setActive("call"); return showCall();}
else if (alarm) {setActive("alarm"); return showAlarm(alarm);} else if (alarm) {setActive("alarm"); return showAlarm();}
else if (map) {setActive("map"); return showMap(map);} else if (map) {setActive("map"); return showMap();}
else if (music) {setActive("music"); return showMusic(music);} else if (music) {setActive("music"); return showMusic();}
else { else {
idx = Bangle.MESSAGES.findIndex(m => !m.handled); idx = Bangle.MESSAGES.findIndex(m => !m.handled);
if (idx >= 0) { if (idx >= 0) {