simplemusic: add listener for button presses

master
Andre 2025-06-05 13:48:55 -04:00
parent 44a988f7df
commit ffc08f0d4c
2 changed files with 23 additions and 14 deletions

View File

@ -20,6 +20,12 @@ Note: On startup, Simple Music will ping Gadgetbridge for track data by quickly
## Controls ## Controls
### Button controls
Press the side button to toggle playing or pausing the current track.
### Touch controls
Use the on-screen buttons to go back to the previous track, play/pause the current track, or skip to the next track. Use the on-screen buttons to go back to the previous track, play/pause the current track, or skip to the next track.
Swipe up/down to increase/decrease the volume, or swip left/right to navigate to the previous/next song. Swipe up/down to increase/decrease the volume, or swip left/right to navigate to the previous/next song.

View File

@ -179,21 +179,24 @@ function updateState(state) {
/** /**
* Listen for Gadgetbridge events * Listen for Gadgetbridge events
*/ */
setTimeout( setTimeout(() => {
() => { globalThis.GB = (_GB => e => {
globalThis.GB = (_GB => e => { switch (e.t) {
switch (e.t) { case "musicinfo":
case "musicinfo": return showTrackInfo(e);
return showTrackInfo(e); case "musicstate":
case "musicstate": return updateState(e);
return updateState(e); default:
default: // pass on other events
// pass on other events if (_GB) setTimeout(_GB, 0, e);
if (_GB) setTimeout(_GB, 0, e); }
} })(globalThis.GB);
})(globalThis.GB); }, 1);
}, 1);
// Toggle play/pause if the button is pressed
setWatch(function() {
sendCommand(appState.state === PlaybackState.paused ? Command.play : Command.pause, true);
}, BTN, {edge:"rising", debounce:50, repeat:true});
// Start the app // Start the app
initialize(); initialize();