android: Add Activity Tracks sync support
Lets Gadgetbridge fetch logs created with the `recorder` app.master
parent
3f87305a2d
commit
87ccb9492b
|
|
@ -33,3 +33,4 @@
|
||||||
0.31: Implement API for activity fetching
|
0.31: Implement API for activity fetching
|
||||||
0.32: Added support for loyalty cards from gadgetbridge
|
0.32: Added support for loyalty cards from gadgetbridge
|
||||||
0.33: Fix alarms created in Gadgetbridge not repeating
|
0.33: Fix alarms created in Gadgetbridge not repeating
|
||||||
|
0.34: Implement API for activity tracks fetching (Recorder app logs).
|
||||||
|
|
|
||||||
|
|
@ -16,10 +16,12 @@
|
||||||
if (settings.vibrate == undefined) settings.vibrate = "..";
|
if (settings.vibrate == undefined) settings.vibrate = "..";
|
||||||
require('Storage').writeJSON("android.settings.json", settings);
|
require('Storage').writeJSON("android.settings.json", settings);
|
||||||
var _GB = global.GB;
|
var _GB = global.GB;
|
||||||
|
let fetchRecInterval;
|
||||||
global.GB = (event) => {
|
global.GB = (event) => {
|
||||||
// feed a copy to other handlers if there were any
|
// feed a copy to other handlers if there were any
|
||||||
if (_GB) setTimeout(_GB,0,Object.assign({},event));
|
if (_GB) setTimeout(_GB,0,Object.assign({},event));
|
||||||
|
|
||||||
|
|
||||||
/* TODO: Call handling, fitness */
|
/* TODO: Call handling, fitness */
|
||||||
var HANDLERS = {
|
var HANDLERS = {
|
||||||
// {t:"notify",id:int, src,title,subject,body,sender,tel:string} add
|
// {t:"notify",id:int, src,title,subject,body,sender,tel:string} add
|
||||||
|
|
@ -230,6 +232,49 @@
|
||||||
}
|
}
|
||||||
gbSend({t: "actfetch", state: "end", count: actCount});
|
gbSend({t: "actfetch", state: "end", count: actCount});
|
||||||
},
|
},
|
||||||
|
//{t:"listRecs", id:"20230616a"}
|
||||||
|
"listRecs": function() {
|
||||||
|
let recs = require("Storage").list(/^recorder\.log.*\.csv$/,{sf:true}).map(s => s.slice(12, 21));
|
||||||
|
if (event.id.length > 2) { // Handle if there was no id supplied. Then we send a list all available recorder logs back.
|
||||||
|
let firstNonsyncedIdx = recs.findIndex((logId) => logId > event.id);
|
||||||
|
if (-1 == firstNonsyncedIdx) {
|
||||||
|
recs = []
|
||||||
|
} else {
|
||||||
|
recs = recs.slice(firstNonsyncedIdx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
gbSend({t:"actTrksList", list: recs}); // TODO: split up in multiple transmissions?
|
||||||
|
},
|
||||||
|
//{t:"fetchRec", id:"20230616a"}
|
||||||
|
"fetchRec": function() {
|
||||||
|
// TODO: Decide on what names keys should have.
|
||||||
|
if (fetchRecInterval) {
|
||||||
|
clearInterval(fetchRecInterval);
|
||||||
|
fetchRecInterval = undefined;
|
||||||
|
}
|
||||||
|
if (event.id=="stop") {
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
let log = require("Storage").open("recorder.log"+event.id+".csv","r");
|
||||||
|
let lines = "init";// = log.readLine();
|
||||||
|
let pkgcnt = 0;
|
||||||
|
gbSend({t:"actTrk", log:event.id, lines:"erase", cnt:pkgcnt}); // "erase" will prompt Gadgetbridge to erase the contents of a already fetched log so we can rewrite it without keeping lines from the previous (probably failed) fetch.
|
||||||
|
let sendlines = ()=>{
|
||||||
|
lines = log.readLine();
|
||||||
|
for (var i = 0; i < 3; i++) {
|
||||||
|
let line = log.readLine();
|
||||||
|
if (line) lines += line;
|
||||||
|
}
|
||||||
|
pkgcnt++;
|
||||||
|
gbSend({t:"actTrk", log:event.id, lines:lines, cnt:pkgcnt});
|
||||||
|
if (!lines && fetchRecInterval) {
|
||||||
|
clearInterval(fetchRecInterval);
|
||||||
|
fetchRecInterval = undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fetchRecInterval = setInterval(sendlines, 50)
|
||||||
|
}
|
||||||
|
},
|
||||||
"nav": function() {
|
"nav": function() {
|
||||||
event.id="nav";
|
event.id="nav";
|
||||||
if (event.instr) {
|
if (event.instr) {
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
"id": "android",
|
"id": "android",
|
||||||
"name": "Android Integration",
|
"name": "Android Integration",
|
||||||
"shortName": "Android",
|
"shortName": "Android",
|
||||||
"version": "0.33",
|
"version": "0.34",
|
||||||
"description": "Display notifications/music/etc sent from the Gadgetbridge app on Android. This replaces the old 'Gadgetbridge' Bangle.js widget.",
|
"description": "Display notifications/music/etc sent from the Gadgetbridge app on Android. This replaces the old 'Gadgetbridge' Bangle.js widget.",
|
||||||
"icon": "app.png",
|
"icon": "app.png",
|
||||||
"tags": "tool,system,messages,notifications,gadgetbridge",
|
"tags": "tool,system,messages,notifications,gadgetbridge",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue