Skip to content

Commit

Permalink
refactor: add backgrond permission & remove experied scans
Browse files Browse the repository at this point in the history
  • Loading branch information
re2005 committed May 14, 2020
1 parent b0e33dc commit fe5b91c
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion config.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version='1.0' encoding='utf-8'?>
<widget id="app.onepointfive" version="1.0.5"
<widget id="app.onepointfive" version="1.0.6"
xmlns="http://www.w3.org/ns/widgets"
xmlns:android="http://schemas.android.com/apk/res/android">
<name short="1point5">app 1point5</name>
Expand Down
4 changes: 4 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"buefy": "^0.8.13",
"cordova-android": "^8.1.0",
"cordova-ios": "^5.1.1",
"cordova-plugin-background-mode": "git+https://bitbucket.org/TheBosZ/cordova-plugin-run-in-background.git",
"cordova-plugin-badge": "^0.8.8",
"cordova-plugin-ble-central": "^1.2.4",
"cordova-plugin-bluetoothle": "^4.5.10",
Expand Down Expand Up @@ -99,11 +100,12 @@
"cordova-plugin-open-app-settings": {},
"cordova-plugin-device": {},
"cordova-plugin-bluetoothle": {},
"cordova-plugin-local-notification": {}
"cordova-plugin-local-notification": {},
"cordova-plugin-background-mode": {}
},
"platforms": [
"android",
"ios"
]
}
}
}
9 changes: 9 additions & 0 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@
onDeviceReady() {
window.StatusBar.hide();
this.setBackgroundAndListeners();
window.cordova.plugins.backgroundMode.enable();
window.cordova.plugins.backgroundMode.setDefaults({
title: '1point5 is running on background',
text: 'Scanning for nearby devices',
icon: 'notification'
});
if (this.intro) {
window.ble.startStateNotifications(this.onInitializeBluetooth, this.onError);
Expand Down Expand Up @@ -130,6 +137,8 @@
setBackgroundAndListeners() {
document.addEventListener('pause', () => {
this.isBackground = true;
window.cordova.plugins.backgroundMode.disableBatteryOptimizations();
window.cordova.plugins.backgroundMode.disableWebViewOptimizations();
}, false);
document.addEventListener('resume', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/store/modules/device.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const mutations: MutationTree<any> = {
},
cleanDevices(state) {
state.devices.forEach((d: any, index: number) => {
if (d.timestamp + 3000 < Date.now() && !d.excluded) {
if (!d.timestamp || (d.timestamp + 3000 < Date.now() && !d.excluded)) {
state.devices.splice(index, 1);
}
});
Expand Down

0 comments on commit fe5b91c

Please sign in to comment.