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
### 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.
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
*/
setTimeout(
() => {
globalThis.GB = (_GB => e => {
switch (e.t) {
case "musicinfo":
return showTrackInfo(e);
case "musicstate":
return updateState(e);
default:
// pass on other events
if (_GB) setTimeout(_GB, 0, e);
}
})(globalThis.GB);
}, 1);
setTimeout(() => {
globalThis.GB = (_GB => e => {
switch (e.t) {
case "musicinfo":
return showTrackInfo(e);
case "musicstate":
return updateState(e);
default:
// pass on other events
if (_GB) setTimeout(_GB, 0, e);
}
})(globalThis.GB);
}, 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
initialize();