Skip to content

Commit

Permalink
messagelist: Fix app crashing when new message arrives
Browse files Browse the repository at this point in the history
new Layout(...) calls Bangle.setUI(), causing uiRemove() to be called
whenever a new messages arrives, instead of only when the app exits.

This fixes that by unsetting Bangle.uiRemove before calling Layout, and
restoring it afterwards.
  • Loading branch information
rigrig committed Aug 19, 2023
1 parent c9ba899 commit 4473acd
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
4 changes: 3 additions & 1 deletion apps/messagelist/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
0.01: New app!
0.02: Fix music updates while app is already open
0.03: Fix invalid use of Bangle.setUI
0.03: Fix invalid use of Bangle.setUI
0.04: Fix app crashing when new message arrives

25 changes: 19 additions & 6 deletions apps/messagelist/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,19 @@
// If options={} assume we still want `remove` to be called when leaving via fast load (so we must have 'mode:custom')
Bangle.setUI(options, cb);
};
/**
* Same as calling `new Layout(layout, options)`, except Bangle.uiRemove is not called
* @param {object} layout
* @param {object} options
* @returns {Layout}
*/
const makeLayout = function(layout, options) {
const remove = Bangle.uiRemove;
delete Bangle.uiRemove; // don't clear out things when setting up new Layout
const result = new Layout(layout, options);
if (remove) Bangle.uiRemove = remove;
return result;
}

const remove = function(msg) {
if (msg.id==="call") call = undefined;
Expand Down Expand Up @@ -267,7 +280,7 @@
} else {
target = map.body;
}
let layout = new Layout({
let layout = makeLayout({
type: "v", c: [
{type: "txt", font: fontNormal, label: target, bgCol: g.theme.bg2, col: g.theme.fg2, fillx: 1, pad: 2},
{
Expand Down Expand Up @@ -369,7 +382,7 @@
else if (dur) info = dur;
else info = {};

layout = new Layout({
layout = makeLayout({
type: "v", c: [
{
type: "h", fillx: 1, bgCol: g.theme.bg2, col: g.theme.fg2, c: [
Expand Down Expand Up @@ -613,7 +626,7 @@
}
l.c.push(row);
}
layout = new Layout(l, {back: back});
layout = makeLayout(l, {back: back});
layout.render();

if (B2) {
Expand Down Expand Up @@ -697,7 +710,7 @@
];
}

layout = new Layout({
layout = makeLayout({
type: "v", c: [
{
type: "h", fillx: 1, bgCol: g.theme.bg2, col: g.theme.fg2, c: [
Expand Down Expand Up @@ -751,7 +764,7 @@
const w = g.getWidth()-48,
lines = g.setFont(fontNormal).wrapString(alarm.title, w),
title = (lines.length>2) ? lines.slice(0, 2).join("\n")+"..." : lines.join("\n");
layout = new Layout({
layout = makeLayout({
type: "v", c: [
{
type: "h", fillx: 1, bgCol: g.theme.bg2, col: g.theme.fg2, c: [
Expand Down Expand Up @@ -1114,7 +1127,7 @@
let imageCol = getImageColor(msg);
if (g.setColor(imageCol).getColor()==hBg) imageCol = hCol;

layout = new Layout({
layout = makeLayout({
type: "v", c: [
{
type: "h", fillx: 1, bgCol: hBg, col: hCol, c: [
Expand Down
2 changes: 1 addition & 1 deletion apps/messagelist/metadata.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "messagelist",
"name": "Message List",
"version": "0.03",
"version": "0.04",
"description": "Display notifications from iOS and Gadgetbridge/Android as a list",
"icon": "app.png",
"type": "app",
Expand Down

0 comments on commit 4473acd

Please sign in to comment.