messagelist: Fix app crashing when new message arrives

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.
pull/2980/head
Richard de Boer 2023-08-18 21:14:43 +02:00
parent c9ba8997b6
commit 4473acdbde
No known key found for this signature in database
3 changed files with 23 additions and 8 deletions

View File

@ -1,3 +1,5 @@
0.01: New app! 0.01: New app!
0.02: Fix music updates while app is already open 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

View File

@ -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') // 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); 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) { const remove = function(msg) {
if (msg.id==="call") call = undefined; if (msg.id==="call") call = undefined;
@ -267,7 +280,7 @@
} else { } else {
target = map.body; target = map.body;
} }
let layout = new Layout({ let layout = makeLayout({
type: "v", c: [ type: "v", c: [
{type: "txt", font: fontNormal, label: target, bgCol: g.theme.bg2, col: g.theme.fg2, fillx: 1, pad: 2}, {type: "txt", font: fontNormal, label: target, bgCol: g.theme.bg2, col: g.theme.fg2, fillx: 1, pad: 2},
{ {
@ -369,7 +382,7 @@
else if (dur) info = dur; else if (dur) info = dur;
else info = {}; else info = {};
layout = new Layout({ layout = makeLayout({
type: "v", c: [ type: "v", c: [
{ {
type: "h", fillx: 1, bgCol: g.theme.bg2, col: g.theme.fg2, c: [ type: "h", fillx: 1, bgCol: g.theme.bg2, col: g.theme.fg2, c: [
@ -613,7 +626,7 @@
} }
l.c.push(row); l.c.push(row);
} }
layout = new Layout(l, {back: back}); layout = makeLayout(l, {back: back});
layout.render(); layout.render();
if (B2) { if (B2) {
@ -697,7 +710,7 @@
]; ];
} }
layout = new Layout({ layout = makeLayout({
type: "v", c: [ type: "v", c: [
{ {
type: "h", fillx: 1, bgCol: g.theme.bg2, col: g.theme.fg2, c: [ type: "h", fillx: 1, bgCol: g.theme.bg2, col: g.theme.fg2, c: [
@ -751,7 +764,7 @@
const w = g.getWidth()-48, const w = g.getWidth()-48,
lines = g.setFont(fontNormal).wrapString(alarm.title, w), lines = g.setFont(fontNormal).wrapString(alarm.title, w),
title = (lines.length>2) ? lines.slice(0, 2).join("\n")+"..." : lines.join("\n"); title = (lines.length>2) ? lines.slice(0, 2).join("\n")+"..." : lines.join("\n");
layout = new Layout({ layout = makeLayout({
type: "v", c: [ type: "v", c: [
{ {
type: "h", fillx: 1, bgCol: g.theme.bg2, col: g.theme.fg2, c: [ type: "h", fillx: 1, bgCol: g.theme.bg2, col: g.theme.fg2, c: [
@ -1114,7 +1127,7 @@
let imageCol = getImageColor(msg); let imageCol = getImageColor(msg);
if (g.setColor(imageCol).getColor()==hBg) imageCol = hCol; if (g.setColor(imageCol).getColor()==hBg) imageCol = hCol;
layout = new Layout({ layout = makeLayout({
type: "v", c: [ type: "v", c: [
{ {
type: "h", fillx: 1, bgCol: hBg, col: hCol, c: [ type: "h", fillx: 1, bgCol: hBg, col: hCol, c: [

View File

@ -1,7 +1,7 @@
{ {
"id": "messagelist", "id": "messagelist",
"name": "Message List", "name": "Message List",
"version": "0.03", "version": "0.04",
"description": "Display notifications from iOS and Gadgetbridge/Android as a list", "description": "Display notifications from iOS and Gadgetbridge/Android as a list",
"icon": "app.png", "icon": "app.png",
"type": "app", "type": "app",