2023-01-20 07:32:08 +00:00
|
|
|
(function () {
|
2023-01-22 08:47:48 +00:00
|
|
|
var DEFAULTS = {
|
|
|
|
mode: 0,
|
|
|
|
apps: [],
|
|
|
|
};
|
|
|
|
var settings = require("Storage").readJSON("backswipe.json", 1) || DEFAULTS;
|
2023-01-20 08:32:11 +00:00
|
|
|
|
2023-01-20 07:32:08 +00:00
|
|
|
// Overrride the default setUI method, so we can save the back button callback
|
|
|
|
var setUI = Bangle.setUI;
|
|
|
|
Bangle.setUI = function (mode, cb) {
|
|
|
|
var options = {};
|
|
|
|
if ("object"==typeof mode) {
|
|
|
|
options = mode;
|
|
|
|
}
|
|
|
|
|
2023-01-20 08:32:11 +00:00
|
|
|
var currentFile = global.__FILE__ || "";
|
|
|
|
|
2023-02-04 21:36:16 +00:00
|
|
|
if (global.BACK) delete global.BACK;
|
2023-02-05 13:25:37 +00:00
|
|
|
if (options && options.back && enabledForApp(currentFile) && !((Bangle["#onswipe"] instanceof Array)&&Bangle["#onswipe"].length>1 )) {
|
2023-01-20 07:32:08 +00:00
|
|
|
global.BACK = options.back;
|
|
|
|
}
|
|
|
|
setUI(mode, cb);
|
|
|
|
};
|
|
|
|
|
2023-02-05 13:43:43 +00:00
|
|
|
function goBack(lr, _) {
|
2023-01-20 07:32:08 +00:00
|
|
|
// 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) {
|
|
|
|
global.BACK();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-22 08:47:48 +00:00
|
|
|
// Check if the back button should be enabled for the current app
|
|
|
|
// app is the src file of the app
|
2023-01-20 08:32:11 +00:00
|
|
|
function enabledForApp(app) {
|
|
|
|
if (!settings) return true;
|
2023-01-22 08:47:48 +00:00
|
|
|
if (settings.mode === 0) {
|
|
|
|
return !(settings.apps.filter((a) => a.src === app).length > 0);
|
|
|
|
} else if (settings.mode === 1) {
|
|
|
|
return settings.apps.filter((a) => a.src === app).length > 0;
|
2023-01-20 08:32:11 +00:00
|
|
|
} else {
|
2023-01-22 08:47:48 +00:00
|
|
|
return settings.mode === 2 ? true : false;
|
2023-01-20 08:32:11 +00:00
|
|
|
}
|
|
|
|
}
|
2023-01-22 08:47:48 +00:00
|
|
|
|
2023-01-20 07:32:08 +00:00
|
|
|
// Listen to left to right swipe
|
|
|
|
Bangle.on("swipe", goBack);
|
|
|
|
})();
|