From a058b08d1406f616c87d400c767c573b8f27e4c3 Mon Sep 17 00:00:00 2001 From: thyttan <6uuxstm66@mozmail.com⁩> Date: Fri, 18 Apr 2025 00:18:44 +0200 Subject: [PATCH 01/18] swipeinv: wip non-working changes --- apps/swipeinv/boot.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/apps/swipeinv/boot.js b/apps/swipeinv/boot.js index fb64f920dc..9f9b2d89c1 100644 --- a/apps/swipeinv/boot.js +++ b/apps/swipeinv/boot.js @@ -1,4 +1,7 @@ { + // TODO: Should the global case just hijack the swipe and drag events, modifying them before passing on to other listeners? + // - That could be a new separate bootloader app instead though? + const settings = Object.assign({ global: false, apps: [] @@ -10,7 +13,17 @@ 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); + mode.swipe = (dirLR, dirUD) => origSwipeCb(dirLR * -1, dirUD * -1); + } + } + if (typeof mode === "object" && mode.drag) { + if (settings.global ^ settings.apps.includes(global.__FILE__)) { + const origDragCb = mode.drag; + mode.drag = (e) => { + e.dx *= -1; + e.dy *= -1; + origDragCb(e); + } } } return setURIOrig(mode, callback); From 553b5b584e9bc4ff3a6de81b2a16201025ac920c Mon Sep 17 00:00:00 2001 From: thyttan <6uuxstm66@mozmail.com⁩> Date: Mon, 21 Apr 2025 00:11:09 +0200 Subject: [PATCH 02/18] swipeinv: (WIP) Add inversion of drag events. Refactor to hijack and modify the events instead of the handling of them. This should add compatibility with most apps, even if Bangle.setUI is not used. --- apps/swipeinv/ChangeLog | 3 +++ apps/swipeinv/boot.js | 39 ++++++++++++++++++++++--------------- apps/swipeinv/metadata.json | 2 +- 3 files changed, 27 insertions(+), 17 deletions(-) diff --git a/apps/swipeinv/ChangeLog b/apps/swipeinv/ChangeLog index 62542be608..f2f321eeb8 100644 --- a/apps/swipeinv/ChangeLog +++ b/apps/swipeinv/ChangeLog @@ -1,2 +1,5 @@ 0.01: New app! 0.02: Minor code improvements +0.03: (WIP) Add inversion of drag events. Refactor to hijack and modify the + events instead of the handling of them. This should add compatibility with + most apps, even if Bangle.setUI is not used. diff --git a/apps/swipeinv/boot.js b/apps/swipeinv/boot.js index 9f9b2d89c1..51f25ab262 100644 --- a/apps/swipeinv/boot.js +++ b/apps/swipeinv/boot.js @@ -1,32 +1,39 @@ { - // TODO: Should the global case just hijack the swipe and drag events, modifying them before passing on to other listeners? - // - That could be a new separate bootloader app instead though? - 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) { + setTimeout(() => { // Timeout so we prepend listeners late, hopefully after all other listerners were added. + if (settings.global || settings.apps.length > 0) { + + let swipeInverter = (dirLR, dirUD, obj) => { if (settings.global ^ settings.apps.includes(global.__FILE__)) { - const origSwipeCb = mode.swipe; - mode.swipe = (dirLR, dirUD) => origSwipeCb(dirLR * -1, dirUD * -1); + if (!(obj && obj.inverted)) { + E.stopEventPropagation(); + obj = Object.assign({inverted:true}, obj); + + Bangle.emit("swipe", dirLR * -1, dirUD * -1, obj) + } } } - if (typeof mode === "object" && mode.drag) { + + let dragInverter = (e) => { if (settings.global ^ settings.apps.includes(global.__FILE__)) { - const origDragCb = mode.drag; - mode.drag = (e) => { + if (!e.inverted) { + E.stopEventPropagation(); + e.inverted = true; + e.dx *= -1; e.dy *= -1; - origDragCb(e); + Bangle.emit("drag", e); } } } - return setURIOrig(mode, callback); - }; - } + + Bangle.prependListener("swipe", swipeInverter); + Bangle.prependListener("drag", dragInverter); + + } + }, 0) } diff --git a/apps/swipeinv/metadata.json b/apps/swipeinv/metadata.json index 67c26a37d0..f24609e2bf 100644 --- a/apps/swipeinv/metadata.json +++ b/apps/swipeinv/metadata.json @@ -3,7 +3,7 @@ "name": "Swipe inversion", "shortName":"Swipe inv.", "icon": "app.png", - "version": "0.02", + "version": "0.03", "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.", "readme":"README.md", "type": "bootloader", From c60fb3230002816f92636a99ccdfcfa7245dbc37 Mon Sep 17 00:00:00 2001 From: thyttan <6uuxstm66@mozmail.com⁩> Date: Mon, 28 Apr 2025 22:52:54 +0200 Subject: [PATCH 03/18] swipeinv: make clocks and launchers selectable --- apps/swipeinv/settings.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/swipeinv/settings.js b/apps/swipeinv/settings.js index e32b75e60e..17c1939003 100644 --- a/apps/swipeinv/settings.js +++ b/apps/swipeinv/settings.js @@ -15,7 +15,7 @@ "" : { "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) => { + require("Storage").list(/\.info$/).map(app=>require("Storage").readJSON(app,1)).filter(app => app.type==="app" || app.type==="clock" || app.type==="launch" || !app.type).sort((a,b) => { if (a.nameb.name) return 1; return 0; From b1d48c11dee7b68f8cd6ed5498d4f8637943aae0 Mon Sep 17 00:00:00 2001 From: thyttan <6uuxstm66@mozmail.com⁩> Date: Tue, 29 Apr 2025 00:48:48 +0200 Subject: [PATCH 04/18] swipeinv: (WIP) update settings --- apps/swipeinv/settings.js | 62 +++++++++++++++++++++++++++++++++------ 1 file changed, 53 insertions(+), 9 deletions(-) diff --git a/apps/swipeinv/settings.js b/apps/swipeinv/settings.js index 17c1939003..396fbf6926 100644 --- a/apps/swipeinv/settings.js +++ b/apps/swipeinv/settings.js @@ -3,13 +3,26 @@ // Load settings const settings = Object.assign({ global: false, - apps: [] + apps: {} }, require("Storage").readJSON(FILE, true) || {}); function writeSettings() { require('Storage').writeJSON(FILE, settings); } + // Convert settings when coming from ver < 4 + function convertSettings() { + if ("array" === typeof(settings.apps)) { + let newObject = {}; + settings.apps.forEach((source)=>{ + let idExtractedFromSource = source.split(".")[0]; + newObject[idExtractedFromSource] = {}; + }) + settings.apps = newObject; + } + } + convertSettings(); + function appMenu() { let menu = { "" : { "title" : /*LANG*/"Swipe inversion apps" }, @@ -21,15 +34,14 @@ return 0; }).forEach(app => { menu[app.name] = { - value: settings.apps.includes(app.src), + value: settings.apps.keys().includes(app.id), onchange: v => { if (v) { - settings.apps.push(app.src); + if (!settings.apps[app.id] || settings.apps[app.id].keys().length===0) { + settings.apps[app.id] = {"swipeH":true, "swipeV":true, "dragH":true, "dragV":true}; + } } else { - const idx = settings.apps.indexOf(app.src); - if (idx !== -1) { - settings.apps.splice(idx, 1); - } + if (settings.apps[app.id]) {delete settings.apps[app.id];} } } }; @@ -38,7 +50,7 @@ } function mainMenu() { - E.showMenu({ + let menu = { "" : { "title" : /*LANG*/"Swipe inversion" }, "< Back" : () => back(), @@ -50,8 +62,40 @@ } }, - /*LANG*/'Select apps': () => appMenu() + /*LANG*/'Select apps': () => appMenu(), + }; + + if (!settings.appTune) {settings.appTune = {};} + + settings.apps.forEach((appSrc,index,array) => { + // Create a sub menu and show it. + let subMenu = { + "" : { "title" : /*LANG*/"Tune"+" "+appSrc }, + "< Back" : () => { writeSettings(); mainMenu();} + } + let entries = [{name:"Swipe Horizontal", id:"swipeH"}, {name:"Swipe Vertical", id:"swipeV"}, {name:"Drag Horizontal", id:"dragH"}, {name:"Drag Vertical", id:"dragV"}]; + entries.forEach((setting, index, array)=>{ + if (!settings.appTune[app[setting.id]) {settings.appTune[settings.id] = } + subMenu[setting.name] = { + value: settings.appTune.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); + } + } + } + }; + + }) + + menu[appSrc] = ()=>E.showMenu(subMenu); }); + + E.showMenu(menu); } mainMenu(); From 0d1130ed400f3f9833663d03673558a35bd74c49 Mon Sep 17 00:00:00 2001 From: thyttan <6uuxstm66@mozmail.com⁩> Date: Thu, 1 May 2025 00:26:25 +0200 Subject: [PATCH 05/18] swipeinv: (wip) continue working --- apps/swipeinv/settings.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/swipeinv/settings.js b/apps/swipeinv/settings.js index 396fbf6926..2dcb594131 100644 --- a/apps/swipeinv/settings.js +++ b/apps/swipeinv/settings.js @@ -67,7 +67,7 @@ if (!settings.appTune) {settings.appTune = {};} - settings.apps.forEach((appSrc,index,array) => { + settings.apps.forEach((appID,index,array) => { // Create a sub menu and show it. let subMenu = { "" : { "title" : /*LANG*/"Tune"+" "+appSrc }, @@ -75,9 +75,9 @@ } let entries = [{name:"Swipe Horizontal", id:"swipeH"}, {name:"Swipe Vertical", id:"swipeV"}, {name:"Drag Horizontal", id:"dragH"}, {name:"Drag Vertical", id:"dragV"}]; entries.forEach((setting, index, array)=>{ - if (!settings.appTune[app[setting.id]) {settings.appTune[settings.id] = } + if (!settings.apps.keys().includes(appID)) {settings.apps.[settings.id] = } subMenu[setting.name] = { - value: settings.appTune.includes(app.src), + value: settings.apps.keys().includes(appID), onchange: v => { if (v) { settings.apps.push(app.src); From 92a218ea41919806942ea70f28f46c3018752f47 Mon Sep 17 00:00:00 2001 From: thyttan <6uuxstm66@mozmail.com⁩> Date: Thu, 1 May 2025 21:22:29 +0200 Subject: [PATCH 06/18] swipeinv: (wip) maybe finalized settings, tweak boot --- apps/swipeinv/boot.js | 16 +++++++++++----- apps/swipeinv/settings.js | 38 ++++++++++++++++---------------------- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/apps/swipeinv/boot.js b/apps/swipeinv/boot.js index 51f25ab262..6e4d4ce25c 100644 --- a/apps/swipeinv/boot.js +++ b/apps/swipeinv/boot.js @@ -4,28 +4,34 @@ apps: [] }, require("Storage").readJSON("swipeinv.json", true) || {}); + let getAppIdFromSrc = ()=> { return global.__FILE__.split(".")[0]; } + setTimeout(() => { // Timeout so we prepend listeners late, hopefully after all other listerners were added. if (settings.global || settings.apps.length > 0) { let swipeInverter = (dirLR, dirUD, obj) => { - if (settings.global ^ settings.apps.includes(global.__FILE__)) { + if (settings.global ^ Object.keys(settings.apps).includes(getAppIdFromSrc())) { if (!(obj && obj.inverted)) { E.stopEventPropagation(); obj = Object.assign({inverted:true}, obj); - Bangle.emit("swipe", dirLR * -1, dirUD * -1, obj) + if (settings.global ^ settings.apps[getAppIdFromSrc].swipeH) {dirLR *= -1;} + if (settings.global ^ settings.apps[getAppIdFromSrc].swipeV) {dirUD *= -1;} + + Bangle.emit("swipe", dirLR, dirUD, obj) } } } let dragInverter = (e) => { - if (settings.global ^ settings.apps.includes(global.__FILE__)) { + if (settings.global ^ Object.keys(settings.apps).includes(getAppIdFromSrc())) { if (!e.inverted) { E.stopEventPropagation(); e.inverted = true; - e.dx *= -1; - e.dy *= -1; + if (settings.global ^ settings.apps[getAppIdFromSrc].dragH) {e.dx *= -1;} + if (settings.global ^ settings.apps[getAppIdFromSrc].dragV) {e.dy *= -1;} + Bangle.emit("drag", e); } } diff --git a/apps/swipeinv/settings.js b/apps/swipeinv/settings.js index 2dcb594131..387f7115ff 100644 --- a/apps/swipeinv/settings.js +++ b/apps/swipeinv/settings.js @@ -11,17 +11,17 @@ } // Convert settings when coming from ver < 4 - function convertSettings() { - if ("array" === typeof(settings.apps)) { + function convertAppsArrayToObject() { + if (Array.isArray(settings.apps)) { let newObject = {}; settings.apps.forEach((source)=>{ - let idExtractedFromSource = source.split(".")[0]; + let idExtractedFromSource = source.split(".")[0]; newObject[idExtractedFromSource] = {}; }) settings.apps = newObject; } } - convertSettings(); + convertAppsArrayToObject(); function appMenu() { let menu = { @@ -34,10 +34,10 @@ return 0; }).forEach(app => { menu[app.name] = { - value: settings.apps.keys().includes(app.id), + value: Object.keys(settings.apps).includes(app.id), onchange: v => { if (v) { - if (!settings.apps[app.id] || settings.apps[app.id].keys().length===0) { + if (!settings.apps[app.id] || Object.keys(settings.apps[app.id]).length===0) { settings.apps[app.id] = {"swipeH":true, "swipeV":true, "dragH":true, "dragV":true}; } } else { @@ -65,38 +65,32 @@ /*LANG*/'Select apps': () => appMenu(), }; - if (!settings.appTune) {settings.appTune = {};} - - settings.apps.forEach((appID,index,array) => { + Object.keys(settings.apps).forEach((appID) => { // Create a sub menu and show it. let subMenu = { - "" : { "title" : /*LANG*/"Tune"+" "+appSrc }, + "" : { "title" : /*LANG*/"Tune"+" "+appID }, "< Back" : () => { writeSettings(); mainMenu();} } - let entries = [{name:"Swipe Horizontal", id:"swipeH"}, {name:"Swipe Vertical", id:"swipeV"}, {name:"Drag Horizontal", id:"dragH"}, {name:"Drag Vertical", id:"dragV"}]; - entries.forEach((setting, index, array)=>{ - if (!settings.apps.keys().includes(appID)) {settings.apps.[settings.id] = } + let subMenuEntries = [{name:"Swipe Horizontal", id:"swipeH"}, {name:"Swipe Vertical", id:"swipeV"}, {name:"Drag Horizontal", id:"dragH"}, {name:"Drag Vertical", id:"dragV"}]; + subMenuEntries.forEach((setting)=>{ + if (!Object.keys(settings.apps).includes(appID)) {settings.apps[appID] = {"swipeH":true, "swipeV":true, "dragH":true, "dragV":true}} subMenu[setting.name] = { - value: settings.apps.keys().includes(appID), + value: settings.apps[appID][setting.id], onchange: v => { if (v) { - settings.apps.push(app.src); + settings.apps[appID][setting.id] = true; } else { - const idx = settings.apps.indexOf(app.src); - if (idx !== -1) { - settings.apps.splice(idx, 1); - } + settings.apps[appID][setting.id] = false; } } }; - }) - menu[appSrc] = ()=>E.showMenu(subMenu); + menu[appID] = ()=>E.showMenu(subMenu); }); E.showMenu(menu); } mainMenu(); -}) +})(()=>{}) // Call with empty back fn when developing. From c2059ff204e54fc930afbe2cefedeced42307408 Mon Sep 17 00:00:00 2001 From: thyttan <6uuxstm66@mozmail.com⁩> Date: Thu, 1 May 2025 21:36:33 +0200 Subject: [PATCH 07/18] swipeinv: amend ChangeLog --- apps/swipeinv/ChangeLog | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/apps/swipeinv/ChangeLog b/apps/swipeinv/ChangeLog index f2f321eeb8..5e1fc879ee 100644 --- a/apps/swipeinv/ChangeLog +++ b/apps/swipeinv/ChangeLog @@ -1,5 +1,6 @@ 0.01: New app! 0.02: Minor code improvements -0.03: (WIP) Add inversion of drag events. Refactor to hijack and modify the - events instead of the handling of them. This should add compatibility with - most apps, even if Bangle.setUI is not used. +0.03: (WIP) Add inversion of drag events. Add per app, per direction setting. + Refactor to hijack and modify the events instead of the handling of them. + This should add compatibility with most apps, even if Bangle.setUI is not + used. From cef20788e947f7a21fa1f0eae41a7eb8168512d2 Mon Sep 17 00:00:00 2001 From: thyttan <6uuxstm66@mozmail.com⁩> Date: Thu, 1 May 2025 21:45:42 +0200 Subject: [PATCH 08/18] swipeinv: drop development back fn --- apps/swipeinv/settings.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/swipeinv/settings.js b/apps/swipeinv/settings.js index 387f7115ff..a4d841e423 100644 --- a/apps/swipeinv/settings.js +++ b/apps/swipeinv/settings.js @@ -93,4 +93,4 @@ } mainMenu(); -})(()=>{}) // Call with empty back fn when developing. +}) From 6d9c85d4405dda55ebb466a97135fc4fa44ecbeb Mon Sep 17 00:00:00 2001 From: thyttan <6uuxstm66@mozmail.com⁩> Date: Thu, 1 May 2025 23:55:35 +0200 Subject: [PATCH 09/18] swipeinv: read number of set apps correctly --- apps/swipeinv/boot.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/apps/swipeinv/boot.js b/apps/swipeinv/boot.js index 6e4d4ce25c..907f1bdb36 100644 --- a/apps/swipeinv/boot.js +++ b/apps/swipeinv/boot.js @@ -4,10 +4,12 @@ apps: [] }, require("Storage").readJSON("swipeinv.json", true) || {}); - let getAppIdFromSrc = ()=> { return global.__FILE__.split(".")[0]; } + let getAppIdFromSrc = ()=> { + return global.__FILE__ && global.__FILE__.split(".")[0]; + } setTimeout(() => { // Timeout so we prepend listeners late, hopefully after all other listerners were added. - if (settings.global || settings.apps.length > 0) { + if (settings.global || Object.keys(settings.apps).length > 0) { let swipeInverter = (dirLR, dirUD, obj) => { if (settings.global ^ Object.keys(settings.apps).includes(getAppIdFromSrc())) { @@ -15,8 +17,8 @@ E.stopEventPropagation(); obj = Object.assign({inverted:true}, obj); - if (settings.global ^ settings.apps[getAppIdFromSrc].swipeH) {dirLR *= -1;} - if (settings.global ^ settings.apps[getAppIdFromSrc].swipeV) {dirUD *= -1;} + if (settings.global ^ (settings.apps[getAppIdFromSrc()]&&settings.apps[getAppIdFromSrc()].swipeH)) {dirLR *= -1;} + if (settings.global ^ (settings.apps[getAppIdFromSrc()]&&settings.apps[getAppIdFromSrc()].swipeV)) {dirUD *= -1;} Bangle.emit("swipe", dirLR, dirUD, obj) } @@ -29,8 +31,8 @@ E.stopEventPropagation(); e.inverted = true; - if (settings.global ^ settings.apps[getAppIdFromSrc].dragH) {e.dx *= -1;} - if (settings.global ^ settings.apps[getAppIdFromSrc].dragV) {e.dy *= -1;} + if (settings.global ^ (settings.apps[getAppIdFromSrc()]&&settings.apps[getAppIdFromSrc()].dragH)) {e.dx *= -1;} + if (settings.global ^ (settings.apps[getAppIdFromSrc()]&&settings.apps[getAppIdFromSrc()].dragV)) {e.dy *= -1;} Bangle.emit("drag", e); } From 90cc1e12e2f14be7f08dca480dc382d89455cab3 Mon Sep 17 00:00:00 2001 From: thyttan <6uuxstm66@mozmail.com⁩> Date: Fri, 2 May 2025 00:31:59 +0200 Subject: [PATCH 10/18] swipeinv: fix name of settings apps entries --- apps/swipeinv/settings.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/swipeinv/settings.js b/apps/swipeinv/settings.js index a4d841e423..f97ebaa4fd 100644 --- a/apps/swipeinv/settings.js +++ b/apps/swipeinv/settings.js @@ -38,7 +38,7 @@ onchange: v => { if (v) { if (!settings.apps[app.id] || Object.keys(settings.apps[app.id]).length===0) { - settings.apps[app.id] = {"swipeH":true, "swipeV":true, "dragH":true, "dragV":true}; + settings.apps[app.id] = {"name":app.name, "swipeH":true, "swipeV":true, "dragH":true, "dragV":true}; } } else { if (settings.apps[app.id]) {delete settings.apps[app.id];} @@ -86,7 +86,7 @@ }; }) - menu[appID] = ()=>E.showMenu(subMenu); + menu[settings.apps[appID].name] = ()=>E.showMenu(subMenu); }); E.showMenu(menu); From 9e7bee6be4624c1c6c0b6fbb1c4c6f992550831e Mon Sep 17 00:00:00 2001 From: thyttan <6uuxstm66@mozmail.com⁩> Date: Fri, 2 May 2025 01:07:18 +0200 Subject: [PATCH 11/18] swipeinv: handle special cases of global.__FILE__ --- apps/swipeinv/boot.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/swipeinv/boot.js b/apps/swipeinv/boot.js index 907f1bdb36..4a473dcba8 100644 --- a/apps/swipeinv/boot.js +++ b/apps/swipeinv/boot.js @@ -5,7 +5,9 @@ }, require("Storage").readJSON("swipeinv.json", true) || {}); let getAppIdFromSrc = ()=> { - return global.__FILE__ && global.__FILE__.split(".")[0]; + if (!global.__FILE__ || global.__FILE__===".bootcde") { + return require("Storage").readJSON("setting.json",true).clock + } else {return global.__FILE__.split(".")[0];} } setTimeout(() => { // Timeout so we prepend listeners late, hopefully after all other listerners were added. From a08c47e4e1362dfdb48693060644a5a0a68401c8 Mon Sep 17 00:00:00 2001 From: thyttan <6uuxstm66@mozmail.com⁩> Date: Fri, 2 May 2025 23:37:49 +0200 Subject: [PATCH 12/18] swipeinv: add "ram" keyword to speed things up --- apps/swipeinv/boot.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/apps/swipeinv/boot.js b/apps/swipeinv/boot.js index 4a473dcba8..9377f01e78 100644 --- a/apps/swipeinv/boot.js +++ b/apps/swipeinv/boot.js @@ -5,6 +5,7 @@ }, require("Storage").readJSON("swipeinv.json", true) || {}); let getAppIdFromSrc = ()=> { + "ram" if (!global.__FILE__ || global.__FILE__===".bootcde") { return require("Storage").readJSON("setting.json",true).clock } else {return global.__FILE__.split(".")[0];} @@ -14,6 +15,7 @@ if (settings.global || Object.keys(settings.apps).length > 0) { let swipeInverter = (dirLR, dirUD, obj) => { + "ram" if (settings.global ^ Object.keys(settings.apps).includes(getAppIdFromSrc())) { if (!(obj && obj.inverted)) { E.stopEventPropagation(); @@ -28,6 +30,7 @@ } let dragInverter = (e) => { + "ram" if (settings.global ^ Object.keys(settings.apps).includes(getAppIdFromSrc())) { if (!e.inverted) { E.stopEventPropagation(); From 30654c6de90b2c6f7cda96c2ce7302ffde8590b5 Mon Sep 17 00:00:00 2001 From: thyttan <6uuxstm66@mozmail.com⁩> Date: Sun, 4 May 2025 15:42:49 +0200 Subject: [PATCH 13/18] swipeinv: update TODO in README --- apps/swipeinv/README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/apps/swipeinv/README.md b/apps/swipeinv/README.md index 389c4bb6eb..22da8bae41 100644 --- a/apps/swipeinv/README.md +++ b/apps/swipeinv/README.md @@ -10,10 +10,11 @@ Swiping behavior that uses the `drag` event is not altered either. ## TODO -- Try to handle swipes from `Bangle.on("swipe", ...)` - - alternatively refactor apps using that to only use `Bangle.setUI` for setting up swipes. - - Think about how to accommodate e.g. `touch` or `back` handlers set up in `Layout` library calls. They are removed if we refactor some `Bangle.on("swipe", ...)` to `Bangle.setUI`. (Is it maybe resolved if we call `Bangle.setUI` before the `Layout` call? - have not tested that yet.) - Add bootloader apps and widgets to the list of apps that can be individually toggled in settings? + - How? Right now we look at `global.__FILE__` the active app in order to determine which events to invert. That doesn't work for widgets and bootcode. In fact they will probably be inverted along with the currently running app. +- Refactor to invert at time of registering the event listeners? + - This would make it so `swipeinv` does not depend on being first in the call list of event listeners. + - Some work towards this was done in [thyttan@5cbb72e](https://github.com/thyttan/BangleApps/commit/5cbb72ee55f7fb7d335ffba228575a862a0ae612) but it it doesn't work yet. ## Requests From bfb8c93da30ec5e24ad9b29c09df82671113f233 Mon Sep 17 00:00:00 2001 From: thyttan <6uuxstm66@mozmail.com⁩> Date: Sun, 4 May 2025 15:47:01 +0200 Subject: [PATCH 14/18] swipeinv: README typos and contributor note --- apps/swipeinv/README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/apps/swipeinv/README.md b/apps/swipeinv/README.md index 22da8bae41..8d02834afc 100644 --- a/apps/swipeinv/README.md +++ b/apps/swipeinv/README.md @@ -11,10 +11,11 @@ Swiping behavior that uses the `drag` event is not altered either. ## TODO - Add bootloader apps and widgets to the list of apps that can be individually toggled in settings? - - How? Right now we look at `global.__FILE__` the active app in order to determine which events to invert. That doesn't work for widgets and bootcode. In fact they will probably be inverted along with the currently running app. + - How? Right now we look at `global.__FILE__` to find the active app in order to determine which events to invert. That doesn't work for widgets and bootcode. + - In fact they will probably be inverted along with the currently running app. - Refactor to invert at time of registering the event listeners? - This would make it so `swipeinv` does not depend on being first in the call list of event listeners. - - Some work towards this was done in [thyttan@5cbb72e](https://github.com/thyttan/BangleApps/commit/5cbb72ee55f7fb7d335ffba228575a862a0ae612) but it it doesn't work yet. + - Some work towards this was done in [thyttan@5cbb72e](https://github.com/thyttan/BangleApps/commit/5cbb72ee55f7fb7d335ffba228575a862a0ae612) but it doesn't work yet. ## Requests @@ -26,3 +27,4 @@ nxdefiant ## Contributors +thyttan From 4696b43c93f9c3c25aabca24c0b3a8bfa21d78b9 Mon Sep 17 00:00:00 2001 From: thyttan <6uuxstm66@mozmail.com⁩> Date: Sun, 4 May 2025 16:28:05 +0200 Subject: [PATCH 15/18] swipeinv: look up filename less often --- apps/swipeinv/boot.js | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/apps/swipeinv/boot.js b/apps/swipeinv/boot.js index 9377f01e78..b65f8006b1 100644 --- a/apps/swipeinv/boot.js +++ b/apps/swipeinv/boot.js @@ -4,10 +4,11 @@ apps: [] }, require("Storage").readJSON("swipeinv.json", true) || {}); - let getAppIdFromSrc = ()=> { - "ram" + const clockAppID = require("Storage").readJSON("setting.json",true).clock.split(".")[0]; + + let getAppIdFromCurrentFile = ()=> { if (!global.__FILE__ || global.__FILE__===".bootcde") { - return require("Storage").readJSON("setting.json",true).clock + return clockAppID; } else {return global.__FILE__.split(".")[0];} } @@ -16,13 +17,14 @@ let swipeInverter = (dirLR, dirUD, obj) => { "ram" - if (settings.global ^ Object.keys(settings.apps).includes(getAppIdFromSrc())) { + const appID = getAppIdFromCurrentFile(); + if (settings.global ^ Object.keys(settings.apps).includes(appID)) { if (!(obj && obj.inverted)) { E.stopEventPropagation(); obj = Object.assign({inverted:true}, obj); - if (settings.global ^ (settings.apps[getAppIdFromSrc()]&&settings.apps[getAppIdFromSrc()].swipeH)) {dirLR *= -1;} - if (settings.global ^ (settings.apps[getAppIdFromSrc()]&&settings.apps[getAppIdFromSrc()].swipeV)) {dirUD *= -1;} + if (settings.global ^ (settings.apps[appID]&&settings.apps[appID].swipeH)) {dirLR *= -1;} + if (settings.global ^ (settings.apps[appID]&&settings.apps[appID].swipeV)) {dirUD *= -1;} Bangle.emit("swipe", dirLR, dirUD, obj) } @@ -31,13 +33,14 @@ let dragInverter = (e) => { "ram" - if (settings.global ^ Object.keys(settings.apps).includes(getAppIdFromSrc())) { + const appID = getAppIdFromCurrentFile(); + if (settings.global ^ Object.keys(settings.apps).includes(appID)) { if (!e.inverted) { E.stopEventPropagation(); e.inverted = true; - if (settings.global ^ (settings.apps[getAppIdFromSrc()]&&settings.apps[getAppIdFromSrc()].dragH)) {e.dx *= -1;} - if (settings.global ^ (settings.apps[getAppIdFromSrc()]&&settings.apps[getAppIdFromSrc()].dragV)) {e.dy *= -1;} + if (settings.global ^ (settings.apps[appID]&&settings.apps[appID].dragH)) {e.dx *= -1;} + if (settings.global ^ (settings.apps[appID]&&settings.apps[appID].dragV)) {e.dy *= -1;} Bangle.emit("drag", e); } From 20321056edf8dbbb2eef42b5c886e9bcf770e88c Mon Sep 17 00:00:00 2001 From: thyttan <6uuxstm66@mozmail.com⁩> Date: Sun, 4 May 2025 16:30:31 +0200 Subject: [PATCH 16/18] swipeinv: adhere to code style guide re consts --- apps/swipeinv/boot.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/apps/swipeinv/boot.js b/apps/swipeinv/boot.js index b65f8006b1..6e7e958bde 100644 --- a/apps/swipeinv/boot.js +++ b/apps/swipeinv/boot.js @@ -1,30 +1,30 @@ { - const settings = Object.assign({ + const SETTINGS = Object.assign({ global: false, apps: [] }, require("Storage").readJSON("swipeinv.json", true) || {}); - const clockAppID = require("Storage").readJSON("setting.json",true).clock.split(".")[0]; + const CLOCK_APP_ID = require("Storage").readJSON("setting.json",true).clock.split(".")[0]; let getAppIdFromCurrentFile = ()=> { if (!global.__FILE__ || global.__FILE__===".bootcde") { - return clockAppID; + return CLOCK_APP_ID; } else {return global.__FILE__.split(".")[0];} } setTimeout(() => { // Timeout so we prepend listeners late, hopefully after all other listerners were added. - if (settings.global || Object.keys(settings.apps).length > 0) { + if (SETTINGS.global || Object.keys(SETTINGS.apps).length > 0) { let swipeInverter = (dirLR, dirUD, obj) => { "ram" - const appID = getAppIdFromCurrentFile(); - if (settings.global ^ Object.keys(settings.apps).includes(appID)) { + const APP_ID = getAppIdFromCurrentFile(); + if (SETTINGS.global ^ Object.keys(SETTINGS.apps).includes(APP_ID)) { if (!(obj && obj.inverted)) { E.stopEventPropagation(); obj = Object.assign({inverted:true}, obj); - if (settings.global ^ (settings.apps[appID]&&settings.apps[appID].swipeH)) {dirLR *= -1;} - if (settings.global ^ (settings.apps[appID]&&settings.apps[appID].swipeV)) {dirUD *= -1;} + if (SETTINGS.global ^ (SETTINGS.apps[APP_ID]&&SETTINGS.apps[APP_ID].swipeH)) {dirLR *= -1;} + if (SETTINGS.global ^ (SETTINGS.apps[APP_ID]&&SETTINGS.apps[APP_ID].swipeV)) {dirUD *= -1;} Bangle.emit("swipe", dirLR, dirUD, obj) } @@ -33,14 +33,14 @@ let dragInverter = (e) => { "ram" - const appID = getAppIdFromCurrentFile(); - if (settings.global ^ Object.keys(settings.apps).includes(appID)) { + const APP_ID = getAppIdFromCurrentFile(); + if (SETTINGS.global ^ Object.keys(SETTINGS.apps).includes(APP_ID)) { if (!e.inverted) { E.stopEventPropagation(); e.inverted = true; - if (settings.global ^ (settings.apps[appID]&&settings.apps[appID].dragH)) {e.dx *= -1;} - if (settings.global ^ (settings.apps[appID]&&settings.apps[appID].dragV)) {e.dy *= -1;} + if (SETTINGS.global ^ (SETTINGS.apps[APP_ID]&&SETTINGS.apps[APP_ID].dragH)) {e.dx *= -1;} + if (SETTINGS.global ^ (SETTINGS.apps[APP_ID]&&SETTINGS.apps[APP_ID].dragV)) {e.dy *= -1;} Bangle.emit("drag", e); } From b6039de2483ea6b684535a03b14c83f8846ec2c6 Mon Sep 17 00:00:00 2001 From: thyttan <6uuxstm66@mozmail.com⁩> Date: Sun, 4 May 2025 17:05:40 +0200 Subject: [PATCH 17/18] swipeinv: add ram keyword to helper fn --- apps/swipeinv/boot.js | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/swipeinv/boot.js b/apps/swipeinv/boot.js index 6e7e958bde..bcb8ac6380 100644 --- a/apps/swipeinv/boot.js +++ b/apps/swipeinv/boot.js @@ -7,6 +7,7 @@ const CLOCK_APP_ID = require("Storage").readJSON("setting.json",true).clock.split(".")[0]; let getAppIdFromCurrentFile = ()=> { + "ram" if (!global.__FILE__ || global.__FILE__===".bootcde") { return CLOCK_APP_ID; } else {return global.__FILE__.split(".")[0];} From 5b494c1a0d6e69175f14ae74d146338e2882b589 Mon Sep 17 00:00:00 2001 From: thyttan <6uuxstm66@mozmail.com⁩> Date: Sun, 4 May 2025 17:14:18 +0200 Subject: [PATCH 18/18] swipeinv: update README --- apps/swipeinv/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/swipeinv/README.md b/apps/swipeinv/README.md index 8d02834afc..302bc169e8 100644 --- a/apps/swipeinv/README.md +++ b/apps/swipeinv/README.md @@ -2,11 +2,11 @@ Inverts swipe direction globally or per app, see settings. If global inversion is enabled, you can unselect the inversion per app and vice versa. -## Limitations +Can invert swipe as well as drag events. This can be fine tuned for each inverted app in the settings. -Swipe Inversion can only invert directions on apps that use `Bangle.setUI` to set up swipes. Swipes set up with `Bangle.on("swipe", ...)` is currently not managed. +## Limitations -Swiping behavior that uses the `drag` event is not altered either. +Swipe Inversion must sit before other swipe and drag event listeners so they don't run before the event is inverted. If a listener were to be prepended to the list of listeners after Swipe Inversion was, that listener will act on the non-inverted event. ## TODO