2022-11-30 17:11:29 +00:00
|
|
|
{
|
2022-11-22 12:52:21 +00:00
|
|
|
require("Font8x12").add(Graphics);
|
|
|
|
|
|
|
|
// load pinned apps from config
|
2022-11-30 17:11:29 +00:00
|
|
|
let settings = require("Storage").readJSON("qcenter.json", 1) || {};
|
|
|
|
let pinnedApps = settings.pinnedApps || [];
|
|
|
|
let exitGesture = settings.exitGesture || "swipeup";
|
2022-11-22 12:52:21 +00:00
|
|
|
|
|
|
|
// if empty load a default set of apps as an example
|
|
|
|
if (pinnedApps.length == 0) {
|
2022-11-30 17:18:31 +00:00
|
|
|
pinnedApps = [
|
|
|
|
{ src: "setting.app.js", icon: "setting.img" },
|
|
|
|
{ src: "about.app.js", icon: "about.img" },
|
|
|
|
];
|
2022-11-22 12:52:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// button drawing from Layout.js, edited to have completely custom button size with icon
|
2022-11-30 17:11:29 +00:00
|
|
|
let drawButton = function(l) {
|
2022-11-30 17:18:31 +00:00
|
|
|
let x = l.x + (0 | l.pad),
|
|
|
|
y = l.y + (0 | l.pad),
|
|
|
|
w = l.w - (l.pad << 1),
|
|
|
|
h = l.h - (l.pad << 1);
|
|
|
|
let poly = [
|
|
|
|
x,
|
|
|
|
y + 4,
|
|
|
|
x + 4,
|
|
|
|
y,
|
|
|
|
x + w - 5,
|
|
|
|
y,
|
|
|
|
x + w - 1,
|
|
|
|
y + 4,
|
|
|
|
x + w - 1,
|
|
|
|
y + h - 5,
|
|
|
|
x + w - 5,
|
|
|
|
y + h - 1,
|
|
|
|
x + 4,
|
|
|
|
y + h - 1,
|
|
|
|
x,
|
|
|
|
y + h - 5,
|
|
|
|
x,
|
|
|
|
y + 4,
|
|
|
|
],
|
|
|
|
bg = l.selected ? g.theme.bgH : g.theme.bg2;
|
|
|
|
g.setColor(bg)
|
|
|
|
.fillPoly(poly)
|
|
|
|
.setColor(l.selected ? g.theme.fgH : g.theme.fg2)
|
|
|
|
.drawPoly(poly);
|
|
|
|
if (l.src)
|
|
|
|
g.setBgColor(bg).drawImage(
|
|
|
|
"function" == typeof l.src ? l.src() : l.src,
|
|
|
|
l.x + l.w / 2,
|
|
|
|
l.y + l.h / 2,
|
|
|
|
{ scale: l.scale || undefined, rotate: Math.PI * 0.5 * (l.r || 0) }
|
|
|
|
);
|
2022-11-22 12:52:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// function to split array into group of 3, for button placement
|
2022-11-30 17:11:29 +00:00
|
|
|
let groupBy3 = function(data) {
|
2022-11-30 17:18:31 +00:00
|
|
|
let result = [];
|
|
|
|
for (let i = 0; i < data.length; i += 3) result.push(data.slice(i, i + 3));
|
|
|
|
return result;
|
2022-11-22 12:52:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// generate object with buttons for apps by group of 3
|
2022-11-30 17:11:29 +00:00
|
|
|
let appButtons = groupBy3(pinnedApps).map((appGroup, i) => {
|
2022-11-30 17:18:31 +00:00
|
|
|
return appGroup.map((app, j) => {
|
|
|
|
return {
|
|
|
|
type: "custom",
|
|
|
|
render: drawButton,
|
|
|
|
width: 50,
|
|
|
|
height: 50,
|
|
|
|
pad: 5,
|
|
|
|
src: require("Storage").read(app.icon),
|
|
|
|
scale: 0.75,
|
|
|
|
cb: (l) => load(app.src),
|
|
|
|
};
|
|
|
|
});
|
2022-11-22 12:52:21 +00:00
|
|
|
});
|
|
|
|
|
2022-11-25 13:42:10 +00:00
|
|
|
// create basic layout content with status info and sensor status on top
|
2022-11-30 17:11:29 +00:00
|
|
|
let layoutContent = [
|
2022-11-30 17:18:31 +00:00
|
|
|
{
|
|
|
|
type: "h",
|
|
|
|
pad: 5,
|
|
|
|
fillx: 1,
|
|
|
|
c: [
|
|
|
|
{ type: "txt", font: "8x12", pad: 3, scale: 2, label: E.getBattery() + "%" },
|
|
|
|
{ type: "txt", font: "8x12", pad: 3, scale: 2, label: "GPS: " + (Bangle.isGPSOn() ? "ON" : "OFF") },
|
|
|
|
],
|
|
|
|
},
|
2022-11-22 12:52:21 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
// create rows for buttons and add them to layoutContent
|
|
|
|
appButtons.forEach((appGroup) => {
|
2022-11-30 17:18:31 +00:00
|
|
|
layoutContent.push({
|
|
|
|
type: "h",
|
|
|
|
pad: 2,
|
|
|
|
c: appGroup,
|
|
|
|
});
|
2022-11-22 12:52:21 +00:00
|
|
|
});
|
|
|
|
|
2022-11-24 17:30:29 +00:00
|
|
|
// create layout with content
|
|
|
|
|
|
|
|
Bangle.loadWidgets();
|
|
|
|
|
2022-11-30 17:11:29 +00:00
|
|
|
let Layout = require("Layout");
|
|
|
|
let layout = new Layout({
|
2022-11-30 17:18:31 +00:00
|
|
|
type: "v",
|
|
|
|
c: layoutContent
|
2022-11-30 17:11:29 +00:00
|
|
|
}, {
|
|
|
|
remove: ()=>{
|
|
|
|
Bangle.removeListener("swipe", onSwipe);
|
2023-01-30 17:27:21 +00:00
|
|
|
Bangle.removeListener("touch", updateTimeout);
|
2023-02-03 11:49:54 +00:00
|
|
|
if (timeout) clearTimeout(timeout);
|
2022-11-30 17:11:29 +00:00
|
|
|
delete Graphics.prototype.setFont8x12;
|
|
|
|
}
|
2022-11-22 12:52:21 +00:00
|
|
|
});
|
|
|
|
g.clear();
|
|
|
|
layout.render();
|
2022-11-24 17:30:29 +00:00
|
|
|
Bangle.drawWidgets();
|
2022-11-22 12:52:21 +00:00
|
|
|
|
2023-01-30 17:27:21 +00:00
|
|
|
let timeout;
|
|
|
|
const updateTimeout = function(){
|
|
|
|
if (settings.timeout){
|
|
|
|
if (timeout) clearTimeout(timeout);
|
|
|
|
timeout = setTimeout(Bangle.showClock,settings.timeout*1000);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
updateTimeout();
|
|
|
|
|
2022-11-24 17:30:29 +00:00
|
|
|
// swipe event listener for exit gesture
|
2022-11-30 17:11:29 +00:00
|
|
|
let onSwipe = function (lr, ud) {
|
2022-11-30 17:18:31 +00:00
|
|
|
if(exitGesture == "swipeup" && ud == -1) Bangle.showClock();
|
|
|
|
if(exitGesture == "swipedown" && ud == 1) Bangle.showClock();
|
|
|
|
if(exitGesture == "swipeleft" && lr == -1) Bangle.showClock();
|
|
|
|
if(exitGesture == "swiperight" && lr == 1) Bangle.showClock();
|
2022-11-30 17:11:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Bangle.on("swipe", onSwipe);
|
2023-01-30 17:27:21 +00:00
|
|
|
Bangle.on("touch", updateTimeout);
|
2022-11-30 17:11:29 +00:00
|
|
|
}
|