1
0
Fork 0

messages Remove '.show' field, tidyup and fix .open if fast load not enabled

master
Gordon Williams 2022-12-15 10:34:40 +00:00
parent 8a4f5930a1
commit 1c7eb92ad5
9 changed files with 43 additions and 33 deletions

View File

@ -84,3 +84,4 @@
0.59: Ensure we do write messages if messages app can't be fast loaded (see #2373) 0.59: Ensure we do write messages if messages app can't be fast loaded (see #2373)
0.60: Fix saving of removal messages if UI not open 0.60: Fix saving of removal messages if UI not open
0.61: Fix regression where loading into messages app stops back from working (#2398) 0.61: Fix regression where loading into messages app stops back from working (#2398)
0.62: Remove '.show' field, tidyup and fix .open if fast load not enabled

View File

@ -72,10 +72,7 @@ var onMessagesModified = function(type,msg) {
Bangle.on("message", onMessagesModified); Bangle.on("message", onMessagesModified);
function saveMessages() { function saveMessages() {
require("messages").write(MESSAGES.map(m => { require("messages").write(MESSAGES);
delete m.show;
return m;
}));
} }
E.on("kill", saveMessages); E.on("kill", saveMessages);
@ -116,11 +113,12 @@ function showMapMessage(msg) {
Bangle.setUI({mode:"updown", back: back}, back); // any input takes us back Bangle.setUI({mode:"updown", back: back}, back); // any input takes us back
} }
let updateLabelsInterval, let updateLabelsInterval;
music = {artist: "", album: "", title: ""}; // defaults, so e.g. msg.title.length doesn't error
function showMusicMessage(msg) { function showMusicMessage(msg) {
active = "music"; active = "music";
msg = Object.assign(music, msg); // combine+remember "musicinfo" and "musicstate" messages // defaults, so e.g. msg.xyz.length doesn't error. `msg` should contain up to date info
msg = Object.assign({artist: "", album: "", track: "Music"}, msg);
openMusic = msg.state=="play"; openMusic = msg.state=="play";
var trackScrollOffset = 0; var trackScrollOffset = 0;
var artistScrollOffset = 0; var artistScrollOffset = 0;
@ -349,6 +347,7 @@ function showMessage(msgid) {
clockIfNoMsg : bool clockIfNoMsg : bool
clockIfAllRead : bool clockIfAllRead : bool
showMsgIfUnread : bool showMsgIfUnread : bool
openMusic : bool // open music if it's playing
} }
*/ */
function checkMessages(options) { function checkMessages(options) {
@ -364,12 +363,8 @@ function checkMessages(options) {
} }
// we have >0 messages // we have >0 messages
var newMessages = MESSAGES.filter(m=>m.new&&m.id!="music"); var newMessages = MESSAGES.filter(m=>m.new&&m.id!="music");
var toShow = MESSAGES.find(m=>m.show);
if (toShow) {
newMessages.unshift(toShow);
}
// If we have a new message, show it // If we have a new message, show it
if ((toShow||options.showMsgIfUnread) && newMessages.length) { if (options.showMsgIfUnread && newMessages.length) {
delete newMessages[0].show; // stop us getting stuck here if we're called a second time delete newMessages[0].show; // stop us getting stuck here if we're called a second time
showMessage(newMessages[0].id); showMessage(newMessages[0].id);
// buzz after showMessage, so being busy during layout doesn't affect the buzz pattern // buzz after showMessage, so being busy during layout doesn't affect the buzz pattern
@ -382,8 +377,8 @@ function checkMessages(options) {
} }
return; return;
} }
// no new messages: show playing music? (only if we have playing music to show) // no new messages: show playing music? Only if we have playing music, or state=="show" (set by messagesmusic)
if (options.openMusic && MESSAGES.some(m=>m.id=="music" && m.track && m.state=="play")) if (options.openMusic && MESSAGES.some(m=>m.id=="music" && ((m.track && m.state=="play") || m.state=="show")))
return showMessage('music'); return showMessage('music');
// no new messages - go to clock? // no new messages - go to clock?
if (options.clockIfAllRead && newMessages.length==0) if (options.clockIfAllRead && newMessages.length==0)
@ -449,7 +444,9 @@ setTimeout(() => {
if (!isFinite(settings.unreadTimeout)) settings.unreadTimeout=60; if (!isFinite(settings.unreadTimeout)) settings.unreadTimeout=60;
if (settings.unreadTimeout) if (settings.unreadTimeout)
unreadTimeout = setTimeout(load, settings.unreadTimeout*1000); unreadTimeout = setTimeout(load, settings.unreadTimeout*1000);
// only openMusic on launch if music is new // only openMusic on launch if music is new, or state=="show" (set by messagesmusic)
var newMusic = MESSAGES.some(m => m.id === "music" && m.new); var musicMsg = MESSAGES.find(m => m.id === "music");
checkMessages({ clockIfNoMsg: 0, clockIfAllRead: 0, showMsgIfUnread: 1, openMusic: newMusic && settings.openMusic }); checkMessages({
clockIfNoMsg: 0, clockIfAllRead: 0, showMsgIfUnread: 1,
openMusic: ((musicMsg&&musicMsg.new) && settings.openMusic) || (musicMsg&&musicMsg.state=="show") });
}, 10); // if checkMessages wants to 'load', do that }, 10); // if checkMessages wants to 'load', do that

View File

@ -1,3 +1 @@
(function() { Bangle.on("message", (type, msg) => require("messagegui").listener(type, msg));
Bangle.on("message", (type, msg) => require("messagegui").listener(type, msg));
})();

View File

@ -1,3 +1,11 @@
// Will calling Bangle.load reset everything? if false, we fast load
function loadWillReset() {
return Bangle.load === load || !Bangle.uiRemove;
/* FIXME: Maybe we need a better way of deciding if an app will
be fast loaded than just hard-coding a Bangle.uiRemove check.
Bangle.load could return a bool (as the load doesn't happen immediately). */
}
/** /**
* Listener set up in boot.js, calls into here to keep boot.js short * Listener set up in boot.js, calls into here to keep boot.js short
*/ */
@ -26,11 +34,8 @@ exports.listener = function(type, msg) {
if (Bangle.CLOCK && msg.state && msg.title && appSettings.openMusic) loadMessages = true; if (Bangle.CLOCK && msg.state && msg.title && appSettings.openMusic) loadMessages = true;
else return; else return;
} }
if (Bangle.load === load || !Bangle.uiRemove) { if (loadWillReset()) {
// no fast loading: store message to flash // no fast loading: store message to flash
/* FIXME: Maybe we need a better way of deciding if an app will
be fast loaded than just hard-coding a Bangle.uiRemove check.
Bangle.load could return a bool (as the load doesn't happen immediately). */
require("messages").save(msg); require("messages").save(msg);
} else { } else {
if (!Bangle.MESSAGES) Bangle.MESSAGES = []; if (!Bangle.MESSAGES) Bangle.MESSAGES = [];
@ -79,11 +84,17 @@ exports.listener = function(type, msg) {
* @param {object} msg * @param {object} msg
*/ */
exports.open = function(msg) { exports.open = function(msg) {
if (msg && msg.id && !msg.show) { if (msg && msg.id) {
msg.show = 1; // force a display by setting it as new and ensuring it ends up at the beginning of messages list
if (Bangle.load === load) { msg.new = 1;
// no fast loading: store message to load in flash if (loadWillReset()) {
// no fast loading: store message to load in flash - `msg` will be put in first
require("messages").save(msg, {force: 1}); require("messages").save(msg, {force: 1});
} else {
// fast load - putting it at the end of Bangle.MESSAGES ensures it goes at the start of messages list
if (!Bangle.MESSAGES) Bangle.MESSAGES=[];
Bangle.MESSAGES = Bangle.MESSAGES.filter(m => m.id!=msg.id)
Bangle.MESSAGES.push(msg); // putting at the
} }
} }

View File

@ -2,7 +2,7 @@
"id": "messagegui", "id": "messagegui",
"name": "Message UI", "name": "Message UI",
"shortName": "Messages", "shortName": "Messages",
"version": "0.61", "version": "0.62",
"description": "Default app to display notifications from iOS and Gadgetbridge/Android", "description": "Default app to display notifications from iOS and Gadgetbridge/Android",
"icon": "app.png", "icon": "app.png",
"type": "app", "type": "app",

View File

@ -72,7 +72,7 @@ exports.apply = function(event, messages) {
messages.splice(mIdx, 1); messages.splice(mIdx, 1);
} else if (event.t==="add") { } else if (event.t==="add") {
if (mIdx>=0) messages.splice(mIdx, 1); // duplicate ID! erase previous version if (mIdx>=0) messages.splice(mIdx, 1); // duplicate ID! erase previous version
messages.unshift(event); messages.unshift(event); // add at the beginning
} else if (event.t==="modify") { } else if (event.t==="modify") {
if (mIdx>=0) messages[mIdx] = Object.assign(messages[mIdx], event); if (mIdx>=0) messages[mIdx] = Object.assign(messages[mIdx], event);
else messages.unshift(event); else messages.unshift(event);

View File

@ -2,4 +2,5 @@
0.02: Remove one line of code that didn't do anything other than in some instances hinder the function of the app. 0.02: Remove one line of code that didn't do anything other than in some instances hinder the function of the app.
0.03: Use the new messages library 0.03: Use the new messages library
0.04: Fix dependency on messages library 0.04: Fix dependency on messages library
Fix loading message UI Fix loading message UI
0.05: Ensure we don't clear artist info

View File

@ -1 +1,2 @@
setTimeout(()=>require('messages').openGUI({"t":"add","artist":" ","album":" ","track":" ","dur":0,"c":-1,"n":-1,"id":"music","title":"Music","state":"play","new":true})); // don't define artist/etc here so we don't wipe them out of memory if they were stored from before
setTimeout(()=>require('messages').openGUI({"t":"add","id":"music","state":"show","new":true}));

View File

@ -1,7 +1,8 @@
{ {
"id": "messagesmusic", "id": "messagesmusic",
"name":"Messages Music", "name":"Messages Music",
"version":"0.04", "shortName": "Music",
"version":"0.05",
"description": "Uses Messages library to push a music message which in turn displays Messages app music controls", "description": "Uses Messages library to push a music message which in turn displays Messages app music controls",
"icon":"app.png", "icon":"app.png",
"type": "app", "type": "app",