forked from FOSS/BangleApps
messages Remove '.show' field, tidyup and fix .open if fast load not enabled
parent
8a4f5930a1
commit
1c7eb92ad5
|
@ -84,3 +84,4 @@
|
|||
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.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
|
||||
|
|
|
@ -72,10 +72,7 @@ var onMessagesModified = function(type,msg) {
|
|||
Bangle.on("message", onMessagesModified);
|
||||
|
||||
function saveMessages() {
|
||||
require("messages").write(MESSAGES.map(m => {
|
||||
delete m.show;
|
||||
return m;
|
||||
}));
|
||||
require("messages").write(MESSAGES);
|
||||
}
|
||||
E.on("kill", saveMessages);
|
||||
|
||||
|
@ -116,11 +113,12 @@ function showMapMessage(msg) {
|
|||
Bangle.setUI({mode:"updown", back: back}, back); // any input takes us back
|
||||
}
|
||||
|
||||
let updateLabelsInterval,
|
||||
music = {artist: "", album: "", title: ""}; // defaults, so e.g. msg.title.length doesn't error
|
||||
let updateLabelsInterval;
|
||||
|
||||
function showMusicMessage(msg) {
|
||||
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";
|
||||
var trackScrollOffset = 0;
|
||||
var artistScrollOffset = 0;
|
||||
|
@ -349,6 +347,7 @@ function showMessage(msgid) {
|
|||
clockIfNoMsg : bool
|
||||
clockIfAllRead : bool
|
||||
showMsgIfUnread : bool
|
||||
openMusic : bool // open music if it's playing
|
||||
}
|
||||
*/
|
||||
function checkMessages(options) {
|
||||
|
@ -364,12 +363,8 @@ function checkMessages(options) {
|
|||
}
|
||||
// we have >0 messages
|
||||
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 ((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
|
||||
showMessage(newMessages[0].id);
|
||||
// buzz after showMessage, so being busy during layout doesn't affect the buzz pattern
|
||||
|
@ -382,8 +377,8 @@ function checkMessages(options) {
|
|||
}
|
||||
return;
|
||||
}
|
||||
// no new messages: show playing music? (only if we have playing music to show)
|
||||
if (options.openMusic && MESSAGES.some(m=>m.id=="music" && m.track && m.state=="play"))
|
||||
// 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") || m.state=="show")))
|
||||
return showMessage('music');
|
||||
// no new messages - go to clock?
|
||||
if (options.clockIfAllRead && newMessages.length==0)
|
||||
|
@ -449,7 +444,9 @@ setTimeout(() => {
|
|||
if (!isFinite(settings.unreadTimeout)) settings.unreadTimeout=60;
|
||||
if (settings.unreadTimeout)
|
||||
unreadTimeout = setTimeout(load, settings.unreadTimeout*1000);
|
||||
// only openMusic on launch if music is new
|
||||
var newMusic = MESSAGES.some(m => m.id === "music" && m.new);
|
||||
checkMessages({ clockIfNoMsg: 0, clockIfAllRead: 0, showMsgIfUnread: 1, openMusic: newMusic && settings.openMusic });
|
||||
// only openMusic on launch if music is new, or state=="show" (set by messagesmusic)
|
||||
var musicMsg = MESSAGES.find(m => m.id === "music");
|
||||
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
|
||||
|
|
|
@ -1,3 +1 @@
|
|||
(function() {
|
||||
Bangle.on("message", (type, msg) => require("messagegui").listener(type, msg));
|
||||
})();
|
|
@ -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
|
||||
*/
|
||||
|
@ -26,11 +34,8 @@ exports.listener = function(type, msg) {
|
|||
if (Bangle.CLOCK && msg.state && msg.title && appSettings.openMusic) loadMessages = true;
|
||||
else return;
|
||||
}
|
||||
if (Bangle.load === load || !Bangle.uiRemove) {
|
||||
if (loadWillReset()) {
|
||||
// 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);
|
||||
} else {
|
||||
if (!Bangle.MESSAGES) Bangle.MESSAGES = [];
|
||||
|
@ -79,11 +84,17 @@ exports.listener = function(type, msg) {
|
|||
* @param {object} msg
|
||||
*/
|
||||
exports.open = function(msg) {
|
||||
if (msg && msg.id && !msg.show) {
|
||||
msg.show = 1;
|
||||
if (Bangle.load === load) {
|
||||
// no fast loading: store message to load in flash
|
||||
if (msg && msg.id) {
|
||||
// force a display by setting it as new and ensuring it ends up at the beginning of messages list
|
||||
msg.new = 1;
|
||||
if (loadWillReset()) {
|
||||
// no fast loading: store message to load in flash - `msg` will be put in first
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
"id": "messagegui",
|
||||
"name": "Message UI",
|
||||
"shortName": "Messages",
|
||||
"version": "0.61",
|
||||
"version": "0.62",
|
||||
"description": "Default app to display notifications from iOS and Gadgetbridge/Android",
|
||||
"icon": "app.png",
|
||||
"type": "app",
|
||||
|
|
|
@ -72,7 +72,7 @@ exports.apply = function(event, messages) {
|
|||
messages.splice(mIdx, 1);
|
||||
} else if (event.t==="add") {
|
||||
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") {
|
||||
if (mIdx>=0) messages[mIdx] = Object.assign(messages[mIdx], event);
|
||||
else messages.unshift(event);
|
||||
|
|
|
@ -3,3 +3,4 @@
|
|||
0.03: Use the new messages library
|
||||
0.04: Fix dependency on messages library
|
||||
Fix loading message UI
|
||||
0.05: Ensure we don't clear artist info
|
||||
|
|
|
@ -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}));
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
{
|
||||
"id": "messagesmusic",
|
||||
"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",
|
||||
"icon":"app.png",
|
||||
"type": "app",
|
||||
|
|
Loading…
Reference in New Issue