Merge remote-tracking branch 'upstream/master'

pull/735/head
hughbarney 2021-04-30 18:08:07 +01:00
commit c82d06e573
5 changed files with 47 additions and 31 deletions

View File

@ -3044,7 +3044,7 @@
"name": "Gadgetbridge Music Controls",
"shortName":"Music Controls",
"icon": "icon.png",
"version":"0.03",
"version":"0.04",
"description": "Control the music on your Gadgetbridge-connected phone",
"tags": "tools,bluetooth,gadgetbridge,music",
"type":"app",

View File

@ -1,3 +1,4 @@
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, auto close after 1 hour of inactivity
0.04: Setting to disable touch controls, minor bugfix

View File

@ -16,10 +16,15 @@ Download the [latest Gadgetbridge for Android here](https://f-droid.org/packages
## Settings
The app can automatically load when you play music and close when the music stops.
You can change this under `Settings`->`App/Widget Settings`->`Music Controls`.
You can change these under `Settings`->`App/Widget Settings`->`Music Controls`.
**Auto start**:
Automatically load the app when you play music and close when the music stops.
(If the app opened automatically, it closes after music has been paused for 5 minutes.)
**Touch**:
Enable touch controls?
## Controls
### Buttons

View File

@ -13,6 +13,10 @@ let info = {
};
const POUT = 300000; // auto close timeout when paused: 5 minutes (in ms)
const IOUT = 3600000; // auto close timeout for inactivity: 1 hour (in ms)
// Touch controls? 0: off, 1: when LCD on, 2: always
let s = require("Storage").readJSON("gbmusic.json", 1) || {};
const TCTL = ("touch" in s) ? (s.touch|0)%3 : 1;
delete s;
///////////////////////
// Self-repeating timeouts
@ -138,16 +142,13 @@ function infoColor(name) {
s = 0;
} else {
// make color depend deterministically on info
let code = 0;
let code = textCode(info[name]);
switch(name) {
case "track":
code += textCode(info.track);
// fallthrough: also use album+artist
case "album":
case "track": // also use album
code += textCode(info.album);
// fallthrough: also use artist
default:
code += textCode(info[name]);
// fallthrough
case "album": // also use artist
code += textCode(info.artist);
}
h = code%360;
s = 0.7;
@ -346,6 +347,7 @@ function controlColor(ctrl) {
return (ctrl in tCommand) ? "#ff0000" : "#008800";
}
function drawControl(ctrl, x, y) {
if (!TCTL) {return;}
g.setColor(controlColor(ctrl));
const s = 20;
if (stat!==controlState) {
@ -518,7 +520,9 @@ function togglePlay() {
sendCommand(stat==="play" ? "pause" : "play");
}
function startTouchWatches() {
if (!TCTL) {return;}
Bangle.on("touch", side => {
if (TCTL<2 && !Bangle.isLCDOn()) {return;}
switch(side) {
case 1:
sendCommand(stat==="play" ? "pause" : "previous");
@ -531,6 +535,7 @@ function startTouchWatches() {
}
});
Bangle.on("swipe", dir => {
if (TCTL<2 && !Bangle.isLCDOn()) {return;}
sendCommand(dir===1 ? "previous" : "next");
});
}

View File

@ -4,35 +4,40 @@
(function(back) {
const SETTINGS_FILE = "gbmusic.json",
storage = require("Storage"),
translate = require("locale").translate
translate = require("locale").translate;
const TOUCH_OPTIONS = ["Off", "When LCD on", "Always"];
// initialize with default settings...
let s = {
autoStart: true,
}
touch: 1,
};
// ...and overwrite them with any saved values
// This way saved values are preserved if a new version adds more settings
const saved = storage.readJSON(SETTINGS_FILE, 1) || {}
const saved = storage.readJSON(SETTINGS_FILE, 1) || {};
for(const key in saved) {
s[key] = saved[key]
s[key] = saved[key];
}
// creates a function to safe a specific setting, e.g. save('autoStart')(true)
function save(key) {
return function(value) {
s[key] = value
storage.write(SETTINGS_FILE, s)
}
function save(key, value) {
s[key] = value;
storage.write(SETTINGS_FILE, s);
}
const menu = {
let menu = {
"": {"title": "Music Control"},
"< Back": back,
"Auto start": {
value: s.autoStart,
format: v => translate(v ? "Yes" : "No"),
onchange: save("autoStart"),
}
}
E.showMenu(menu)
})
};
menu[translate("< Back")] = back;
menu[translate("Auto start")] = {
value: s.autoStart,
format: v => translate(v ? "Yes" : "No"),
onchange: v => {save("autoStart", v);},
};
menu[translate("Touch")] = {
value: s.touch|0,
format: v => translate(TOUCH_OPTIONS[(v+3)%3]),
onchange: v => {save("touch", (v+3)%3);},
};
E.showMenu(menu);
});