From 9ff42c928e3fb18141886040b110cf02d2f7c33f Mon Sep 17 00:00:00 2001 From: Richard de Boer Date: Mon, 7 Mar 2022 22:46:57 +0100 Subject: [PATCH 1/3] messages: auto-open music --- apps/messages/ChangeLog | 1 + apps/messages/README.md | 5 ++-- apps/messages/app.js | 58 +++++++++++++++++++++++++++---------- apps/messages/lib.js | 18 ++++++++++-- apps/messages/metadata.json | 2 +- apps/messages/settings.js | 6 ++++ apps/messages/widget.js | 2 +- 7 files changed, 70 insertions(+), 22 deletions(-) diff --git a/apps/messages/ChangeLog b/apps/messages/ChangeLog index bd40868a5..f39b75c4d 100644 --- a/apps/messages/ChangeLog +++ b/apps/messages/ChangeLog @@ -37,3 +37,4 @@ 0.23: Change message colors to match current theme instead of using green Now attempt to use Large/Big/Medium fonts, and allow minimum font size to be configured 0.24: Remove left-over debug statement +0.25: Setting to auto-open music diff --git a/apps/messages/README.md b/apps/messages/README.md index cce4391e7..655c549b9 100644 --- a/apps/messages/README.md +++ b/apps/messages/README.md @@ -13,12 +13,13 @@ and `Messages`: * `Vibrate` - This is the pattern of buzzes that should be made when a new message is received * `Repeat` - How often should buzzes repeat - the default of 4 means the Bangle will buzz every 4 seconds -* `Unread Timer` - when a new message is received we go into the Messages app. +* `Unread Timer` - When a new message is received we go into the Messages app. If there is no user input for this amount of time then the app will exit and return to the clock where a ringing bell will be shown in the Widget bar. -* `Min Font` - the minimum font size used when displaying messages on the screen. A bigger font +* `Min Font` - The minimum font size used when displaying messages on the screen. A bigger font is chosen if there isn't much message text, but this specifies the smallest the font should get before it starts getting clipped. +* `Auto-Open Music` - Should the app automatically open when the phone starts playing music? ## New Messages diff --git a/apps/messages/app.js b/apps/messages/app.js index 3f3b80080..403f9b5d8 100644 --- a/apps/messages/app.js +++ b/apps/messages/app.js @@ -26,6 +26,8 @@ var fontSmall = "6x8"; var fontMedium = g.getFonts().includes("6x15")?"6x15":"6x8:2"; var fontBig = g.getFonts().includes("12x20")?"12x20":"6x8:2"; var fontLarge = g.getFonts().includes("6x15")?"6x15:2":"6x8:4"; +var active; // active screen +var openMusic = false; // go back to music screen after we handle something else? // hack for 2v10 firmware's lack of ':size' font handling try { g.setFont("6x8:2"); @@ -50,10 +52,14 @@ var MESSAGES = require("Storage").readJSON("messages.json",1)||[]; if (!Array.isArray(MESSAGES)) MESSAGES=[]; var onMessagesModified = function(msg) { // TODO: if new, show this new one - if (msg && msg.new && !((require('Storage').readJSON('setting.json', 1) || {}).quiet)) { + if (msg && msg.id!=="music" && msg.new && !((require('Storage').readJSON('setting.json', 1) || {}).quiet)) { if (WIDGETS["messages"]) WIDGETS["messages"].buzz(); else Bangle.buzz(); } + if (msg && msg.id=="music") { + if (msg.state && msg.state!="play") openMusic = false; // no longer playing music to go back to + if (active!="music") return; // don't open music over other screens + } showMessage(msg&&msg.id); }; function saveMessages() { @@ -135,6 +141,7 @@ function getMessageImageCol(msg,def) { } function showMapMessage(msg) { + active = "map"; var m; var distance, street, target, eta; m=msg.title.match(/(.*) - (.*)/); @@ -168,12 +175,14 @@ function showMapMessage(msg) { msg.new = false; saveMessages(); layout = undefined; - checkMessages({clockIfNoMsg:1,clockIfAllRead:1,showMsgIfUnread:1}); + checkMessages({clockIfNoMsg:1,clockIfAllRead:1,showMsgIfUnread:1,openMusic:0}); }); } +var updateLabelsInterval; function showMusicMessage(msg) { - var updateLabelsInterval; + active = "music"; + openMusic = msg.state=="play"; var trackScrollOffset = 0; var artistScrollOffset = 0; var albumScrollOffset = 0; @@ -194,10 +203,14 @@ function showMusicMessage(msg) { function back() { clearInterval(updateLabelsInterval); + updateLabelsInterval = undefined; + openMusic = false; + var wasNew = msg.new; msg.new = false; saveMessages(); layout = undefined; - checkMessages({clockIfNoMsg:1,clockIfAllRead:1,showMsgIfUnread:1}); + if (wasNew) checkMessages({clockIfNoMsg:1,clockIfAllRead:1,showMsgIfUnread:0,openMusic:0}); + else checkMessages({clockIfNoMsg:0,clockIfAllRead:0,showMsgIfUnread:0,openMusic:0}); } function updateLabels() { trackName = reduceStringAndPad(msg.track, trackScrollOffset, 13); @@ -243,6 +256,7 @@ function showMusicMessage(msg) { } function showMessageScroller(msg) { + active = "scroller"; var bodyFont = fontBig; g.setFont(bodyFont); var lines = []; @@ -272,6 +286,7 @@ function showMessageScroller(msg) { } function showMessageSettings(msg) { + active = "settings"; E.showMenu({"":{"title":/*LANG*/"Message"}, "< Back" : () => showMessage(msg.id), /*LANG*/"View Message" : () => { @@ -280,12 +295,12 @@ function showMessageSettings(msg) { /*LANG*/"Delete" : () => { MESSAGES = MESSAGES.filter(m=>m.id!=msg.id); saveMessages(); - checkMessages({clockIfNoMsg:0,clockIfAllRead:0,showMsgIfUnread:0}); + checkMessages({clockIfNoMsg:0,clockIfAllRead:0,showMsgIfUnread:0,openMusic:0}); }, /*LANG*/"Mark Unread" : () => { msg.new = true; saveMessages(); - checkMessages({clockIfNoMsg:0,clockIfAllRead:0,showMsgIfUnread:0}); + checkMessages({clockIfNoMsg:0,clockIfAllRead:0,showMsgIfUnread:0,openMusic:0}); }, /*LANG*/"Delete all messages" : () => { E.showPrompt(/*LANG*/"Are you sure?", {title:/*LANG*/"Delete All Messages"}).then(isYes => { @@ -293,7 +308,7 @@ function showMessageSettings(msg) { MESSAGES = []; saveMessages(); } - checkMessages({clockIfNoMsg:0,clockIfAllRead:0,showMsgIfUnread:0}); + checkMessages({clockIfNoMsg:0,clockIfAllRead:0,showMsgIfUnread:0,openMusic:0}); }); }, }); @@ -301,15 +316,20 @@ function showMessageSettings(msg) { function showMessage(msgid) { var msg = MESSAGES.find(m=>m.id==msgid); - if (!msg) return checkMessages({clockIfNoMsg:1,clockIfAllRead:0,showMsgIfUnread:0}); // go home if no message found - if (msg.src=="Maps") { - cancelReloadTimeout(); // don't auto-reload to clock now - return showMapMessage(msg); + if (updateLabelsInterval) { + clearInterval(updateLabelsInterval); + updateLabelsInterval=undefined; } + if (!msg) return checkMessages({clockIfNoMsg:1,clockIfAllRead:0,showMsgIfUnread:0,openMusic:openMusic}); // go home if no message found if (msg.id=="music") { cancelReloadTimeout(); // don't auto-reload to clock now return showMusicMessage(msg); } + if (msg.src=="Maps") { + cancelReloadTimeout(); // don't auto-reload to clock now + return showMapMessage(msg); + } + active = "message"; // Normal text message display var title=msg.title, titleFont = fontLarge, lines; if (title) { @@ -342,7 +362,7 @@ function showMessage(msgid) { function goBack() { msg.new = false; saveMessages(); // read mail cancelReloadTimeout(); // don't auto-reload to clock now - checkMessages({clockIfNoMsg:1,clockIfAllRead:0,showMsgIfUnread:0}); + checkMessages({clockIfNoMsg:1,clockIfAllRead:0,showMsgIfUnread:0,openMusic:openMusic}); } var buttons = [ {type:"btn", src:getBackImage(), cb:goBack} // back @@ -353,7 +373,7 @@ function showMessage(msgid) { msg.new = false; saveMessages(); cancelReloadTimeout(); // don't auto-reload to clock now Bangle.messageResponse(msg,true); - checkMessages({clockIfNoMsg:1,clockIfAllRead:1,showMsgIfUnread:1}); + checkMessages({clockIfNoMsg:1,clockIfAllRead:1,showMsgIfUnread:1,openMusic:openMusic}); }}); } if (msg.negative) { @@ -362,7 +382,7 @@ function showMessage(msgid) { msg.new = false; saveMessages(); cancelReloadTimeout(); // don't auto-reload to clock now Bangle.messageResponse(msg,false); - checkMessages({clockIfNoMsg:1,clockIfAllRead:1,showMsgIfUnread:1}); + checkMessages({clockIfNoMsg:1,clockIfAllRead:1,showMsgIfUnread:1,openMusic:openMusic}); }}); } @@ -411,15 +431,19 @@ function checkMessages(options) { return load(); } // we have >0 messages - var newMessages = MESSAGES.filter(m=>m.new); + var newMessages = MESSAGES.filter(m=>m.new&&m.id!="music"); // If we have a new message, show it if (options.showMsgIfUnread && newMessages.length) return showMessage(newMessages[0].id); + // no new messages: show playing music? (only if we have playing music to show) + if (options.openMusic && MESSAGES.some(m=>m.id=="music" && m.track && m.state=="play")) + return showMessage('music'); // no new messages - go to clock? if (options.clockIfAllRead && newMessages.length==0) return load(); // we don't have to time out of this screen... cancelReloadTimeout(); + active = "main"; // Otherwise show a menu E.showScroller({ h : 48, @@ -482,5 +506,7 @@ setTimeout(() => { print("Message not seen - reloading"); load(); }, unreadTimeoutSecs*1000); - checkMessages({clockIfNoMsg:0,clockIfAllRead:0,showMsgIfUnread:1}); + // only openMusic on launch if music is new + var newMusic = MESSAGES.some(m=>m.id==="music"&&m.new); + checkMessages({clockIfNoMsg:0,clockIfAllRead:0,showMsgIfUnread:1,openMusic:newMusic&&settings.openMusic}); },10); // if checkMessages wants to 'load', do that diff --git a/apps/messages/lib.js b/apps/messages/lib.js index 32dff78ba..0f514a73d 100644 --- a/apps/messages/lib.js +++ b/apps/messages/lib.js @@ -1,3 +1,10 @@ +function openMusic() { + // only read settings file for first music message + if ("undefined"==typeof exports._openMusic) { + exports._openMusic = !!((require('Storage').readJSON("messages.settings.json", true) || {}).openMusic); + } + return exports._openMusic; +} /* Push a new message onto messages queue, event is: {t:"add",id:int, src,title,subject,body,sender,tel, important:bool, new:bool} {t:"add",id:int, id:"music", state, artist, track, etc} // add new @@ -26,6 +33,9 @@ exports.pushMessage = function(event) { messages.unshift(event); // add new messages to the beginning } else Object.assign(messages[mIdx], event); + if (event.id=="music" && messages[mIdx].state=="play") { + messages[mIdx].new = true; // new track, or playback (re)started + } } require("Storage").writeJSON("messages.json",messages); // if in app, process immediately @@ -34,8 +44,12 @@ exports.pushMessage = function(event) { if (event.t=="remove" && !messages.some(m=>m.new)) { if (global.WIDGETS && WIDGETS.messages) WIDGETS.messages.hide(); } - // ok, saved now - we only care if it's new - if (event.t!="add") { + // ok, saved now + if (event.id=="music" && Bangle.CLOCK && messages[mIdx].new && openMusic()) { + // just load the app to display music: no buzzing + load("messages.app.js"); + } else if (event.t!="add") { + // we only care if it's new return; } else if(event.new == false) { return; diff --git a/apps/messages/metadata.json b/apps/messages/metadata.json index 0387c1972..ff6a078a5 100644 --- a/apps/messages/metadata.json +++ b/apps/messages/metadata.json @@ -1,7 +1,7 @@ { "id": "messages", "name": "Messages", - "version": "0.24", + "version": "0.25", "description": "App to display notifications from iOS and Gadgetbridge/Android", "icon": "app.png", "type": "app", diff --git a/apps/messages/settings.js b/apps/messages/settings.js index 622177440..99843602b 100644 --- a/apps/messages/settings.js +++ b/apps/messages/settings.js @@ -4,6 +4,7 @@ if (settings.vibrate===undefined) settings.vibrate="."; if (settings.repeat===undefined) settings.repeat=4; if (settings.unreadTimeout===undefined) settings.unreadTimeout=60; + settings.openMusic=!!settings.openMusic; settings.maxUnreadTimeout=240; return settings; } @@ -43,6 +44,11 @@ format: v => [/*LANG*/"Small",/*LANG*/"Medium"][v], onchange: v => updateSetting("fontSize", v) }, + /*LANG*/'Auto-Open Music': { + value: !!settings().openMusic, + format: v => v?/*LANG*/'Yes':/*LANG*/'No', + onchange: v => updateSetting("openMusic", v) + }, }; E.showMenu(mainmenu); }) diff --git a/apps/messages/widget.js b/apps/messages/widget.js index d9363573a..03a44a4ab 100644 --- a/apps/messages/widget.js +++ b/apps/messages/widget.js @@ -45,5 +45,5 @@ message but then the watch was never viewed. In that case we don't want to buzz but should still show that there are unread messages. */ if (global.MESSAGES===undefined) (function() { var messages = require("Storage").readJSON("messages.json",1)||[]; - if (messages.some(m=>m.new)) WIDGETS["messages"].show(true); + if (messages.some(m=>m.new&&m.id!="music")) WIDGETS["messages"].show(true); })(); From b5bc96a2294644950a1e2cb2cbe4679f3ac945a5 Mon Sep 17 00:00:00 2001 From: Stiralbios Date: Thu, 10 Mar 2022 21:18:55 +0100 Subject: [PATCH 2/3] update forgoten metadata.json --- apps/terminalclock/metadata.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/terminalclock/metadata.json b/apps/terminalclock/metadata.json index 6907da84d..de0244318 100644 --- a/apps/terminalclock/metadata.json +++ b/apps/terminalclock/metadata.json @@ -3,7 +3,7 @@ "name": "Terminal Clock", "shortName":"Terminal Clock", "description": "A terminal cli like clock displaying multiple sensor data", - "version":"0.01", + "version":"0.02", "icon": "app.png", "type": "clock", "tags": "clock", From 43094112d1ed47d63f2c414e85e9369b7892a7b8 Mon Sep 17 00:00:00 2001 From: hughbarney Date: Thu, 10 Mar 2022 22:00:40 +0000 Subject: [PATCH 3/3] Daisy: changed text to uppercase, just looks better --- apps/daisy/ChangeLog | 1 + apps/daisy/app.js | 10 +++++----- apps/daisy/metadata.json | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/apps/daisy/ChangeLog b/apps/daisy/ChangeLog index 115c8f2ff..26396b75c 100644 --- a/apps/daisy/ChangeLog +++ b/apps/daisy/ChangeLog @@ -2,3 +2,4 @@ 0.02: added settings menu to change color 0.03: fix metadata.json to allow setting as clock 0.04: added heart rate which is switched on when cycled to it through up/down touch on rhs +0.05: changed text to uppercase, just looks better, removed colons on text diff --git a/apps/daisy/app.js b/apps/daisy/app.js index 01d177a32..cf0287616 100644 --- a/apps/daisy/app.js +++ b/apps/daisy/app.js @@ -109,10 +109,10 @@ function updateSunRiseSunSet(now, lat, lon, line){ const infoData = { ID_DATE: { calc: () => {var d = (new Date()).toString().split(" "); return d[2] + ' ' + d[1] + ' ' + d[3];} }, ID_DAY: { calc: () => {var d = require("locale").dow(new Date()).toLowerCase(); return d[0].toUpperCase() + d.substring(1);} }, - ID_SR: { calc: () => 'Sunrise: ' + sunRise }, - ID_SS: { calc: () => 'Sunset: ' + sunSet }, - ID_STEP: { calc: () => 'Steps: ' + getSteps() }, - ID_BATT: { calc: () => 'Battery: ' + E.getBattery() + '%' }, + ID_SR: { calc: () => 'Sunrise ' + sunRise }, + ID_SS: { calc: () => 'Sunset ' + sunSet }, + ID_STEP: { calc: () => 'Steps ' + getSteps() }, + ID_BATT: { calc: () => 'Battery ' + E.getBattery() + '%' }, ID_HRM: { calc: () => hrmCurrent } }; @@ -158,7 +158,7 @@ function drawInfo() { g.setColor('#f00'); // red drawHeartIcon(); } else { - g.drawString((infoData[infoMode].calc()), w/2, infoLine); + g.drawString((infoData[infoMode].calc().toUpperCase()), w/2, infoLine); } } diff --git a/apps/daisy/metadata.json b/apps/daisy/metadata.json index 5e53f2d5e..15a24592c 100644 --- a/apps/daisy/metadata.json +++ b/apps/daisy/metadata.json @@ -1,6 +1,6 @@ { "id": "daisy", "name": "Daisy", - "version":"0.04", + "version":"0.05", "dependencies": {"mylocation":"app"}, "description": "A clock based on the Pastel clock with large ring guage for steps", "icon": "app.png",