Gordon Williams 2022-11-28 14:22:35 +00:00
parent cac0c306f4
commit 8678d0cc21
5 changed files with 32 additions and 37 deletions

View File

@ -15,3 +15,4 @@
0.15: Allow method/body/headers to be specified for `http` (needs Gadgetbridge 0.68.0b or later)
0.16: Bangle.http now fails immediately if there is no Bluetooth connection (fix #2152)
0.17: Now kick off Calendar sync as soon as connected to Gadgetbridge
0.18: If connected to Gadgetbridge, allow GPS forwarding from phone (Gadgetbridge code still not merged)

View File

@ -20,6 +20,8 @@ It contains:
of Gadgetbridge - making your phone make noise so you can find it.
* `Keep Msgs` - default is `Off`. When Gadgetbridge disconnects, should Bangle.js
keep any messages it has received, or should it delete them?
* `Overwrite GPS` - when GPS is requested by an app, this doesn't use Bangle.js's GPS
but instead asks Gadgetbridge on the phone to use the phone's GPS
* `Messages` - launches the messages app, showing a list of messages
## How it works

View File

@ -137,8 +137,7 @@
Bangle.emit('gps', event);
},
"is_gps_active": function() {
const gpsActive = originalIsGpsOn();
sendGPSPowerStatus(gpsActive);
gbSend({ t: "gps_power", status: Bangle._PWR && Bangle._PWR.GPS && Bangle._PWR.GPS.length>0 });
}
};
var h = HANDLERS[event.t];
@ -202,34 +201,27 @@
if (isFinite(msg.id)) return gbSend({ t: "notify", n:response?"OPEN":"DISMISS", id: msg.id });
// error/warn here?
};
// GPS overwrite logic
// Save current logic
const originalSetGpsPower = Bangle.setGPSPower;
const originalIsGpsOn = Bangle.isGPSOn;
function sendGPSPowerStatus(status) { gbSend({ t: "gps_power", status: status }); }
// Replace set GPS power logic to suppress activation of gps, if the overwrite option is active
Bangle.setGPSPower = (isOn, appID) => {
const currentSettings = require("Storage").readJSON("android.settings.json",1)||{};
if (!currentSettings.overwriteGps) {
originalSetGpsPower(isOn, appID);
} else {
sendGPSPowerStatus(Bangle.isGPSOn());
const logMessage = 'Ignore gps power change due to the gps overwrite from android integration app';
console.log(logMessage);
Bluetooth.println(logMessage);
if (settings.overwriteGps) { // if the overwrite option is set../
// Save current logic
const originalSetGpsPower = Bangle.setGPSPower;
// Replace set GPS power logic to suppress activation of gps (and instead request it from the phone)
Bangle.setGPSPower = (isOn, appID) => {
// if not connected, use old logic
if (!NRF.getSecurityStatus().connected) return originalSetGpsPower(isOn, appID);
// Emulate old GPS power logic
if (!Bangle._PWR) Bangle._PWR={};
if (!Bangle._PWR.GPS) Bangle._PWR.GPS=[];
if (!appID) appID="?";
if (isOn && !Bangle._PWR.GPS.includes(appID)) Bangle._PWR.GPS.push(appID);
if (!isOn && Bangle._PWR.GPS.includes(appID)) Bangle._PWR.GPS.splice(Bangle._PWR.GPS.indexOf(appID),1);
let pwr = Bangle._PWR.GPS.length>0;
gbSend({ t: "gps_power", status: pwr });
return pwr;
}
}
// Replace check if the GPS is on, to show it as always active, if the overwrite option is set
Bangle.isGPSOn = () => {
const currentSettings = require("Storage").readJSON("android.settings.json",1)||{};
if (!currentSettings.overwriteGps) {
return originalIsGpsOn();
} else {
return true;
// Replace check if the GPS is on to check the _PWR variable
Bangle.isGPSOn = () => {
return Bangle._PWR && Bangle._PWR.GPS && Bangle._PWR.GPS.length>0;
}
}

View File

@ -2,7 +2,7 @@
"id": "android",
"name": "Android Integration",
"shortName": "Android",
"version": "0.17",
"version": "0.18",
"description": "Display notifications/music/etc sent from the Gadgetbridge app on Android. This replaces the old 'Gadgetbridge' Bangle.js widget.",
"icon": "app.png",
"tags": "tool,system,messages,notifications,gadgetbridge",

View File

@ -1,12 +1,6 @@
(function(back) {
function onGpsOverwriteChange(newValue) {
if (newValue) {
Bangle.setGPSPower(false, 'android');
}
settings.overwriteGps = newValue;
updateSettings();
}
function gb(j) {
Bluetooth.println(JSON.stringify(j));
@ -34,7 +28,13 @@
},
/*LANG*/"Overwrite GPS" : {
value : !!settings.overwriteGps,
onchange: onGpsOverwriteChange
onchange: newValue => {
if (newValue) {
Bangle.setGPSPower(false, 'android');
}
settings.overwriteGps = newValue;
updateSettings();
}
},
/*LANG*/"Messages" : ()=>load("messages.app.js"),
};