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.master
parent
ca394e3ff7
commit
2ca3ccfaa0
|
|
@ -3043,7 +3043,7 @@
|
||||||
"name": "Gadgetbridge Music Controls",
|
"name": "Gadgetbridge Music Controls",
|
||||||
"shortName":"Music Controls",
|
"shortName":"Music Controls",
|
||||||
"icon": "icon.png",
|
"icon": "icon.png",
|
||||||
"version":"0.02",
|
"version":"0.03",
|
||||||
"description": "Control the music on your Gadgetbridge-connected phone",
|
"description": "Control the music on your Gadgetbridge-connected phone",
|
||||||
"tags": "tools,bluetooth,gadgetbridge,music",
|
"tags": "tools,bluetooth,gadgetbridge,music",
|
||||||
"type":"app",
|
"type":"app",
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
0.01: Initial version
|
0.01: Initial version
|
||||||
0.02: Increase text brightness, improve controls, (try to) reduce memory usage
|
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,
|
n: 0,
|
||||||
c: 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
|
// Self-repeating timeouts
|
||||||
|
|
@ -44,7 +45,7 @@ function brightness() {
|
||||||
if (!fade) {
|
if (!fade) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return Math.max(0, 1-((Date.now()-fade)/TOUT));
|
return Math.max(0, 1-((Date.now()-fade)/POUT));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scroll long track names
|
// Scroll long track names
|
||||||
|
|
@ -396,26 +397,50 @@ function musicInfo(e) {
|
||||||
if (Bangle.isLCDOn()) {
|
if (Bangle.isLCDOn()) {
|
||||||
drawMusic();
|
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) {
|
function musicState(e) {
|
||||||
stat = e.state;
|
stat = e.state;
|
||||||
// if paused for five minutes, load the clock
|
// if paused for five minutes, load the clock
|
||||||
// (but timeout resets if we get new info, even while paused)
|
// (but timeout resets if we get new info, even while paused)
|
||||||
if (tXit) {
|
if (tPxt) {
|
||||||
clearTimeout(tXit);
|
clearTimeout(tPxt);
|
||||||
|
tPxt = null;
|
||||||
|
}
|
||||||
|
if (tIxt) {
|
||||||
|
clearTimeout(tIxt);
|
||||||
|
tIxt = null;
|
||||||
}
|
}
|
||||||
tXit = null;
|
|
||||||
fade = null;
|
fade = null;
|
||||||
delete info.track_color;
|
delete info.track_color;
|
||||||
if (stat!=="play" && auto) {
|
if (auto) { // auto opened -> auto close
|
||||||
if (stat==="stop") { // never actually happens with my phone :-(
|
switch(stat) {
|
||||||
|
case "stop": // never actually happens with my phone :-(
|
||||||
load();
|
load();
|
||||||
} else { // also quit when paused for a long time
|
break;
|
||||||
tXit = setTimeout(load, TOUT);
|
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();
|
fade = Date.now();
|
||||||
fadeOut();
|
fadeOut();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (Bangle.isLCDOn()) {
|
if (Bangle.isLCDOn()) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue