Merge pull request #2557 from thyttan/backswipe

[backswipe] check for existing swipe/drag handlers
pull/2570/head
Gordon Williams 2023-02-09 10:24:20 +00:00 committed by GitHub
commit af99384821
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 66 additions and 16 deletions

View File

@ -1 +1,2 @@
0.01: New App!
0.02: Don't fire if the app uses swipes already.

17
apps/backswipe/README.md Normal file
View File

@ -0,0 +1,17 @@
Service that allows you to use an app's back button using left to right swipe gesture.
## Settings
Mode: Blacklist/Whitelist/Always On/Disabled
App List: Black-/whitelisted apps
Standard # of swipe handlers: 0-10 (Default: 0, must be changed for backswipe to work at all)
Standard # of drag handlers: 0-10 (Default: 0, must be changed for backswipe to work at all)
Standard # of handlers settings are used to fine tune when backswipe should trigger the back function. E.g. when using a keyboard that works on drags, we don't want the backswipe to trigger when we just wanted to select a letter. This might not be able to cover all cases however.
## Creator
Kedlub
## Contributors
thyttan

View File

@ -15,18 +15,28 @@
var currentFile = global.__FILE__ || "";
if(global.BACK) delete global.BACK;
if (global.BACK) delete global.BACK;
if (options && options.back && enabledForApp(currentFile)) {
global.BACK = options.back;
}
setUI(mode, cb);
};
function goBack(lr, ud) {
function countHandlers(eventType) {
if (Bangle["#on"+eventType] === undefined) {
return 0;
} else if (Bangle["#on"+eventType] instanceof Array) {
return Bangle["#on"+eventType].length;
} else if (Bangle["#on"+eventType] !== undefined) {
return 1;
}
}
function goBack(lr, _) {
// if it is a left to right swipe
if (lr === 1) {
// if we're in an app that has a back button, run the callback for it
if (global.BACK) {
if (global.BACK && countHandlers("swipe")<=settings.standardNumSwipeHandlers && countHandlers("drag")<=settings.standardNumDragHandlers) {
global.BACK();
}
}

View File

@ -1,7 +1,7 @@
{ "id": "backswipe",
"name": "Back Swipe",
"shortName":"BackSwipe",
"version":"0.01",
"version":"0.02",
"description": "Service that allows you to use an app's back button using left to right swipe gesture",
"icon": "app.png",
"tags": "back,gesture,swipe",

View File

@ -4,19 +4,21 @@
// Apps is an array of app info objects, where all the apps that are there are either blocked or allowed, depending on the mode
var DEFAULTS = {
'mode': 0,
'apps': []
'apps': [],
'standardNumSwipeHandlers': 0,
'standardNumDragHandlers': 0
};
var settings = {};
var loadSettings = function() {
settings = require('Storage').readJSON(FILE, 1) || DEFAULTS;
}
};
var saveSettings = function(settings) {
require('Storage').write(FILE, settings);
}
};
// Get all app info files
var getApps = function() {
var apps = require('Storage').list(/\.info$/).map(appInfoFileName => {
@ -35,8 +37,8 @@
return 0;
});
return apps;
}
};
var showMenu = function() {
var menu = {
'': { 'title': 'Backswipe' },
@ -55,11 +57,31 @@
},
'App List': () => {
showAppSubMenu();
},
'Standard # of swipe handlers' : { // If more than this many handlers are present backswipe will not go back
value: 0|settings.standardNumSwipeHandlers,
min: 0,
max: 10,
format: v=>v,
onchange: v => {
settings.standardNumSwipeHandlers = v;
saveSettings(settings);
},
},
'Standard # of drag handlers' : { // If more than this many handlers are present backswipe will not go back
value: 0|settings.standardNumDragHandlers,
min: 0,
max: 10,
format: v=>v,
onchange: v => {
settings.standardNumDragHandlers = v;
saveSettings(settings);
},
}
};
E.showMenu(menu);
}
};
var showAppSubMenu = function() {
var menu = {
@ -101,4 +123,4 @@
loadSettings();
showMenu();
})
})