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
|
Move widget to widmessage
|
||||||
0.56: Fix handling of music messages
|
0.56: Fix handling of music messages
|
||||||
0.57: Fix "unread Timeout" = off (previously defaulted to 60s)
|
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;
|
var unreadTimeout;
|
||||||
/// List of all our messages
|
/// List of all our messages
|
||||||
var MESSAGES = require("messages").getMessages();
|
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) {
|
var onMessagesModified = function(type,msg) {
|
||||||
if (msg.handled) return;
|
if (msg.handled) return;
|
||||||
|
@ -105,7 +110,6 @@ function showMapMessage(msg) {
|
||||||
layout.render();
|
layout.render();
|
||||||
function back() { // mark as not new and return to menu
|
function back() { // mark as not new and return to menu
|
||||||
msg.new = false;
|
msg.new = false;
|
||||||
saveMessages();
|
|
||||||
layout = undefined;
|
layout = undefined;
|
||||||
checkMessages({clockIfNoMsg:1,clockIfAllRead:1,showMsgIfUnread:1,openMusic:0});
|
checkMessages({clockIfNoMsg:1,clockIfAllRead:1,showMsgIfUnread:1,openMusic:0});
|
||||||
}
|
}
|
||||||
|
@ -140,7 +144,6 @@ function showMusicMessage(msg) {
|
||||||
openMusic = false;
|
openMusic = false;
|
||||||
var wasNew = msg.new;
|
var wasNew = msg.new;
|
||||||
msg.new = false;
|
msg.new = false;
|
||||||
saveMessages();
|
|
||||||
layout = undefined;
|
layout = undefined;
|
||||||
if (wasNew) checkMessages({clockIfNoMsg:1,clockIfAllRead:1,showMsgIfUnread:0,openMusic:0});
|
if (wasNew) checkMessages({clockIfNoMsg:1,clockIfAllRead:1,showMsgIfUnread:0,openMusic:0});
|
||||||
else checkMessages({clockIfNoMsg:0,clockIfAllRead:0,showMsgIfUnread:0,openMusic:0});
|
else checkMessages({clockIfNoMsg:0,clockIfAllRead:0,showMsgIfUnread:0,openMusic:0});
|
||||||
|
@ -223,24 +226,20 @@ function showMessageSettings(msg) {
|
||||||
},
|
},
|
||||||
/*LANG*/"Delete" : () => {
|
/*LANG*/"Delete" : () => {
|
||||||
MESSAGES = MESSAGES.filter(m=>m.id!=msg.id);
|
MESSAGES = MESSAGES.filter(m=>m.id!=msg.id);
|
||||||
saveMessages();
|
|
||||||
checkMessages({clockIfNoMsg:0,clockIfAllRead:0,showMsgIfUnread:0,openMusic:0});
|
checkMessages({clockIfNoMsg:0,clockIfAllRead:0,showMsgIfUnread:0,openMusic:0});
|
||||||
},
|
},
|
||||||
/*LANG*/"Mark Unread" : () => {
|
/*LANG*/"Mark Unread" : () => {
|
||||||
msg.new = true;
|
msg.new = true;
|
||||||
saveMessages();
|
|
||||||
checkMessages({clockIfNoMsg:0,clockIfAllRead:0,showMsgIfUnread:0,openMusic:0});
|
checkMessages({clockIfNoMsg:0,clockIfAllRead:0,showMsgIfUnread:0,openMusic:0});
|
||||||
},
|
},
|
||||||
/*LANG*/"Mark all read" : () => {
|
/*LANG*/"Mark all read" : () => {
|
||||||
MESSAGES.forEach(msg => msg.new = false);
|
MESSAGES.forEach(msg => msg.new = false);
|
||||||
saveMessages();
|
|
||||||
checkMessages({clockIfNoMsg:0,clockIfAllRead:0,showMsgIfUnread:0,openMusic:0});
|
checkMessages({clockIfNoMsg:0,clockIfAllRead:0,showMsgIfUnread:0,openMusic:0});
|
||||||
},
|
},
|
||||||
/*LANG*/"Delete all messages" : () => {
|
/*LANG*/"Delete all messages" : () => {
|
||||||
E.showPrompt(/*LANG*/"Are you sure?", {title:/*LANG*/"Delete All Messages"}).then(isYes => {
|
E.showPrompt(/*LANG*/"Are you sure?", {title:/*LANG*/"Delete All Messages"}).then(isYes => {
|
||||||
if (isYes) {
|
if (isYes) {
|
||||||
MESSAGES = [];
|
MESSAGES = [];
|
||||||
saveMessages();
|
|
||||||
}
|
}
|
||||||
checkMessages({clockIfNoMsg:0,clockIfAllRead:0,showMsgIfUnread:0,openMusic:0});
|
checkMessages({clockIfNoMsg:0,clockIfAllRead:0,showMsgIfUnread:0,openMusic:0});
|
||||||
});
|
});
|
||||||
|
@ -295,7 +294,7 @@ function showMessage(msgid) {
|
||||||
}
|
}
|
||||||
function goBack() {
|
function goBack() {
|
||||||
layout = undefined;
|
layout = undefined;
|
||||||
msg.new = false; saveMessages(); // read mail
|
msg.new = false; // read mail
|
||||||
cancelReloadTimeout(); // don't auto-reload to clock now
|
cancelReloadTimeout(); // don't auto-reload to clock now
|
||||||
checkMessages({clockIfNoMsg:1,clockIfAllRead:0,showMsgIfUnread:0,openMusic:openMusic});
|
checkMessages({clockIfNoMsg:1,clockIfAllRead:0,showMsgIfUnread:0,openMusic:openMusic});
|
||||||
}
|
}
|
||||||
|
@ -303,7 +302,7 @@ function showMessage(msgid) {
|
||||||
];
|
];
|
||||||
if (msg.positive) {
|
if (msg.positive) {
|
||||||
buttons.push({type:"btn", src:atob("GRSBAAAAAYAAAcAAAeAAAfAAAfAAAfAAAfAAAfAAAfBgAfA4AfAeAfAPgfAD4fAA+fAAP/AAD/AAA/AAAPAAADAAAA=="), cb:()=>{
|
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
|
cancelReloadTimeout(); // don't auto-reload to clock now
|
||||||
Bangle.messageResponse(msg,true);
|
Bangle.messageResponse(msg,true);
|
||||||
checkMessages({clockIfNoMsg:1,clockIfAllRead:1,showMsgIfUnread:1,openMusic:openMusic});
|
checkMessages({clockIfNoMsg:1,clockIfAllRead:1,showMsgIfUnread:1,openMusic:openMusic});
|
||||||
|
@ -312,7 +311,7 @@ function showMessage(msgid) {
|
||||||
if (msg.negative) {
|
if (msg.negative) {
|
||||||
if (buttons.length) buttons.push({width:32}); // nasty hack...
|
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:()=>{
|
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
|
cancelReloadTimeout(); // don't auto-reload to clock now
|
||||||
Bangle.messageResponse(msg,false);
|
Bangle.messageResponse(msg,false);
|
||||||
checkMessages({clockIfNoMsg:1,clockIfAllRead:1,showMsgIfUnread:1,openMusic:openMusic});
|
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;
|
if (Bangle.CLOCK && msg.state && msg.title && appSettings.openMusic) loadMessages = true;
|
||||||
else return;
|
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;
|
msg.handled = true;
|
||||||
if ((msg.t!=="add" || !msg.new) && (type!=="music")) { // music always has t:"modify"
|
if ((msg.t!=="add" || !msg.new) && (type!=="music")) { // music always has t:"modify"
|
||||||
|
saveToFlash();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,7 +48,11 @@ exports.listener = function(type, msg) {
|
||||||
exports.messageTimeout = setTimeout(function() {
|
exports.messageTimeout = setTimeout(function() {
|
||||||
delete exports.messageTimeout;
|
delete exports.messageTimeout;
|
||||||
if (type!=="music") {
|
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) {
|
if (!quiet && unlockWatch) {
|
||||||
Bangle.setLocked(false);
|
Bangle.setLocked(false);
|
||||||
Bangle.setLCDPower(1); // turn screen on
|
Bangle.setLCDPower(1); // turn screen on
|
||||||
|
@ -51,9 +68,11 @@ exports.listener = function(type, msg) {
|
||||||
*/
|
*/
|
||||||
exports.open = function(msg) {
|
exports.open = function(msg) {
|
||||||
if (msg && msg.id && !msg.show) {
|
if (msg && msg.id && !msg.show) {
|
||||||
// store which message to load
|
|
||||||
msg.show = 1;
|
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");
|
Bangle.load((msg && msg.new && msg.id!=="music") ? "messagegui.new.js" : "messagegui.app.js");
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"id": "messagegui",
|
"id": "messagegui",
|
||||||
"name": "Message UI",
|
"name": "Message UI",
|
||||||
"version": "0.57",
|
"version": "0.58",
|
||||||
"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",
|
||||||
|
|
Loading…
Reference in New Issue