Skip to content

Commit c88c0cb

Browse files
author
thyttan
committed
Merge remote-tracking branch 'upstream/music_message_handling' into app-loader
2 parents 50f1b80 + 43034df commit c88c0cb

File tree

25 files changed

+155
-106
lines changed

25 files changed

+155
-106
lines changed

apps/android/ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,4 @@
4747
version 85 when it's out)
4848
0.43: Ensure listRecs doesn't list old-style recorded tracks (Otherwise Gadgetbridge fails parsing the filename)
4949
0.44: Pass HTTP request timeout to Gadgetbridge
50+
0.45: Don't pass on music messages if nothing has changed

apps/android/lib.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ exports.gbSend = function(message) {
22
Bluetooth.println("");
33
Bluetooth.println(JSON.stringify(message));
44
}
5-
let lastMsg, // for music messages - may not be needed now...
5+
let lastMsg, // for GadgetBridge workaround - may not be needed now...
66
gpsState = {}, // keep information on GPS via Gadgetbridge
77
settings = Object.assign({rp:true,as:true,vibrate:".."},
88
require("Storage").readJSON("android.settings.json",1)||{}
@@ -38,6 +38,8 @@ exports.gbHandler = (event) => {
3838
},
3939
// {t:"musicstate", state:"play/pause",position,shuffle,repeat}
4040
"musicstate" : function() {
41+
if (event.state===exports.musicState) return; // no change - avoid spamming message handling with identical messages
42+
exports.musicState = event.state;
4143
require("messages").pushMessage({t:"modify",id:"music",title:"Music",state:event.state});
4244
},
4345
// {t:"musicinfo", artist,album,track,dur,c(track count),n(track num}

apps/android/metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"id": "android",
33
"name": "Android Integration",
44
"shortName": "Android",
5-
"version": "0.44",
5+
"version": "0.45",
66
"description": "Display notifications/music/etc sent from the Gadgetbridge app on Android. This replaces the old 'Gadgetbridge' Bangle.js widget.",
77
"icon": "app.png",
88
"tags": "tool,system,messages,notifications,gadgetbridge",

apps/clock_info/ChangeLog

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,6 @@
2222
0.20: Altitude ClockInfo now uses the distance units set in locale.
2323
0.21: Add haptics when changing infos and a setting to toggle it on or off
2424
0.22: Tapping on step counter now disable step counting on 2v29+ firmwares
25-
0.23: Use filter function for better image borders if it exists (2v22)
25+
0.23: Use filter function for better image borders if it exists (2v22)
26+
0.24: Only save settings once (not once per clockinfo)
27+
Add .setFocus function to allow a clockinfo to be focused without faking a click on it

apps/clock_info/lib.js

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ clockInfoMenu is the 'options' parameter, with the following added:
235235
* `remove` : function - remove this clockInfo item
236236
* `redraw` : function - force a redraw
237237
* `focus` : bool to show if menu is focused or not
238+
* `setFocus(f)` function - set if we're focussed or not
238239
239240
You can have more than one clock_info at once as well, for instance:
240241
@@ -255,27 +256,21 @@ exports.addInteractive = function(menu, options) {
255256
if ("function" == typeof options) options = {draw:options}; // backwards compatibility
256257
options.index = 0|exports.loadCount;
257258
exports.loadCount = options.index+1;
259+
if (!exports.clockInfos.length)
260+
E.on("kill", exports.save); // only need one save handler
258261
exports.clockInfos[options.index] = options;
259262
options.focus = options.index==0 && options.x===undefined; // focus if we're the first one loaded and no position has been defined
260-
const appName = (options.app||"default")+":"+options.index;
261-
263+
options.appName = (options.app||"default")+":"+options.index;
262264
// load the currently showing clock_infos
263265
let settings = exports.loadSettings();
264-
if (settings.apps[appName]) {
265-
let a = settings.apps[appName].a|0;
266-
let b = settings.apps[appName].b|0;
266+
if (settings.apps[options.appName]) {
267+
let a = settings.apps[options.appName].a|0;
268+
let b = settings.apps[options.appName].b|0;
267269
if (menu[a] && menu[a].items[b]) { // all ok
268270
options.menuA = a;
269271
options.menuB = b;
270272
}
271273
}
272-
const save = () => {
273-
// save the currently showing clock_info
274-
const settings = exports.loadSettings();
275-
settings.apps[appName] = {a:options.menuA, b:options.menuB};
276-
require("Storage").writeJSON("clock_info.json",settings);
277-
};
278-
E.on("kill", save);
279274

280275
if (options.menuA===undefined) options.menuA = 0;
281276
if (options.menuB===undefined) options.menuB = Math.min(exports.loadCount, menu[options.menuA].items.length)-1;
@@ -307,6 +302,7 @@ exports.addInteractive = function(menu, options) {
307302
options.menuB += ud;
308303
if (options.menuB<0) options.menuB = menu[options.menuA].items.length-1;
309304
if (options.menuB>=menu[options.menuA].items.length) options.menuB = 0;
305+
options.modified = true;
310306
} else if (lr) {
311307
if (menu.length==1) return; // 1 item - can't move
312308
oldMenuItem = menu[options.menuA].items[options.menuB];
@@ -324,6 +320,7 @@ exports.addInteractive = function(menu, options) {
324320
while ((options.menuB < menu[options.menuA].items.length-1) &&
325321
exports.clockInfos.some(m => (m!=options) && m.menuA==options.menuA && m.menuB==options.menuB))
326322
options.menuB++;
323+
options.modified = true;
327324
}
328325
if (oldMenuItem) {
329326
menuHideItem(oldMenuItem);
@@ -383,15 +380,16 @@ exports.addInteractive = function(menu, options) {
383380
menuShowItem(menu[options.menuA].items[options.menuB]);
384381
// return an object with info that can be used to remove the info
385382
options.remove = function() {
386-
save();
387-
E.removeListener("kill", save);
383+
exports.save();
388384
Bangle.removeListener("swipe",swipeHandler);
389385
if (touchHandler) Bangle.removeListener("touch",touchHandler);
390386
if (lockHandler) Bangle.removeListener("lock", lockHandler);
391387
Bangle.CLKINFO_FOCUS--;
392388
menuHideItem(menu[options.menuA].items[options.menuB]);
393389
exports.loadCount--;
394390
delete exports.clockInfos[options.index];
391+
if (!exports.clockInfos.length) // if no more clockinfos, no need to save
392+
E.removeListener("kill", exports.save);
395393
// If nothing loaded now, clear our list of loaded menus
396394
if (exports.loadCount==0)
397395
exports.clockInfoMenus = undefined;
@@ -416,12 +414,16 @@ exports.addInteractive = function(menu, options) {
416414

417415
return true;
418416
};
417+
options.setFocus = function(f) {
418+
if (f==options.focus) return;
419+
if (f) focus(); else blur();
420+
};
419421
if (options.focus) focus();
420422
delete settings; // don't keep settings in RAM - save space
421423
return options;
422424
};
423425

424-
/* clockinfos usually return a 24x24 image. This draws that image but
426+
/** clockinfos usually return a 24x24 image. This draws that image but
425427
recolors it such that it is transparent, with the middle of the image as background
426428
and the image itself as foreground. options is passed to g.drawImage */
427429
exports.drawFilledImage = function(img,x,y,options) {
@@ -442,7 +444,7 @@ exports.drawFilledImage = function(img,x,y,options) {
442444
return g.drawImage(gfx, x-scale,y-scale,options);
443445
};
444446

445-
/* clockinfos usually return a 24x24 image. This creates a 26x26 gfx of the image but
447+
/** clockinfos usually return a 24x24 image. This creates a 26x26 gfx of the image but
446448
recolors it such that it is transparent, with the middle and border of the image as background
447449
and the image itself as foreground. options is passed to g.drawImage */
448450
exports.drawBorderedImage = function(img,x,y,options) {
@@ -470,6 +472,17 @@ exports.drawBorderedImage = function(img,x,y,options) {
470472
return g.drawImage(gfx, x-o,y-o,options);
471473
};
472474

475+
/** Save clockinfos if modified */
476+
exports.save = function() {
477+
if (!exports.clockInfos.some(ci=>ci.modified)) return; // all written?
478+
const settings = exports.loadSettings();
479+
exports.clockInfos.forEach(ci => {
480+
settings.apps[ci.appName] = {a:ci.menuA, b:ci.menuB};
481+
ci.modified = false;
482+
});
483+
require("Storage").writeJSON("clock_info.json",settings);
484+
};
485+
473486
// Code for testing (plots all elements from first list)
474487
/*
475488
g.clear();

apps/clock_info/metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{ "id": "clock_info",
22
"name": "Clock Info Module",
33
"shortName": "Clock Info",
4-
"version":"0.23",
4+
"version":"0.24",
55
"description": "A library used by clocks to provide extra information on the clock face (Altitude, BPM, etc)",
66
"icon": "app.png",
77
"type": "module",

apps/confthyttan/ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@
88
loading apps.
99
0.08: hide bt indicator when connected (`widbt_notify`). Add "Message Twist to
1010
Scroll". Add "Big Clock Info app".
11+
Auto open messages if locked.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{vibrateTimeout:10,vibrate:":",vibrateCalls:":::",flash:false}
1+
{vibrateTimeout:10,vibrate:":",vibrateCalls:":::",flash:false, autoOpen:2}

apps/fwupdate/custom.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@
112112
else if (crcs[0] == 4148062987 || crcs[0] == 3675049818) version = "2v25";
113113
else if (crcs[0] == 2489937616) version = "2v26";
114114
else if (crcs[0] == 3325639688) version = "2v27";
115+
else if (crcs[0] == 3143424848) version = "2v28";
115116
else { // for other versions all 7 pages are used, check those
116117
var crc = crcs[1];
117118
if (crc==1339551013) { version = "2v10.219"; ok = false; }
@@ -380,6 +381,7 @@
380381
function createJS_bootloader(binary, startAddress, endAddress) {
381382
var crc = CRC32(binary);
382383
console.log("CRC 0x"+crc.toString(16));
384+
// it is possible to do E.memoryArea(0xF7000,0x7000).match(/BL (2v[^\n]*)/) - can take 1s
383385
hexJS = `\x10if (E.CRC32(E.memoryArea(${startAddress},${endAddress-startAddress}))==${crc}) { print("DFU UP TO DATE!"); load();}\n`;
384386
hexJS += `\x10var _fw = new Uint8Array(${binary.length})\n`;
385387
var CHUNKSIZE = 1024;

apps/invader/ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
0.01: New App!
22
0.11: Changes...
33
0.12: Minor code improvements
4+
0.13: Fix app on dark theme screens (fix #1940)

0 commit comments

Comments
 (0)