messages,messagegui: fix handling of music

The library combines musicinfo+musicstate messages, and waited for a
"complete" message before emitting the event.
But once you are playing music you don't get new music state events.
The problem was that when the first "complete" message arrives, the UI
is load()ed, so the library forgets its state, and doesn't emit anymore
music events until the play state changes.

This
- changes the library to keep combining music messages, but always
  emit an event
- makes the UI only launch itself if it sees a "complete" music event
- makes the UI also combine musicinfo+musicstate messages
master
Richard de Boer 2022-11-30 23:58:36 +01:00
parent dda81fe199
commit e9c673e119
No known key found for this signature in database
7 changed files with 9 additions and 6 deletions

View File

@ -77,3 +77,4 @@
0.54: Move icons out to messageicons module 0.54: Move icons out to messageicons module
0.55: Rename to messagegui, move global message handling library to message module 0.55: Rename to messagegui, move global message handling library to message module
Move widget to widmessage Move widget to widmessage
0.56: Fix handling of music messages

View File

@ -112,9 +112,11 @@ function showMapMessage(msg) {
Bangle.setUI({mode:"updown", back: back}, back); // any input takes us back Bangle.setUI({mode:"updown", back: back}, back); // any input takes us back
} }
var updateLabelsInterval; let updateLabelsInterval,
music = {artist: "", album: "", title: ""}; // defaults, so e.g. msg.title.length doesn't error
function showMusicMessage(msg) { function showMusicMessage(msg) {
active = "music"; active = "music";
msg = Object.assign(music, msg); // combine+remember "musicinfo" and "musicstate" messages
openMusic = msg.state=="play"; openMusic = msg.state=="play";
var trackScrollOffset = 0; var trackScrollOffset = 0;
var artistScrollOffset = 0; var artistScrollOffset = 0;

View File

@ -15,12 +15,12 @@ exports.listener = function(type, msg) {
const appSettings = require("Storage").readJSON("messages.settings.json", 1) || {}; const appSettings = require("Storage").readJSON("messages.settings.json", 1) || {};
let loadMessages = (Bangle.CLOCK || event.important); let loadMessages = (Bangle.CLOCK || event.important);
if (type==="music") { if (type==="music") {
if (Bangle.CLOCK && msg.new && appSettings.openMusic) loadMessages = true; if (Bangle.CLOCK && msg.state && msg.title && appSettings.openMusic) loadMessages = true;
else return; else return;
} }
require("messages").save(msg); require("messages").save(msg);
msg.handled = true; msg.handled = true;
if (msg.t!=="add" || !msg.new) { if ((msg.t!=="add" || !msg.new) && (type!=="music")) { // music always has t:"modify"
return; return;
} }

View File

@ -1,7 +1,7 @@
{ {
"id": "messagegui", "id": "messagegui",
"name": "Message UI", "name": "Message UI",
"version": "0.55", "version": "0.56",
"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",

View File

@ -1 +1,2 @@
0.55: Moved messages library into standalone library 0.55: Moved messages library into standalone library
0.56: Fix handling of music messages

View File

@ -6,7 +6,6 @@ exports.music = {};
function emit(msg) { function emit(msg) {
let type = "text"; let type = "text";
if (["call", "music", "map"].includes(msg.id)) type = msg.id; if (["call", "music", "map"].includes(msg.id)) type = msg.id;
if (type==="music" && msg.t!=="remove" && (!("state" in msg) || (!("track" in msg)))) return; // wait for complete music info
if (msg.src && msg.src.toLowerCase().startsWith("alarm")) type = "alarm"; if (msg.src && msg.src.toLowerCase().startsWith("alarm")) type = "alarm";
Bangle.emit("message", type, msg); Bangle.emit("message", type, msg);
} }

View File

@ -1,7 +1,7 @@
{ {
"id": "messages", "id": "messages",
"name": "Messages", "name": "Messages",
"version": "0.55", "version": "0.56",
"description": "Library to handle, load and store message events received from Android/iOS", "description": "Library to handle, load and store message events received from Android/iOS",
"icon": "app.png", "icon": "app.png",
"type": "module", "type": "module",