1
0
Fork 0

swipeinv: new app

Inverts swipe direction globally or per app
master
Erik Andresen 2024-02-27 08:13:21 +01:00
parent cb2a321963
commit 03bf02eb22
3 changed files with 94 additions and 0 deletions

19
apps/swipeinv/boot.js Normal file
View File

@ -0,0 +1,19 @@
{
const settings = Object.assign({
global: false,
apps: []
}, require("Storage").readJSON("swipeinv.json", true) || {});
if (settings.global || settings.apps.length > 0) {
const setURIOrig = Bangle.setUI;
Bangle.setUI = (mode, callback) => {
if (typeof mode === "object" && mode.swipe) {
if (settings.global ^ settings.apps.includes(global.__FILE__)) {
const origSwipeCb = mode.swipe;
mode.swipe = (dirLR, dirUD) => origSwipeCb(dirLR*-1, dirUD*-1);
}
}
return setURIOrig(mode, callback);
};
}
}

View File

@ -0,0 +1,17 @@
{
"id": "swipeinv",
"name": "Swipe inversion",
"shortName":"Swipe inv.",
"icon": "app.png",
"version":"0.01",
"description": "Inverts swipe direction globally or per app, see settings. If global inversion is enabled, you can unselect the inversion per app and vice versa.",
"type": "bootloader",
"tags": "system",
"supports": ["BANGLEJS2"],
"storage": [
{"name":"swipeinv.boot.js","url":"boot.js"},
{"name":"swipeinv.settings.js","url":"settings.js"}
],
"data": [{"name":"swipeinv.json"}]
}

58
apps/swipeinv/settings.js Normal file
View File

@ -0,0 +1,58 @@
(function(back) {
var FILE = "swipeinv.json";
// Load settings
const settings = Object.assign({
global: false,
apps: []
}, require("Storage").readJSON(FILE, true) || {});
function writeSettings() {
require('Storage').writeJSON(FILE, settings);
}
function appMenu() {
menu = {
"" : { "title" : /*LANG*/"Swipe inversion apps" },
"< Back" : () => { writeSettings(); mainMenu();}
};
require("Storage").list(/\.info$/).map(app=>require("Storage").readJSON(app,1)).filter(app => app.type === "app" || !app.type).sort((a,b) => {
if (a.name<b.name) return -1;
if (a.name>b.name) return 1;
return 0;
}).forEach(app => {
menu[app.name] = {
value: settings.apps.includes(app.src),
onchange: v => {
if (v) {
settings.apps.push(app.src);
} else {
const idx = settings.apps.indexOf(app.src);
if (idx !== -1) {
settings.apps.splice(idx, 1);
}
}
}
};
});
E.showMenu(menu);
}
function mainMenu() {
E.showMenu({
"" : { "title" : /*LANG*/"Swipe inversion" },
"< Back" : () => back(),
/*LANG*/'Invert globally': {
value: !!settings.global,
onchange: v => {
settings.global = v;
writeSettings();
}
},
/*LANG*/'Select apps': () => appMenu()
});
}
mainMenu();
})