Add wakelock feature
This commit is contained in:
parent
1e0b435064
commit
a429277009
@ -15,7 +15,8 @@
|
||||
"cordova": {
|
||||
"plugins": {
|
||||
"cordova-plugin-geolocation": {},
|
||||
"cordova-plugin-whitelist": {}
|
||||
"cordova-plugin-whitelist": {},
|
||||
"at.gofg.sportscomputer.powermanagement": {}
|
||||
},
|
||||
"platforms": [
|
||||
"android"
|
||||
@ -23,6 +24,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"cordova-android": "^8.0.0",
|
||||
"cordova-plugin-powermanagement-orig": "git+https://github.com/boltex/cordova-plugin-powermanagement.git",
|
||||
"cordova-plugin-whitelist": "^1.3.4"
|
||||
}
|
||||
}
|
@ -73,7 +73,19 @@ function initCordova() {
|
||||
}, false);
|
||||
|
||||
document.addEventListener("deviceready", function () {
|
||||
|
||||
if (localStorage.getItem("wakelock") == "true") {
|
||||
window.powerManagement.dim(function () {
|
||||
console.log('Partial wakelock acquired');
|
||||
}, function () {
|
||||
console.log('Failed to acquire partial wakelock');
|
||||
});
|
||||
} else {
|
||||
window.powerManagement.release(function () {
|
||||
console.log('Wakelock released');
|
||||
}, function () {
|
||||
console.log('Failed to release wakelock');
|
||||
});
|
||||
}
|
||||
}, false);
|
||||
|
||||
openBrowser = function (url) {
|
||||
|
@ -17,6 +17,35 @@ $('.item-content[data-setting=darktheme] .toggle input').on("change", function (
|
||||
}
|
||||
});
|
||||
|
||||
$('.item-content[data-setting=wakelock] .toggle input').on("change", function () {
|
||||
var checked = $(this).prop('checked');
|
||||
console.log(checked);
|
||||
localStorage.setItem("wakelock", checked);
|
||||
|
||||
if (platform_type == "cordova") {
|
||||
if (localStorage.getItem("wakelock") == "true") {
|
||||
window.powerManagement.dim(function () {
|
||||
console.log('Partial wakelock acquired');
|
||||
}, function () {
|
||||
console.log('Failed to acquire partial wakelock');
|
||||
});
|
||||
} else {
|
||||
window.powerManagement.release(function () {
|
||||
console.log('Wakelock released');
|
||||
}, function () {
|
||||
console.log('Failed to release wakelock');
|
||||
});
|
||||
}
|
||||
} else {
|
||||
app.toast.show({
|
||||
text: "This setting won't do anything on your device.",
|
||||
position: "bottom",
|
||||
destroyOnClose: true,
|
||||
closeTimeout: 1000 * 10
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
function pickAlertSound() {
|
||||
var currentalertsound = localStorage.getItem("alertsound");
|
||||
app.dialog.create({
|
||||
@ -91,7 +120,7 @@ function pickMapSource() {
|
||||
mapsource = "offline";
|
||||
}
|
||||
localStorage.setItem("mapsource", mapsource);
|
||||
|
||||
|
||||
}
|
||||
}).open();
|
||||
}
|
@ -81,10 +81,18 @@ var routes = [
|
||||
text: "Select which sound to play when a package is nearby.",
|
||||
onclick: "pickAlertSound()"
|
||||
},
|
||||
{
|
||||
setting: "wakelock",
|
||||
title: "Keep screen on",
|
||||
text: "Improves GPS accuracy and alert sound reliability, but uses more battery.",
|
||||
toggle: true,
|
||||
checked: localStorage.getItem("wakelock") == "true",
|
||||
onclick: ""
|
||||
},
|
||||
{
|
||||
setting: "darktheme",
|
||||
title: "Use dark theme",
|
||||
text: "",
|
||||
text: "Saves power on phones with OLED screens.",
|
||||
toggle: true,
|
||||
checked: localStorage.getItem("darktheme") == "true",
|
||||
onclick: ""
|
||||
|
Loading…
x
Reference in New Issue
Block a user