Skip to content

Commit 2b6c6b6

Browse files
authored
Merge pull request #2373 from rigrig/messagegui-fast-load
messagegui: don't write messages to flash quite as often
2 parents 1bd3803 + 8e54894 commit 2b6c6b6

File tree

4 files changed

+34
-14
lines changed

4 files changed

+34
-14
lines changed

apps/messagegui/ChangeLog

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,5 @@
7979
Move widget to widmessage
8080
0.56: Fix handling of music messages
8181
0.57: Fix "unread Timeout" = off (previously defaulted to 60s)
82+
0.58: Fast load messages without writing to flash
83+
Don't write messages to flash until the app closes

apps/messagegui/app.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ to the clock. */
4848
var unreadTimeout;
4949
/// List of all our messages
5050
var MESSAGES = require("messages").getMessages();
51+
if (Bangle.MESSAGES) {
52+
// fast loading messages
53+
Bangle.MESSAGES.forEach(m => require("messages").apply(m, MESSAGES));
54+
delete Bangle.MESSAGES;
55+
}
5156

5257
var onMessagesModified = function(type,msg) {
5358
if (msg.handled) return;
@@ -105,7 +110,6 @@ function showMapMessage(msg) {
105110
layout.render();
106111
function back() { // mark as not new and return to menu
107112
msg.new = false;
108-
saveMessages();
109113
layout = undefined;
110114
checkMessages({clockIfNoMsg:1,clockIfAllRead:1,showMsgIfUnread:1,openMusic:0});
111115
}
@@ -140,7 +144,6 @@ function showMusicMessage(msg) {
140144
openMusic = false;
141145
var wasNew = msg.new;
142146
msg.new = false;
143-
saveMessages();
144147
layout = undefined;
145148
if (wasNew) checkMessages({clockIfNoMsg:1,clockIfAllRead:1,showMsgIfUnread:0,openMusic:0});
146149
else checkMessages({clockIfNoMsg:0,clockIfAllRead:0,showMsgIfUnread:0,openMusic:0});
@@ -223,24 +226,20 @@ function showMessageSettings(msg) {
223226
},
224227
/*LANG*/"Delete" : () => {
225228
MESSAGES = MESSAGES.filter(m=>m.id!=msg.id);
226-
saveMessages();
227229
checkMessages({clockIfNoMsg:0,clockIfAllRead:0,showMsgIfUnread:0,openMusic:0});
228230
},
229231
/*LANG*/"Mark Unread" : () => {
230232
msg.new = true;
231-
saveMessages();
232233
checkMessages({clockIfNoMsg:0,clockIfAllRead:0,showMsgIfUnread:0,openMusic:0});
233234
},
234235
/*LANG*/"Mark all read" : () => {
235236
MESSAGES.forEach(msg => msg.new = false);
236-
saveMessages();
237237
checkMessages({clockIfNoMsg:0,clockIfAllRead:0,showMsgIfUnread:0,openMusic:0});
238238
},
239239
/*LANG*/"Delete all messages" : () => {
240240
E.showPrompt(/*LANG*/"Are you sure?", {title:/*LANG*/"Delete All Messages"}).then(isYes => {
241241
if (isYes) {
242242
MESSAGES = [];
243-
saveMessages();
244243
}
245244
checkMessages({clockIfNoMsg:0,clockIfAllRead:0,showMsgIfUnread:0,openMusic:0});
246245
});
@@ -295,15 +294,15 @@ function showMessage(msgid) {
295294
}
296295
function goBack() {
297296
layout = undefined;
298-
msg.new = false; saveMessages(); // read mail
297+
msg.new = false; // read mail
299298
cancelReloadTimeout(); // don't auto-reload to clock now
300299
checkMessages({clockIfNoMsg:1,clockIfAllRead:0,showMsgIfUnread:0,openMusic:openMusic});
301300
}
302301
var buttons = [
303302
];
304303
if (msg.positive) {
305304
buttons.push({type:"btn", src:atob("GRSBAAAAAYAAAcAAAeAAAfAAAfAAAfAAAfAAAfAAAfBgAfA4AfAeAfAPgfAD4fAA+fAAP/AAD/AAA/AAAPAAADAAAA=="), cb:()=>{
306-
msg.new = false; saveMessages();
305+
msg.new = false;
307306
cancelReloadTimeout(); // don't auto-reload to clock now
308307
Bangle.messageResponse(msg,true);
309308
checkMessages({clockIfNoMsg:1,clockIfAllRead:1,showMsgIfUnread:1,openMusic:openMusic});
@@ -312,7 +311,7 @@ function showMessage(msgid) {
312311
if (msg.negative) {
313312
if (buttons.length) buttons.push({width:32}); // nasty hack...
314313
buttons.push({type:"btn", src:atob("FhaBADAAMeAB78AP/4B/fwP4/h/B/P4D//AH/4AP/AAf4AB/gAP/AB/+AP/8B/P4P4fx/A/v4B//AD94AHjAAMA="), cb:()=>{
315-
msg.new = false; saveMessages();
314+
msg.new = false;
316315
cancelReloadTimeout(); // don't auto-reload to clock now
317316
Bangle.messageResponse(msg,false);
318317
checkMessages({clockIfNoMsg:1,clockIfAllRead:1,showMsgIfUnread:1,openMusic:openMusic});

apps/messagegui/lib.js

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,22 @@ exports.listener = function(type, msg) {
1818
if (Bangle.CLOCK && msg.state && msg.title && appSettings.openMusic) loadMessages = true;
1919
else return;
2020
}
21-
require("messages").save(msg);
21+
if (Bangle.load === load) {
22+
// no fast loading: store message to flash
23+
require("messages").save(msg);
24+
} else {
25+
if (!Bangle.MESSAGES) Bangle.MESSAGES = [];
26+
Bangle.MESSAGES.push(msg);
27+
}
28+
const saveToFlash = () => {
29+
// save messages from RAM to flash after all, if we decide not to launch app
30+
if (!Bangle.MESSAGES) return;
31+
Bangle.MESSAGES.forEach(m => require("messages").save(m));
32+
delete Bangle.MESSAGES;
33+
}
2234
msg.handled = true;
2335
if ((msg.t!=="add" || !msg.new) && (type!=="music")) { // music always has t:"modify"
36+
saveToFlash();
2437
return;
2538
}
2639

@@ -35,7 +48,11 @@ exports.listener = function(type, msg) {
3548
exports.messageTimeout = setTimeout(function() {
3649
delete exports.messageTimeout;
3750
if (type!=="music") {
38-
if (!loadMessages) return require("messages").buzz(msg.src); // no opening the app, just buzz
51+
if (!loadMessages) {
52+
// not opening the app, just buzz
53+
saveToFlash();
54+
return require("messages").buzz(msg.src);
55+
}
3956
if (!quiet && unlockWatch) {
4057
Bangle.setLocked(false);
4158
Bangle.setLCDPower(1); // turn screen on
@@ -51,9 +68,11 @@ exports.listener = function(type, msg) {
5168
*/
5269
exports.open = function(msg) {
5370
if (msg && msg.id && !msg.show) {
54-
// store which message to load
5571
msg.show = 1;
56-
require("messages").save(msg, {force: 1});
72+
if (Bangle.load === load) {
73+
// no fast loading: store message to load in flash
74+
require("messages").save(msg, {force: 1});
75+
}
5776
}
5877

5978
Bangle.load((msg && msg.new && msg.id!=="music") ? "messagegui.new.js" : "messagegui.app.js");

apps/messagegui/metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "messagegui",
33
"name": "Message UI",
4-
"version": "0.57",
4+
"version": "0.58",
55
"description": "Default app to display notifications from iOS and Gadgetbridge/Android",
66
"icon": "app.png",
77
"type": "app",

0 commit comments

Comments
 (0)