diff --git a/apps/swipeinv/app.png b/apps/swipeinv/app.png new file mode 100644 index 000000000..a23f71111 Binary files /dev/null and b/apps/swipeinv/app.png differ diff --git a/apps/swipeinv/boot.js b/apps/swipeinv/boot.js new file mode 100644 index 000000000..fb64f920d --- /dev/null +++ b/apps/swipeinv/boot.js @@ -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); + }; + } +} diff --git a/apps/swipeinv/metadata.json b/apps/swipeinv/metadata.json new file mode 100644 index 000000000..32619b916 --- /dev/null +++ b/apps/swipeinv/metadata.json @@ -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"}] +} + diff --git a/apps/swipeinv/settings.js b/apps/swipeinv/settings.js new file mode 100644 index 000000000..6ce16d00a --- /dev/null +++ b/apps/swipeinv/settings.js @@ -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.nameb.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(); +})