mirror of https://github.com/espruino/BangleApps
Merge pull request #2373 from rigrig/messagegui-fast-load
messagegui: don't write messages to flash quite as oftenpull/2377/head^2
commit
2b6c6b69aa
|
@ -79,3 +79,5 @@
|
|||
Move widget to widmessage
|
||||
0.56: Fix handling of music messages
|
||||
0.57: Fix "unread Timeout" = off (previously defaulted to 60s)
|
||||
0.58: Fast load messages without writing to flash
|
||||
Don't write messages to flash until the app closes
|
||||
|
|
|
@ -48,6 +48,11 @@ to the clock. */
|
|||
var unreadTimeout;
|
||||
/// List of all our messages
|
||||
var MESSAGES = require("messages").getMessages();
|
||||
if (Bangle.MESSAGES) {
|
||||
// fast loading messages
|
||||
Bangle.MESSAGES.forEach(m => require("messages").apply(m, MESSAGES));
|
||||
delete Bangle.MESSAGES;
|
||||
}
|
||||
|
||||
var onMessagesModified = function(type,msg) {
|
||||
if (msg.handled) return;
|
||||
|
@ -105,7 +110,6 @@ function showMapMessage(msg) {
|
|||
layout.render();
|
||||
function back() { // mark as not new and return to menu
|
||||
msg.new = false;
|
||||
saveMessages();
|
||||
layout = undefined;
|
||||
checkMessages({clockIfNoMsg:1,clockIfAllRead:1,showMsgIfUnread:1,openMusic:0});
|
||||
}
|
||||
|
@ -140,7 +144,6 @@ function showMusicMessage(msg) {
|
|||
openMusic = false;
|
||||
var wasNew = msg.new;
|
||||
msg.new = false;
|
||||
saveMessages();
|
||||
layout = undefined;
|
||||
if (wasNew) checkMessages({clockIfNoMsg:1,clockIfAllRead:1,showMsgIfUnread:0,openMusic:0});
|
||||
else checkMessages({clockIfNoMsg:0,clockIfAllRead:0,showMsgIfUnread:0,openMusic:0});
|
||||
|
@ -223,24 +226,20 @@ function showMessageSettings(msg) {
|
|||
},
|
||||
/*LANG*/"Delete" : () => {
|
||||
MESSAGES = MESSAGES.filter(m=>m.id!=msg.id);
|
||||
saveMessages();
|
||||
checkMessages({clockIfNoMsg:0,clockIfAllRead:0,showMsgIfUnread:0,openMusic:0});
|
||||
},
|
||||
/*LANG*/"Mark Unread" : () => {
|
||||
msg.new = true;
|
||||
saveMessages();
|
||||
checkMessages({clockIfNoMsg:0,clockIfAllRead:0,showMsgIfUnread:0,openMusic:0});
|
||||
},
|
||||
/*LANG*/"Mark all read" : () => {
|
||||
MESSAGES.forEach(msg => msg.new = false);
|
||||
saveMessages();
|
||||
checkMessages({clockIfNoMsg:0,clockIfAllRead:0,showMsgIfUnread:0,openMusic:0});
|
||||
},
|
||||
/*LANG*/"Delete all messages" : () => {
|
||||
E.showPrompt(/*LANG*/"Are you sure?", {title:/*LANG*/"Delete All Messages"}).then(isYes => {
|
||||
if (isYes) {
|
||||
MESSAGES = [];
|
||||
saveMessages();
|
||||
}
|
||||
checkMessages({clockIfNoMsg:0,clockIfAllRead:0,showMsgIfUnread:0,openMusic:0});
|
||||
});
|
||||
|
@ -295,7 +294,7 @@ function showMessage(msgid) {
|
|||
}
|
||||
function goBack() {
|
||||
layout = undefined;
|
||||
msg.new = false; saveMessages(); // read mail
|
||||
msg.new = false; // read mail
|
||||
cancelReloadTimeout(); // don't auto-reload to clock now
|
||||
checkMessages({clockIfNoMsg:1,clockIfAllRead:0,showMsgIfUnread:0,openMusic:openMusic});
|
||||
}
|
||||
|
@ -303,7 +302,7 @@ function showMessage(msgid) {
|
|||
];
|
||||
if (msg.positive) {
|
||||
buttons.push({type:"btn", src:atob("GRSBAAAAAYAAAcAAAeAAAfAAAfAAAfAAAfAAAfAAAfBgAfA4AfAeAfAPgfAD4fAA+fAAP/AAD/AAA/AAAPAAADAAAA=="), cb:()=>{
|
||||
msg.new = false; saveMessages();
|
||||
msg.new = false;
|
||||
cancelReloadTimeout(); // don't auto-reload to clock now
|
||||
Bangle.messageResponse(msg,true);
|
||||
checkMessages({clockIfNoMsg:1,clockIfAllRead:1,showMsgIfUnread:1,openMusic:openMusic});
|
||||
|
@ -312,7 +311,7 @@ function showMessage(msgid) {
|
|||
if (msg.negative) {
|
||||
if (buttons.length) buttons.push({width:32}); // nasty hack...
|
||||
buttons.push({type:"btn", src:atob("FhaBADAAMeAB78AP/4B/fwP4/h/B/P4D//AH/4AP/AAf4AB/gAP/AB/+AP/8B/P4P4fx/A/v4B//AD94AHjAAMA="), cb:()=>{
|
||||
msg.new = false; saveMessages();
|
||||
msg.new = false;
|
||||
cancelReloadTimeout(); // don't auto-reload to clock now
|
||||
Bangle.messageResponse(msg,false);
|
||||
checkMessages({clockIfNoMsg:1,clockIfAllRead:1,showMsgIfUnread:1,openMusic:openMusic});
|
||||
|
|
|
@ -18,9 +18,22 @@ exports.listener = function(type, msg) {
|
|||
if (Bangle.CLOCK && msg.state && msg.title && appSettings.openMusic) loadMessages = true;
|
||||
else return;
|
||||
}
|
||||
require("messages").save(msg);
|
||||
if (Bangle.load === load) {
|
||||
// no fast loading: store message to flash
|
||||
require("messages").save(msg);
|
||||
} else {
|
||||
if (!Bangle.MESSAGES) Bangle.MESSAGES = [];
|
||||
Bangle.MESSAGES.push(msg);
|
||||
}
|
||||
const saveToFlash = () => {
|
||||
// save messages from RAM to flash after all, if we decide not to launch app
|
||||
if (!Bangle.MESSAGES) return;
|
||||
Bangle.MESSAGES.forEach(m => require("messages").save(m));
|
||||
delete Bangle.MESSAGES;
|
||||
}
|
||||
msg.handled = true;
|
||||
if ((msg.t!=="add" || !msg.new) && (type!=="music")) { // music always has t:"modify"
|
||||
saveToFlash();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -35,7 +48,11 @@ exports.listener = function(type, msg) {
|
|||
exports.messageTimeout = setTimeout(function() {
|
||||
delete exports.messageTimeout;
|
||||
if (type!=="music") {
|
||||
if (!loadMessages) return require("messages").buzz(msg.src); // no opening the app, just buzz
|
||||
if (!loadMessages) {
|
||||
// not opening the app, just buzz
|
||||
saveToFlash();
|
||||
return require("messages").buzz(msg.src);
|
||||
}
|
||||
if (!quiet && unlockWatch) {
|
||||
Bangle.setLocked(false);
|
||||
Bangle.setLCDPower(1); // turn screen on
|
||||
|
@ -51,9 +68,11 @@ exports.listener = function(type, msg) {
|
|||
*/
|
||||
exports.open = function(msg) {
|
||||
if (msg && msg.id && !msg.show) {
|
||||
// store which message to load
|
||||
msg.show = 1;
|
||||
require("messages").save(msg, {force: 1});
|
||||
if (Bangle.load === load) {
|
||||
// no fast loading: store message to load in flash
|
||||
require("messages").save(msg, {force: 1});
|
||||
}
|
||||
}
|
||||
|
||||
Bangle.load((msg && msg.new && msg.id!=="music") ? "messagegui.new.js" : "messagegui.app.js");
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"id": "messagegui",
|
||||
"name": "Message UI",
|
||||
"version": "0.57",
|
||||
"version": "0.58",
|
||||
"description": "Default app to display notifications from iOS and Gadgetbridge/Android",
|
||||
"icon": "app.png",
|
||||
"type": "app",
|
||||
|
|
Loading…
Reference in New Issue