mirror of https://github.com/espruino/BangleApps
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
parent
c9ba8997b6
commit
4473acdbde
|
@ -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
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
@ -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},
|
||||
{
|
||||
|
@ -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: [
|
||||
|
@ -613,7 +626,7 @@
|
|||
}
|
||||
l.c.push(row);
|
||||
}
|
||||
layout = new Layout(l, {back: back});
|
||||
layout = makeLayout(l, {back: back});
|
||||
layout.render();
|
||||
|
||||
if (B2) {
|
||||
|
@ -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: [
|
||||
|
@ -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: [
|
||||
|
@ -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: [
|
||||
|
|
|
@ -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",
|
||||
|
|
Loading…
Reference in New Issue