Add shortcuts app

master
Ben Whittaker 2021-09-13 15:08:28 -04:00
parent fa344f75f5
commit 152e9be521
6 changed files with 107 additions and 0 deletions

View File

@ -3442,5 +3442,22 @@
"data": [
{"name":"app.json"}
]
},
{ "id": "shortcuts",
"name": "Shortcuts",
"shortName":"Shortcuts",
"icon": "app.png",
"version":"0.01",
"description": "Quickly load your favourite apps from (almost) any watch face.",
"tags": "tool",
"type": "bootloader",
"readme": "README.md",
"storage": [
{"name":"shortcuts.boot.js","url":"boot.js"},
{"name":"shortcuts.settings.js","url":"settings.js"}
],
"data": [
{"name":"shortcuts.json"}
]
}
]

1
apps/shortcuts/ChangeLog Normal file
View File

@ -0,0 +1 @@
0.01: New App!

7
apps/shortcuts/README.md Normal file
View File

@ -0,0 +1,7 @@
# Shortcuts
Any installed app can be assigned to BTN1 and BTN3 and launched directly from compatible watch faces. This works with any watch face that uses `Bangle.setUI("clock")`.
## Credits
<a target="_blank" href="https://icons8.com/icon/i1z7pQ2orcJk/shortcut">Shortcut</a> icon by <a target="_blank" href="https://icons8.com">Icons8</a>

BIN
apps/shortcuts/app.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 767 B

16
apps/shortcuts/boot.js Normal file
View File

@ -0,0 +1,16 @@
(function() {
var sui = Bangle.setUI;
Bangle.setUI = function(mode, cb) {
if (mode!="clock") return sui(mode,cb);
return sui("clockupdown", (dir) => {
let settings = require("Storage").readJSON("shortcuts.json", 1)||{};
console.log(settings);
if (dir == -1) {
if (settings.BTN1) load(settings.BTN1);
} else if (dir == 1) {
if (settings.BTN3) load(settings.BTN3);
}
});
};
})();

View File

@ -0,0 +1,66 @@
(function(back) {
const s = require("Storage");
const apps = s
.list(/\.info$/)
.map(app => {
var a = s.readJSON(app, 1);
return a && (a.type=="app" || a.type=="clock" || !a.type) && {n: a.name, src: a.src};
})
.filter(Boolean);
apps.sort((a, b) => {
if (a.n < b.n) return -1;
if (a.n > b.n) return 1;
return 0;
});
apps.push({n: "NONE", src: null});
const settings = s.readJSON("shortcuts.json", 1) || {
BTN1: null,
BTN3: null
};
function showApps(btn) {
function format(v) {
return v === settings[btn] ? "*" : "";
}
function onchange(v) {
settings[btn] = v;
s.writeJSON("shortcuts.json", settings);
}
const btnMenu = {
"": {
title: `Apps for ${btn}`
},
"< Back": () => E.showMenu(mainMenu)
};
if (apps.length > 0) {
for (let a of apps) {
btnMenu[a.n] = {
value: a.src,
format: format,
onchange: onchange
};
}
} else {
btnMenu["...No Apps..."] = {
value: undefined,
format: () => "",
onchange: () => {}
};
}
E.showMenu(btnMenu);
}
const mainMenu = {
"": { title: "Shortcuts Settings" },
"< Back": back,
"BTN1 app": () => showApps("BTN1"),
"BTN3 app": () => showApps("BTN3")
};
E.showMenu(mainMenu);
});