mirror of https://github.com/espruino/BangleApps
gbmusic: auto close after double song duration (or 1 hour) of inactivity
Because some phones don't end an update when the music simply finished.pull/731/head
parent
ca394e3ff7
commit
2ca3ccfaa0
|
@ -3043,7 +3043,7 @@
|
|||
"name": "Gadgetbridge Music Controls",
|
||||
"shortName":"Music Controls",
|
||||
"icon": "icon.png",
|
||||
"version":"0.02",
|
||||
"version":"0.03",
|
||||
"description": "Control the music on your Gadgetbridge-connected phone",
|
||||
"tags": "tools,bluetooth,gadgetbridge,music",
|
||||
"type":"app",
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
0.01: Initial version
|
||||
0.02: Increase text brightness, improve controls, (try to) reduce memory usage
|
||||
0.03: Only auto-start if active app is a clock
|
||||
0.03: Only auto-start if active app is a clock, auto close after 1 hour of inactivity
|
||||
|
|
|
@ -11,7 +11,8 @@ let info = {
|
|||
n: 0,
|
||||
c: 0,
|
||||
};
|
||||
const TOUT = 300000; // auto close timeout: 5 minutes (in ms)
|
||||
const POUT = 300000; // auto close timeout when paused: 5 minutes (in ms)
|
||||
const IOUT = 3600000; // auto close timeout for inactivity: 1 hour (in ms)
|
||||
|
||||
///////////////////////
|
||||
// Self-repeating timeouts
|
||||
|
@ -44,7 +45,7 @@ function brightness() {
|
|||
if (!fade) {
|
||||
return 1;
|
||||
}
|
||||
return Math.max(0, 1-((Date.now()-fade)/TOUT));
|
||||
return Math.max(0, 1-((Date.now()-fade)/POUT));
|
||||
}
|
||||
|
||||
// Scroll long track names
|
||||
|
@ -396,26 +397,50 @@ function musicInfo(e) {
|
|||
if (Bangle.isLCDOn()) {
|
||||
drawMusic();
|
||||
}
|
||||
if (tIxt) {
|
||||
clearTimeout(tIxt);
|
||||
tIxt = null;
|
||||
}
|
||||
if (auto && stat==="play") {
|
||||
// if inactive for double song duration (or an hour if unknown), load the clock
|
||||
// i.e. phone finished playing without bothering to notify the watch
|
||||
tIxt = setTimeout(load, (info.dur*2000) || IOUT);
|
||||
}
|
||||
}
|
||||
|
||||
let tXit;
|
||||
let tPxt, tIxt;
|
||||
function musicState(e) {
|
||||
stat = e.state;
|
||||
// if paused for five minutes, load the clock
|
||||
// (but timeout resets if we get new info, even while paused)
|
||||
if (tXit) {
|
||||
clearTimeout(tXit);
|
||||
if (tPxt) {
|
||||
clearTimeout(tPxt);
|
||||
tPxt = null;
|
||||
}
|
||||
if (tIxt) {
|
||||
clearTimeout(tIxt);
|
||||
tIxt = null;
|
||||
}
|
||||
tXit = null;
|
||||
fade = null;
|
||||
delete info.track_color;
|
||||
if (stat!=="play" && auto) {
|
||||
if (stat==="stop") { // never actually happens with my phone :-(
|
||||
load();
|
||||
} else { // also quit when paused for a long time
|
||||
tXit = setTimeout(load, TOUT);
|
||||
fade = Date.now();
|
||||
fadeOut();
|
||||
if (auto) { // auto opened -> auto close
|
||||
switch(stat) {
|
||||
case "stop": // never actually happens with my phone :-(
|
||||
load();
|
||||
break;
|
||||
case "play":
|
||||
// if inactive for double song duration (or an hour if unknown), load the clock
|
||||
// i.e. phone finished playing without bothering to notify the watch
|
||||
tIxt = setTimeout(load, (info.dur*2000) || IOUT);
|
||||
break;
|
||||
case "pause":
|
||||
default:
|
||||
// quit when paused for a long time
|
||||
// also fade out track info while waiting for this
|
||||
tPxt = setTimeout(load, POUT);
|
||||
fade = Date.now();
|
||||
fadeOut();
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (Bangle.isLCDOn()) {
|
||||
|
|
Loading…
Reference in New Issue