qcenter - Change tabs to spaces according to code style
parent
e82f64b696
commit
557190b666
|
|
@ -8,95 +8,95 @@ let exitGesture = settings.exitGesture || "swipeup";
|
||||||
|
|
||||||
// if empty load a default set of apps as an example
|
// if empty load a default set of apps as an example
|
||||||
if (pinnedApps.length == 0) {
|
if (pinnedApps.length == 0) {
|
||||||
pinnedApps = [
|
pinnedApps = [
|
||||||
{ src: "setting.app.js", icon: "setting.img" },
|
{ src: "setting.app.js", icon: "setting.img" },
|
||||||
{ src: "about.app.js", icon: "about.img" },
|
{ src: "about.app.js", icon: "about.img" },
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
// button drawing from Layout.js, edited to have completely custom button size with icon
|
// button drawing from Layout.js, edited to have completely custom button size with icon
|
||||||
let drawButton = function(l) {
|
let drawButton = function(l) {
|
||||||
let x = l.x + (0 | l.pad),
|
let x = l.x + (0 | l.pad),
|
||||||
y = l.y + (0 | l.pad),
|
y = l.y + (0 | l.pad),
|
||||||
w = l.w - (l.pad << 1),
|
w = l.w - (l.pad << 1),
|
||||||
h = l.h - (l.pad << 1);
|
h = l.h - (l.pad << 1);
|
||||||
let poly = [
|
let poly = [
|
||||||
x,
|
x,
|
||||||
y + 4,
|
y + 4,
|
||||||
x + 4,
|
x + 4,
|
||||||
y,
|
y,
|
||||||
x + w - 5,
|
x + w - 5,
|
||||||
y,
|
y,
|
||||||
x + w - 1,
|
x + w - 1,
|
||||||
y + 4,
|
y + 4,
|
||||||
x + w - 1,
|
x + w - 1,
|
||||||
y + h - 5,
|
y + h - 5,
|
||||||
x + w - 5,
|
x + w - 5,
|
||||||
y + h - 1,
|
y + h - 1,
|
||||||
x + 4,
|
x + 4,
|
||||||
y + h - 1,
|
y + h - 1,
|
||||||
x,
|
x,
|
||||||
y + h - 5,
|
y + h - 5,
|
||||||
x,
|
x,
|
||||||
y + 4,
|
y + 4,
|
||||||
],
|
],
|
||||||
bg = l.selected ? g.theme.bgH : g.theme.bg2;
|
bg = l.selected ? g.theme.bgH : g.theme.bg2;
|
||||||
g.setColor(bg)
|
g.setColor(bg)
|
||||||
.fillPoly(poly)
|
.fillPoly(poly)
|
||||||
.setColor(l.selected ? g.theme.fgH : g.theme.fg2)
|
.setColor(l.selected ? g.theme.fgH : g.theme.fg2)
|
||||||
.drawPoly(poly);
|
.drawPoly(poly);
|
||||||
if (l.src)
|
if (l.src)
|
||||||
g.setBgColor(bg).drawImage(
|
g.setBgColor(bg).drawImage(
|
||||||
"function" == typeof l.src ? l.src() : l.src,
|
"function" == typeof l.src ? l.src() : l.src,
|
||||||
l.x + l.w / 2,
|
l.x + l.w / 2,
|
||||||
l.y + l.h / 2,
|
l.y + l.h / 2,
|
||||||
{ scale: l.scale || undefined, rotate: Math.PI * 0.5 * (l.r || 0) }
|
{ scale: l.scale || undefined, rotate: Math.PI * 0.5 * (l.r || 0) }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// function to split array into group of 3, for button placement
|
// function to split array into group of 3, for button placement
|
||||||
let groupBy3 = function(data) {
|
let groupBy3 = function(data) {
|
||||||
let result = [];
|
let result = [];
|
||||||
for (let i = 0; i < data.length; i += 3) result.push(data.slice(i, i + 3));
|
for (let i = 0; i < data.length; i += 3) result.push(data.slice(i, i + 3));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// generate object with buttons for apps by group of 3
|
// generate object with buttons for apps by group of 3
|
||||||
let appButtons = groupBy3(pinnedApps).map((appGroup, i) => {
|
let appButtons = groupBy3(pinnedApps).map((appGroup, i) => {
|
||||||
return appGroup.map((app, j) => {
|
return appGroup.map((app, j) => {
|
||||||
return {
|
return {
|
||||||
type: "custom",
|
type: "custom",
|
||||||
render: drawButton,
|
render: drawButton,
|
||||||
width: 50,
|
width: 50,
|
||||||
height: 50,
|
height: 50,
|
||||||
pad: 5,
|
pad: 5,
|
||||||
src: require("Storage").read(app.icon),
|
src: require("Storage").read(app.icon),
|
||||||
scale: 0.75,
|
scale: 0.75,
|
||||||
cb: (l) => load(app.src),
|
cb: (l) => load(app.src),
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// create basic layout content with status info and sensor status on top
|
// create basic layout content with status info and sensor status on top
|
||||||
let layoutContent = [
|
let layoutContent = [
|
||||||
{
|
{
|
||||||
type: "h",
|
type: "h",
|
||||||
pad: 5,
|
pad: 5,
|
||||||
fillx: 1,
|
fillx: 1,
|
||||||
c: [
|
c: [
|
||||||
{ type: "txt", font: "8x12", pad: 3, scale: 2, label: E.getBattery() + "%" },
|
{ 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") },
|
{ type: "txt", font: "8x12", pad: 3, scale: 2, label: "GPS: " + (Bangle.isGPSOn() ? "ON" : "OFF") },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
// create rows for buttons and add them to layoutContent
|
// create rows for buttons and add them to layoutContent
|
||||||
appButtons.forEach((appGroup) => {
|
appButtons.forEach((appGroup) => {
|
||||||
layoutContent.push({
|
layoutContent.push({
|
||||||
type: "h",
|
type: "h",
|
||||||
pad: 2,
|
pad: 2,
|
||||||
c: appGroup,
|
c: appGroup,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// create layout with content
|
// create layout with content
|
||||||
|
|
@ -105,8 +105,8 @@ Bangle.loadWidgets();
|
||||||
|
|
||||||
let Layout = require("Layout");
|
let Layout = require("Layout");
|
||||||
let layout = new Layout({
|
let layout = new Layout({
|
||||||
type: "v",
|
type: "v",
|
||||||
c: layoutContent
|
c: layoutContent
|
||||||
}, {
|
}, {
|
||||||
remove: ()=>{
|
remove: ()=>{
|
||||||
Bangle.removeListener("swipe", onSwipe);
|
Bangle.removeListener("swipe", onSwipe);
|
||||||
|
|
@ -119,10 +119,10 @@ Bangle.drawWidgets();
|
||||||
|
|
||||||
// swipe event listener for exit gesture
|
// swipe event listener for exit gesture
|
||||||
let onSwipe = function (lr, ud) {
|
let onSwipe = function (lr, ud) {
|
||||||
if(exitGesture == "swipeup" && ud == -1) Bangle.showClock();
|
if(exitGesture == "swipeup" && ud == -1) Bangle.showClock();
|
||||||
if(exitGesture == "swipedown" && ud == 1) Bangle.showClock();
|
if(exitGesture == "swipedown" && ud == 1) Bangle.showClock();
|
||||||
if(exitGesture == "swipeleft" && lr == -1) Bangle.showClock();
|
if(exitGesture == "swipeleft" && lr == -1) Bangle.showClock();
|
||||||
if(exitGesture == "swiperight" && lr == 1) Bangle.showClock();
|
if(exitGesture == "swiperight" && lr == 1) Bangle.showClock();
|
||||||
}
|
}
|
||||||
|
|
||||||
Bangle.on("swipe", onSwipe);
|
Bangle.on("swipe", onSwipe);
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,18 @@
|
||||||
{
|
{
|
||||||
"id": "qcenter",
|
"id": "qcenter",
|
||||||
"name": "Quick Center",
|
"name": "Quick Center",
|
||||||
"shortName": "QCenter",
|
"shortName": "QCenter",
|
||||||
"version": "0.01",
|
"version": "0.01",
|
||||||
"description": "An app for quickly launching your favourite apps, inspired by the control centres of other watches.",
|
"description": "An app for quickly launching your favourite apps, inspired by the control centres of other watches.",
|
||||||
"icon": "app.png",
|
"icon": "app.png",
|
||||||
"tags": "",
|
"tags": "",
|
||||||
"supports": ["BANGLEJS2"],
|
"supports": ["BANGLEJS2"],
|
||||||
"readme": "README.md",
|
"readme": "README.md",
|
||||||
"screenshots": [{ "url": "screenshot.png" }],
|
"screenshots": [{ "url": "screenshot.png" }],
|
||||||
"storage": [
|
"storage": [
|
||||||
{ "name": "qcenter.app.js", "url": "app.js" },
|
{ "name": "qcenter.app.js", "url": "app.js" },
|
||||||
{ "name": "qcenter.settings.js", "url": "settings.js" },
|
{ "name": "qcenter.settings.js", "url": "settings.js" },
|
||||||
{ "name": "qcenter.img", "url": "app-icon.js", "evaluate": true }
|
{ "name": "qcenter.img", "url": "app-icon.js", "evaluate": true }
|
||||||
],
|
],
|
||||||
"data": [{"name":"qcenter.json"}]
|
"data": [{"name":"qcenter.json"}]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,133 +1,133 @@
|
||||||
// make sure to enclose the function in parentheses
|
// make sure to enclose the function in parentheses
|
||||||
(function (back) {
|
(function (back) {
|
||||||
let settings = require("Storage").readJSON("qcenter.json", 1) || {};
|
let settings = require("Storage").readJSON("qcenter.json", 1) || {};
|
||||||
var apps = require("Storage")
|
var apps = require("Storage")
|
||||||
.list(/\.info$/)
|
.list(/\.info$/)
|
||||||
.map((app) => {
|
.map((app) => {
|
||||||
var a = require("Storage").readJSON(app, 1);
|
var a = require("Storage").readJSON(app, 1);
|
||||||
return (
|
return (
|
||||||
a && {
|
a && {
|
||||||
name: a.name,
|
name: a.name,
|
||||||
type: a.type,
|
type: a.type,
|
||||||
sortorder: a.sortorder,
|
sortorder: a.sortorder,
|
||||||
src: a.src,
|
src: a.src,
|
||||||
icon: a.icon,
|
icon: a.icon,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
.filter(
|
.filter(
|
||||||
(app) =>
|
(app) =>
|
||||||
app &&
|
app &&
|
||||||
(app.type == "app" ||
|
(app.type == "app" ||
|
||||||
app.type == "launch" ||
|
app.type == "launch" ||
|
||||||
app.type == "clock" ||
|
app.type == "clock" ||
|
||||||
!app.type)
|
!app.type)
|
||||||
);
|
);
|
||||||
apps.sort((a, b) => {
|
apps.sort((a, b) => {
|
||||||
var n = (0 | a.sortorder) - (0 | b.sortorder);
|
var n = (0 | a.sortorder) - (0 | b.sortorder);
|
||||||
if (n) return n; // do sortorder first
|
if (n) return n; // do sortorder first
|
||||||
if (a.name < b.name) return -1;
|
if (a.name < b.name) return -1;
|
||||||
if (a.name > b.name) return 1;
|
if (a.name > b.name) return 1;
|
||||||
return 0;
|
return 0;
|
||||||
});
|
});
|
||||||
|
|
||||||
function save(key, value) {
|
function save(key, value) {
|
||||||
settings[key] = value;
|
settings[key] = value;
|
||||||
require("Storage").write("qcenter.json", settings);
|
require("Storage").write("qcenter.json", settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
var pinnedApps = settings.pinnedApps || [];
|
var pinnedApps = settings.pinnedApps || [];
|
||||||
var exitGesture = settings.exitGesture || "swipeup";
|
var exitGesture = settings.exitGesture || "swipeup";
|
||||||
|
|
||||||
function showMainMenu() {
|
function showMainMenu() {
|
||||||
var mainmenu = {
|
var mainmenu = {
|
||||||
"": { title: "Quick Center", back: back}
|
"": { title: "Quick Center", back: back},
|
||||||
};
|
};
|
||||||
|
|
||||||
// Set exit gesture
|
// Set exit gesture
|
||||||
mainmenu["Exit Gesture: " + exitGesture] = function () {
|
mainmenu["Exit Gesture: " + exitGesture] = function () {
|
||||||
E.showMenu(exitGestureMenu);
|
E.showMenu(exitGestureMenu);
|
||||||
};
|
};
|
||||||
|
|
||||||
//List all pinned apps, redirecting to menu with options to unpin and reorder
|
//List all pinned apps, redirecting to menu with options to unpin and reorder
|
||||||
pinnedApps.forEach((app, i) => {
|
pinnedApps.forEach((app, i) => {
|
||||||
mainmenu[app.name] = function () {
|
mainmenu[app.name] = function () {
|
||||||
E.showMenu({
|
E.showMenu({
|
||||||
"": { title: app.name, back: showMainMenu },
|
"": { title: app.name, back: showMainMenu },
|
||||||
"Unpin": () => {
|
"Unpin": () => {
|
||||||
pinnedApps.splice(i, 1);
|
pinnedApps.splice(i, 1);
|
||||||
save("pinnedApps", pinnedApps);
|
save("pinnedApps", pinnedApps);
|
||||||
showMainMenu();
|
showMainMenu();
|
||||||
},
|
},
|
||||||
"Move Up": () => {
|
"Move Up": () => {
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
pinnedApps.splice(i - 1, 0, pinnedApps.splice(i, 1)[0]);
|
pinnedApps.splice(i - 1, 0, pinnedApps.splice(i, 1)[0]);
|
||||||
save("pinnedApps", pinnedApps);
|
save("pinnedApps", pinnedApps);
|
||||||
showMainMenu();
|
showMainMenu();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"Move Down": () => {
|
"Move Down": () => {
|
||||||
if (i < pinnedApps.length - 1) {
|
if (i < pinnedApps.length - 1) {
|
||||||
pinnedApps.splice(i + 1, 0, pinnedApps.splice(i, 1)[0]);
|
pinnedApps.splice(i + 1, 0, pinnedApps.splice(i, 1)[0]);
|
||||||
save("pinnedApps", pinnedApps);
|
save("pinnedApps", pinnedApps);
|
||||||
showMainMenu();
|
showMainMenu();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
// Show pin app menu, or show alert if max amount of apps are pinned
|
// Show pin app menu, or show alert if max amount of apps are pinned
|
||||||
mainmenu["Pin App"] = function () {
|
mainmenu["Pin App"] = function () {
|
||||||
if (pinnedApps.length < 6) {
|
if (pinnedApps.length < 6) {
|
||||||
E.showMenu(pinAppMenu);
|
E.showMenu(pinAppMenu);
|
||||||
} else {
|
} else {
|
||||||
E.showAlert("Max apps pinned").then(showMainMenu);
|
E.showAlert("Max apps pinned").then(showMainMenu);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return E.showMenu(mainmenu);
|
return E.showMenu(mainmenu);
|
||||||
}
|
}
|
||||||
|
|
||||||
// menu for adding apps to the quick launch menu, listing all apps
|
// menu for adding apps to the quick launch menu, listing all apps
|
||||||
var pinAppMenu = {
|
var pinAppMenu = {
|
||||||
"": { title: "Add App", back: showMainMenu }
|
"": { title: "Add App", back: showMainMenu }
|
||||||
};
|
};
|
||||||
apps.forEach((a) => {
|
apps.forEach((a) => {
|
||||||
pinAppMenu[a.name] = function () {
|
pinAppMenu[a.name] = function () {
|
||||||
// strip unncecessary properties
|
// strip unncecessary properties
|
||||||
delete a.type;
|
delete a.type;
|
||||||
delete a.sortorder;
|
delete a.sortorder;
|
||||||
pinnedApps.push(a);
|
pinnedApps.push(a);
|
||||||
save("pinnedApps", pinnedApps);
|
save("pinnedApps", pinnedApps);
|
||||||
showMainMenu();
|
showMainMenu();
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
// menu for setting exit gesture
|
// menu for setting exit gesture
|
||||||
var exitGestureMenu = {
|
var exitGestureMenu = {
|
||||||
"": { title: "Exit Gesture", back: showMainMenu }
|
"": { title: "Exit Gesture", back: showMainMenu }
|
||||||
};
|
};
|
||||||
exitGestureMenu["Swipe Up"] = function () {
|
exitGestureMenu["Swipe Up"] = function () {
|
||||||
exitGesture = "swipeup";
|
exitGesture = "swipeup";
|
||||||
save("exitGesture", "swipeup");
|
save("exitGesture", "swipeup");
|
||||||
showMainMenu();
|
showMainMenu();
|
||||||
};
|
};
|
||||||
exitGestureMenu["Swipe Down"] = function () {
|
exitGestureMenu["Swipe Down"] = function () {
|
||||||
exitGesture = "swipedown";
|
exitGesture = "swipedown";
|
||||||
save("exitGesture", "swipedown");
|
save("exitGesture", "swipedown");
|
||||||
showMainMenu();
|
showMainMenu();
|
||||||
};
|
};
|
||||||
exitGestureMenu["Swipe Left"] = function () {
|
exitGestureMenu["Swipe Left"] = function () {
|
||||||
exitGesture = "swipeleft";
|
exitGesture = "swipeleft";
|
||||||
save("exitGesture", "swipeleft");
|
save("exitGesture", "swipeleft");
|
||||||
showMainMenu();
|
showMainMenu();
|
||||||
};
|
};
|
||||||
exitGestureMenu["Swipe Right"] = function () {
|
exitGestureMenu["Swipe Right"] = function () {
|
||||||
exitGesture = "swiperight";
|
exitGesture = "swiperight";
|
||||||
save("exitGesture", "swiperight");
|
save("exitGesture", "swiperight");
|
||||||
showMainMenu();
|
showMainMenu();
|
||||||
};
|
};
|
||||||
|
|
||||||
showMainMenu();
|
showMainMenu();
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue