Skip to content

Commit 49818ad

Browse files
authored
Merge pull request #4104 from bobrippling/feat/clkinfo-filtering
clkinfo: add filtering
2 parents dc8f047 + 22abcd1 commit 49818ad

File tree

6 files changed

+69
-8
lines changed

6 files changed

+69
-8
lines changed

apps/boot/ChangeLog

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,5 @@
7676
Bangle.loadWidgets overwritten with fast version on success
7777
Refuse to work on firmware <2v16 and remove old polyfills
7878
0.65: Only display interpreter errors if log is nonzero
79-
0.66: Ensure __FILE__ is set even after a fresh boot (fix #3857)
79+
0.66: Ensure __FILE__ is set even after a fresh boot (fix #3857)
80+
0.67: When generating .clkinfocache, apply configured exclusions

apps/boot/bootupdate.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ let bootFiles = require('Storage').list(/\.boot\.js$/).sort((a,b)=>{
116116
// precalculate file size
117117
bootPost += "}";
118118
let fileOffset,fileSize;
119-
/* code to output a file, plus preable and postable
119+
/* code to output a file, plus preamble and postamble
120120
when called with dst==undefined it just increments
121121
fileOffset so we can see ho wbig the file has to be */
122122
let outputFile = (dst,src,pre,post) => {"ram";
@@ -192,8 +192,10 @@ delete widget,widgetPost,widgetFiles;
192192
// ================================================== .clkinfocache for clockinfos
193193
let ciFiles = require("Storage").list(/\.clkinfo\.js$/);
194194
let ci = `// Made by bootupdate.js\n`;
195+
let ci_exclude = (require("Storage").readJSON("clock_info.json", 1) || {}).exclude;
195196
if (DEBUG) ci+="var _tm=Date.now();";
196197
outputFileComplete = (dst,fn) => {
198+
if (ci_exclude && ci_exclude[fn]) return;
197199
outputFile(dst,fn,"try{let fn=",`;let a=fn(),b=menu.find(x=>x.name===a.name);if(b)b.items=b.items.concat(a.items)else menu=menu.concat(a);}catch(e){print(${E.toJS(fn)},e,e.stack)}\n`);
198200
};
199201
fileOffset = ci.length;

apps/boot/metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "boot",
33
"name": "Bootloader",
4-
"version": "0.66",
4+
"version": "0.67",
55
"description": "This is needed by Bangle.js to automatically load the clock, menu, widgets and settings",
66
"icon": "bootloader.png",
77
"type": "bootloader",

apps/clock_info/ChangeLog

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@
2424
0.22: Tapping on step counter now disable step counting on 2v29+ firmwares
2525
0.23: Use filter function for better image borders if it exists (2v22)
2626
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
27+
Add .setFocus function to allow a clockinfo to be focused without faking a click on it
28+
0.25: Add ability to filter-out installed clockinfos

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.24",
4+
"version":"0.25",
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/clock_info/settings.js

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,23 @@
22
let settings = require("clock_info").loadSettings();
33

44
function save(key, value) {
5-
settings[key] = value;
5+
if (key)
6+
settings[key] = value;
67
require('Storage').write("clock_info.json", settings);
78
}
89

9-
let menu ={
10+
let forced = false;
11+
function forceBootUpdate() {
12+
if(forced) return;
13+
14+
const fname = "setting.json";
15+
const j = require("Storage").readJSON(fname);
16+
j.toggle = !j.toggle;
17+
require("Storage").writeJSON(fname);
18+
forced = true;
19+
}
20+
21+
let menu = {
1022
'': { 'title': 'Clock Info' },
1123
/*LANG*/'< Back': back,
1224
/*LANG*/'Defocus on Lock': {
@@ -28,7 +40,52 @@
2840
/*LANG*/'Haptics': {
2941
value: !!settings.haptics,
3042
onchange: x => save('haptics', x),
31-
}
43+
},
44+
/*LANG*/'Filtering': () => {
45+
let filterMenu = {
46+
'': { 'title': 'Exclude clkinfos' },
47+
'< Back': () => E.showMenu(menu)
48+
};
49+
50+
const re = /\.clkinfo\.js$/;
51+
require("Storage")
52+
.list(re)
53+
.forEach(file => {
54+
const name = file.replace(re, "");
55+
56+
filterMenu[name] = {
57+
value: !!(settings.exclude && settings.exclude[file]),
58+
format: v => v ? "hide" : "show",
59+
onchange: v => {
60+
if (v) {
61+
if (!settings.exclude)
62+
settings.exclude = {};
63+
settings.exclude[file] = true;
64+
} else {
65+
if (settings.exclude)
66+
delete settings.exclude[file];
67+
}
68+
save();
69+
forceBootUpdate();
70+
},
71+
};
72+
});
73+
74+
let changed = false;
75+
// clean up stale entries
76+
Object
77+
.keys(settings.exclude)
78+
.filter(k => !(k.replace(re, "") in filterMenu))
79+
.forEach(k => {
80+
delete settings.exclude[k];
81+
changed = true;
82+
});
83+
84+
if(changed) save();
85+
86+
E.showMenu(filterMenu);
87+
},
3288
};
89+
3390
E.showMenu(menu);
3491
})

0 commit comments

Comments
 (0)