swp2clk: Create Initial app with whitelist feature

master
crazysaem 2021-12-21 21:46:30 +00:00
parent d9d5926416
commit 9a58a14681
8 changed files with 256 additions and 0 deletions

View File

@ -5062,5 +5062,22 @@
{"name":"ltherm.app.js","url":"app.js"},
{"name":"ltherm.img","url":"icon.js","evaluate":true}
]
},
{
"id": "swp2clk",
"name": "Swipe back to the Clock",
"shortName": "Swipe to Clock",
"version": "0.01",
"description": "Let's you swipe from left to right on any app to return back to the clock face. Please configure in the settings app after installing to activate, since its disabled by default.",
"icon": "app.png",
"tags": "tools",
"supports": ["BANGLEJS2"],
"readme": "README.md",
"storage": [
{ "name": "swp2clk.boot.js", "url": "boot.js" },
{"name":"swp2clk.settings.js","url":"settings.js"},
{ "name": "swp2clk.img", "url": "app-icon.js", "evaluate": true }
],
"data": [{"name":"swp2clk.data.json"}]
}
]

1
apps/swp2clk/ChangeLog Normal file
View File

@ -0,0 +1 @@
0.01: Initial creation of "Swipe back to the Clock" App. Let's you swipe from left to right on any app to return back to the clock face.

12
apps/swp2clk/README.md Normal file
View File

@ -0,0 +1,12 @@
# Swipe back to the Clock
Let's you swipe from left to right on any app to return back to the clock face.
## Configurable Modes:
The swipe modes can be configured in the settings app, under "Swipe to Clock".
- Always Off: Deactivated for all apps (Default)
- White List: Only activate for chosen apps, otherwise deactivated for all apps.
- Black List: Only disabled for chosen apps, otherwise activated for all apps.
- Always On: Active for all apps (Not actually recommended! E.g. Games need to be able to deal with swipe gestures)

1
apps/swp2clk/app-icon.js Normal file
View File

@ -0,0 +1 @@
require("heatshrink").decompress(atob("mEwwkE/4A2+cyiJABiMjn4WPiAVCDIUBDBsyiEBiUzAwMzkIHBl4tMBw/yBIIxKkIME+YEEiESIpMBkYGD+MfKQoMEEQcgiYHE+EPAwkxgRJG+RSGC4xJBNYwuGC44wCD4sRG4wXHCAweGC5JABQAhGHC5IpFiDIHC5HzgIEHC5oqE+JeHC5RgDmBkEC5vxgYXZkDdGC5fyLYSOIC5SLDC5MgQJAXDUxHygEAKREQC5XxC4KCIC8xHLO4/ziERiSPTmI4IC4rXGFwMTC5LXDmBsFFwLHINQUDC44uH+fc54XG+LlE+QuFnvM5gXDkArCMYYFCkYsECwIAHSBIsDC5cgLIoVMC4ZgFC6PziJIFLpYXDJA53PUY6nHZQMvEwwwIa4kxgQmHmUBXoYMHiAMJkJJJIoMSEZIMBgJTG+QJBERAOFiUzAwMzkIgIGJEAgERiIDBFpgYEmQVCiMjCx4AoA="))

BIN
apps/swp2clk/app.pdn Normal file

Binary file not shown.

BIN
apps/swp2clk/app.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

92
apps/swp2clk/boot.js Normal file
View File

@ -0,0 +1,92 @@
(function () {
var DEBUG = true;
var FILE = "swp2clk.data.json";
var main = () => {
var settings = readSettings();
if (settings.addSwipeHandler) {
var swipeHandler = (dir) => {
log("swipe");
log(dir);
if (dir === 1) {
load();
}
};
Bangle.on("swipe", swipeHandler);
}
var global_load = global.load;
global.load = (fileName) => {
log("loading filename!");
log(fileName);
var settings = readSettings();
if (fileName) {
// "Off"
if (settings.mode === 0) {
settings.addSwipeHandler = false;
}
// "White List"
if (settings.mode === 1) {
if (settings.whiteList.indexOf(fileName) >= 0) {
settings.addSwipeHandler = true;
} else {
settings.addSwipeHandler = false;
}
}
// "Black List"
if (settings.mode === 2) {
if (settings.blackList.indexOf(fileName) >= 0) {
settings.addSwipeHandler = false;
} else {
settings.addSwipeHandler = true;
}
}
// "Always"
if (settings.mode === 3) {
settings.addSwipeHandler = true;
}
} else {
// Clock will load
settings.addSwipeHandler = false;
}
writeSettings(settings);
global_load(fileName);
};
};
// lib functions
var log = (message) => {
if (DEBUG) {
console.log(JSON.stringify(message));
}
};
var readSettings = () => {
log("reading settings");
var settings = require("Storage").readJSON(FILE, 1) || {
mode: 0,
whiteList: [],
blackList: [],
addSwipeHandler: false,
};
log(settings);
return settings;
};
var writeSettings = (settings) => {
log("writing settings");
log(settings);
require("Storage").writeJSON(FILE, settings);
};
// start main function
main();
})();

133
apps/swp2clk/settings.js Normal file
View File

@ -0,0 +1,133 @@
(function (back) {
var DEBUG = true;
var FILE = "swp2clk.data.json";
var settings = {};
var showMainMenu = () => {
log("Loading main menu");
E.showMenu({
"": { title: "Swipe to Clock" },
"< Back": () => back(),
Mode: {
value: settings.mode,
min: 0,
max: 3,
format: (value) => ["Off", "White List", "Black List", "Always"][value],
onchange: (value) => {
settings.mode = value;
writeSettings(settings);
},
},
"White List": () => showWhiteListMenu(),
"Black List": () => {},
});
};
var showWhiteListMenu = () => {
var appList = getAppList();
var whiteListMenu = {
"": { title: "White List" },
"< Back": () => showMainMenu(),
"_Add App_": () => {
var addAppMenu = {
"": { title: "Add to WL" },
"< Back": () => showWhiteListMenu(),
};
appList.forEach((app) => {
if (settings.whiteList.indexOf(app.src) < 0) {
addAppMenu[app.name] = () => {
settings.whiteList.push(app.src);
writeSettings(settings);
showWhiteListMenu();
};
}
});
E.showMenu(addAppMenu);
},
};
appList.forEach((app) => {
if (settings.whiteList.indexOf(app.src) >= 0) {
whiteListMenu[app.name] = () => {
E.showPrompt("Delete from WL?", {
title: "Delete from WL?",
buttons: { Yes: true, No: false },
}).then(function (flag) {
if (flag) {
settings.whiteList.splice(index, 1);
writeSettings(settings);
}
showWhiteListMenu();
});
};
}
});
log("Loading white list menu");
E.showMenu(whiteListMenu);
};
// lib functions
var log = (message) => {
if (DEBUG) {
console.log(JSON.stringify(message));
}
};
var readSettings = () => {
log("reading settings");
var settings = require("Storage").readJSON(FILE, 1) || {
mode: 0,
whiteList: [],
blackList: [],
addSwipeHandler: false,
};
log(settings);
return settings;
};
var writeSettings = (settings) => {
log("writing settings");
log(settings);
require("Storage").writeJSON(FILE, settings);
};
var getAppList = () => {
var appList = storage
.list(/\.info$/)
.map((appInfoFileName) => {
var appInfo = storage.readJSON(appInfoFileName, 1);
return (
appInfo && {
name: appInfo.name,
// type: appInfo.type,
// icon: appInfo.icon,
sortorder: appInfo.sortorder,
src: appInfo.src,
}
);
})
.filter((app) => app && !!app.src);
appList.sort((a, b) => {
var n = (0 | a.sortorder) - (0 | b.sortorder);
if (n) return n; // do sortorder first
if (a.name < b.name) return -1;
if (a.name > b.name) return 1;
return 0;
});
return appList;
};
// start main function
settings = readSettings();
showMainMenu();
});