From 205e95347ee757bbbbf010574742ffb7f1559216 Mon Sep 17 00:00:00 2001 From: Logan B <3870583+thinkpoop@users.noreply.github.com> Date: Sat, 8 Feb 2025 14:27:01 -0600 Subject: [PATCH 1/5] [gbmusic] fix #3737; fix autostart saved state; pass playpause to gb instead of play; allow widget clicks --- apps/gbmusic/ChangeLog | 1 + apps/gbmusic/app.js | 16 +++++++++++----- apps/gbmusic/boot.js | 4 ++-- apps/gbmusic/metadata.json | 2 +- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/apps/gbmusic/ChangeLog b/apps/gbmusic/ChangeLog index 0275542fb..433c58368 100644 --- a/apps/gbmusic/ChangeLog +++ b/apps/gbmusic/ChangeLog @@ -12,3 +12,4 @@ 0.11: Use default Bangle formatter for booleans 0.12: Issue newline before GB commands (solves issue with console.log and ignored commands) 0.13: Upgrade to new translation system +0.14: Fix auto-start saved state; fix clearing track number; allow widget clicks diff --git a/apps/gbmusic/app.js b/apps/gbmusic/app.js index 7f5aad8f3..8cf813fb9 100644 --- a/apps/gbmusic/app.js +++ b/apps/gbmusic/app.js @@ -91,8 +91,8 @@ function rScroller(l) { const w = g.stringWidth(l.label)+40, y = l.y+l.h/2; l.offset = l.offset%w; - g.setClipRect(l.x, l.y, l.x+l.w-1, l.y+l.h-1) - .setColor(l.col).setBgColor(l.bgCol) // need to set colors: iScroll calls this function outside Layout + //g.setClipRect(l.x, l.y, l.x+l.w-1, l.y+l.h-1) + g.setColor(l.col).setBgColor(l.bgCol) // need to set colors: iScroll calls this function outside Layout .setFontAlign(-1, 0) // left center .clearRect(l.x, l.y, l.x+l.w-1, l.y+l.h-1) .drawString(l.label, l.x-l.offset+40, y) @@ -433,15 +433,21 @@ function sendCommand(command) { drawControls(); } +function handleTouch(btn, pos) { + if (pos === undefined || pos.y >= Bangle.appRect.y) { + togglePlay(); + } +} + function togglePlay() { - sendCommand(stat==="play" ? "pause" : "play"); + sendCommand(stat==="play" ? "pause" : "playpause"); } /** * Setup touch+swipe for Bangle.js 1 */ function touch1() { - Bangle.on("touch", togglePlay); + Bangle.on("touch", handleTouch); Bangle.on("swipe", dir => { sendCommand(dir===1 ? "previous" : "next"); }); @@ -450,7 +456,7 @@ function touch1() { * Setup touch+swipe for Bangle.js 2 */ function touch2() { - Bangle.on("touch", togglePlay); + Bangle.on("touch", handleTouch); // swiping let drag; Bangle.on("drag", e => { diff --git a/apps/gbmusic/boot.js b/apps/gbmusic/boot.js index 154f85c2b..6cd544a21 100644 --- a/apps/gbmusic/boot.js +++ b/apps/gbmusic/boot.js @@ -10,7 +10,7 @@ setTimeout( // make other boot code run first, so we override e.g. android.boot. * Only runs while other apps are loaded */ function check() { - if (s!=="play" || !i || !a || !Bangle.CLOCK) return; // only launch app if we know which song we are playing, and autoLoad is enabled + if ((!s || s.state!=="play") || !i || !a || !Bangle.CLOCK) return; // only launch app if we know which song we are playing, and autoLoad is enabled delete (i.t); // store info and launch music app require("Storage").writeJSON("gbmusic.load.json", { @@ -27,7 +27,7 @@ setTimeout( // make other boot code run first, so we override e.g. android.boot. i = e; return APP ? info(e) : check(); case "musicstate": - s = e.state; + s = e; return APP ? state(e) : check(); default: // pass on other events diff --git a/apps/gbmusic/metadata.json b/apps/gbmusic/metadata.json index 0024a1708..a463e6ea0 100644 --- a/apps/gbmusic/metadata.json +++ b/apps/gbmusic/metadata.json @@ -2,7 +2,7 @@ "id": "gbmusic", "name": "Gadgetbridge Music Controls", "shortName": "Music Controls", - "version": "0.13", + "version": "0.14", "description": "Control the music on your Gadgetbridge-connected phone", "icon": "icon.png", "screenshots": [{"url":"screenshot_v1_d.png"},{"url":"screenshot_v1_l.png"}, From 63797c402abde3f827f30e9e9d1e8b1ab1789be8 Mon Sep 17 00:00:00 2001 From: Logan B <3870583+thinkpoop@users.noreply.github.com> Date: Sat, 8 Feb 2025 16:01:18 -0600 Subject: [PATCH 2/5] [gbmusic] fix lint warnings --- apps/gbmusic/app.js | 109 ++++++++++++++++++++++--------------------- apps/gbmusic/boot.js | 11 +++-- 2 files changed, 62 insertions(+), 58 deletions(-) diff --git a/apps/gbmusic/app.js b/apps/gbmusic/app.js index 8cf813fb9..1f6f6c620 100644 --- a/apps/gbmusic/app.js +++ b/apps/gbmusic/app.js @@ -128,57 +128,60 @@ function rInfo(l) { .setFontAlign(0, -1) // center top .drawString(l.label, l.x+l.w/2, l.y); } -/** - * Render icon - * @param l - */ -function rIcon(l) { - const x2 = l.x+l.w-1, - y2 = l.y+l.h-1; - switch(l.icon) { - case "pause": { - const w13 = l.w/3; - g.drawRect(l.x, l.y, l.x+w13, y2); - g.drawRect(l.x+l.w-w13, l.y, x2, y2); - break; - } - case "play": { - g.drawPoly([ - l.x, l.y, - x2, l.y+l.h/2, - l.x, y2, - ], true); - break; - } - case "previous": { - const w15 = l.w*1/5; - g.drawPoly([ - x2, l.y, - l.x+w15, l.y+l.h/2, - x2, y2, - ], true); - g.drawRect(l.x, l.y, l.x+w15, y2); - break; - } - case "next": { - const w45 = l.w*4/5; - g.drawPoly([ - l.x, l.y, - l.x+w45, l.y+l.h/2, - l.x, y2, - ], true); - g.drawRect(l.x+w45, l.y, x2, y2); - break; - } - default: { // red X - console.log(`Unknown icon: ${l.icon}`); - g.setColor("#f00") - .drawRect(l.x, l.y, x2, y2) - .drawLine(l.x, l.y, x2, y2) - .drawLine(l.x, y2, x2, l.y); - } - } -} + +// *** Unused Function *** +// // /** +// // * Render icon +// // * @param l +// // */ +// // function rIcon(l) { +// // const x2 = l.x+l.w-1, +// // y2 = l.y+l.h-1; +// // switch(l.icon) { +// // case "pause": { +// // const w13 = l.w/3; +// // g.drawRect(l.x, l.y, l.x+w13, y2); +// // g.drawRect(l.x+l.w-w13, l.y, x2, y2); +// // break; +// // } +// // case "play": { +// // g.drawPoly([ +// // l.x, l.y, +// // x2, l.y+l.h/2, +// // l.x, y2, +// // ], true); +// // break; +// // } +// // case "previous": { +// // const w15 = l.w*1/5; +// // g.drawPoly([ +// // x2, l.y, +// // l.x+w15, l.y+l.h/2, +// // x2, y2, +// // ], true); +// // g.drawRect(l.x, l.y, l.x+w15, y2); +// // break; +// // } +// // case "next": { +// // const w45 = l.w*4/5; +// // g.drawPoly([ +// // l.x, l.y, +// // l.x+w45, l.y+l.h/2, +// // l.x, y2, +// // ], true); +// // g.drawRect(l.x+w45, l.y, x2, y2); +// // break; +// // } +// // default: { // red X +// // console.log(`Unknown icon: ${l.icon}`); +// // g.setColor("#f00") +// // .drawRect(l.x, l.y, x2, y2) +// // .drawLine(l.x, l.y, x2, y2) +// // .drawLine(l.x, y2, x2, l.y); +// // } +// // } +// // } + let layout; function makeUI() { Bangle.loadWidgets(); @@ -489,10 +492,10 @@ function startLCDWatch() { Bangle.on("lcdPower", (on) => { if (on) { // redraw and resume scrolling - tick(); + //tick(); // Not sure what this function was; currently undefined layout.render(); fadeOut(); - if (offset.offset!==null) { + if (layout.title.offset!==null) { // Making an assumption about what offset.offset was supposed to be if (!iScroll) { iScroll = setInterval(scroll, 200); } diff --git a/apps/gbmusic/boot.js b/apps/gbmusic/boot.js index 6cd544a21..2f1c09d8a 100644 --- a/apps/gbmusic/boot.js +++ b/apps/gbmusic/boot.js @@ -1,6 +1,6 @@ setTimeout( // make other boot code run first, so we override e.g. android.boot.js GB () => { - const APP = global.__FILE__==="gbmusic.app.js", + const APP = globalThis.__FILE__==="gbmusic.app.js", a = !!(require("Storage").readJSON("gbmusic.json", 1) || {}).autoStart; let s, i; // state, info @@ -20,18 +20,19 @@ setTimeout( // make other boot code run first, so we override e.g. android.boot. load("gbmusic.app.js"); } - global.GB = (_GB => e => { + + globalThis.GB = (_GB => e => { // we eat music events! switch(e.t) { case "musicinfo": i = e; - return APP ? info(e) : check(); + return APP ? globalThis.info(e) : check(); case "musicstate": s = e; - return APP ? state(e) : check(); + return APP ? globalThis.state(e) : check(); default: // pass on other events if (_GB) setTimeout(_GB, 0, e); } - })(global.GB); + })(globalThis.GB); }, 1); From 13b16ac87dccc022f63ace1827a84ce9ea70d83f Mon Sep 17 00:00:00 2001 From: Logan B <3870583+thinkpoop@users.noreply.github.com> Date: Wed, 12 Feb 2025 11:17:54 -0600 Subject: [PATCH 3/5] [gbmusic] delete commented out code --- apps/gbmusic/app.js | 54 --------------------------------------------- 1 file changed, 54 deletions(-) diff --git a/apps/gbmusic/app.js b/apps/gbmusic/app.js index 1f6f6c620..50e7cf500 100644 --- a/apps/gbmusic/app.js +++ b/apps/gbmusic/app.js @@ -91,7 +91,6 @@ function rScroller(l) { const w = g.stringWidth(l.label)+40, y = l.y+l.h/2; l.offset = l.offset%w; - //g.setClipRect(l.x, l.y, l.x+l.w-1, l.y+l.h-1) g.setColor(l.col).setBgColor(l.bgCol) // need to set colors: iScroll calls this function outside Layout .setFontAlign(-1, 0) // left center .clearRect(l.x, l.y, l.x+l.w-1, l.y+l.h-1) @@ -129,58 +128,6 @@ function rInfo(l) { .drawString(l.label, l.x+l.w/2, l.y); } -// *** Unused Function *** -// // /** -// // * Render icon -// // * @param l -// // */ -// // function rIcon(l) { -// // const x2 = l.x+l.w-1, -// // y2 = l.y+l.h-1; -// // switch(l.icon) { -// // case "pause": { -// // const w13 = l.w/3; -// // g.drawRect(l.x, l.y, l.x+w13, y2); -// // g.drawRect(l.x+l.w-w13, l.y, x2, y2); -// // break; -// // } -// // case "play": { -// // g.drawPoly([ -// // l.x, l.y, -// // x2, l.y+l.h/2, -// // l.x, y2, -// // ], true); -// // break; -// // } -// // case "previous": { -// // const w15 = l.w*1/5; -// // g.drawPoly([ -// // x2, l.y, -// // l.x+w15, l.y+l.h/2, -// // x2, y2, -// // ], true); -// // g.drawRect(l.x, l.y, l.x+w15, y2); -// // break; -// // } -// // case "next": { -// // const w45 = l.w*4/5; -// // g.drawPoly([ -// // l.x, l.y, -// // l.x+w45, l.y+l.h/2, -// // l.x, y2, -// // ], true); -// // g.drawRect(l.x+w45, l.y, x2, y2); -// // break; -// // } -// // default: { // red X -// // console.log(`Unknown icon: ${l.icon}`); -// // g.setColor("#f00") -// // .drawRect(l.x, l.y, x2, y2) -// // .drawLine(l.x, l.y, x2, y2) -// // .drawLine(l.x, y2, x2, l.y); -// // } -// // } -// // } let layout; function makeUI() { @@ -492,7 +439,6 @@ function startLCDWatch() { Bangle.on("lcdPower", (on) => { if (on) { // redraw and resume scrolling - //tick(); // Not sure what this function was; currently undefined layout.render(); fadeOut(); if (layout.title.offset!==null) { // Making an assumption about what offset.offset was supposed to be From 879485b664dbd3ac28852653e4706211542e56fd Mon Sep 17 00:00:00 2001 From: Logan B <3870583+thinkpoop@users.noreply.github.com> Date: Wed, 12 Feb 2025 18:29:00 -0600 Subject: [PATCH 4/5] [gbmusic] update sendCommand parameter jsdoc --- apps/gbmusic/app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/gbmusic/app.js b/apps/gbmusic/app.js index 50e7cf500..b09d772ff 100644 --- a/apps/gbmusic/app.js +++ b/apps/gbmusic/app.js @@ -367,7 +367,7 @@ function handleButton2Press() { let tCommand = {}; /** * Send command and highlight corresponding control - * @param {string} command - "play"/"pause"/"next"/"previous"/"volumeup"/"volumedown" + * @param {"play"|"pause"|"playpause"|"next"|"previous"|"volumeup"|"volumedown"} command */ function sendCommand(command) { Bluetooth.println(""); From 7a245cc8af83841d789ad565d01839c7cefeae5f Mon Sep 17 00:00:00 2001 From: Logan B <3870583+thinkpoop@users.noreply.github.com> Date: Wed, 12 Feb 2025 18:31:39 -0600 Subject: [PATCH 5/5] [gbmusic] always send playpause when toggling play/pause --- apps/gbmusic/app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/gbmusic/app.js b/apps/gbmusic/app.js index b09d772ff..31e56ec39 100644 --- a/apps/gbmusic/app.js +++ b/apps/gbmusic/app.js @@ -390,7 +390,7 @@ function handleTouch(btn, pos) { } function togglePlay() { - sendCommand(stat==="play" ? "pause" : "playpause"); + sendCommand("playpause"); } /**