Socket
Socket
Sign inDemoInstall

cordova-plugin-background-mode

Package Overview
Dependencies
0
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.7.2 to 0.7.3

src/android/BackgroundModeExt.java

11

CHANGELOG.md
## ChangeLog
#### Version 0.7.3 (07.08.2019)
This is more a "just publish all changes after long time" release.
- [___change___:] Removed code for Windows 10 Mobile
- [feature:] Check if screen is off on Android
- [feature:] Wake-up device on Android
- [feature:] Unlock device on Android
- [bugfix:] Plugin not working for Android 8
- [bugfix:] Cannot install plugin on cordova > 9
- [bugfix:] Function `onactivate` does no longer exist
#### Version 0.7.2 (02.02.2017)

@@ -3,0 +14,0 @@ - Fixed app freeze on iOS using wkwebview-engine

30

package.json
{
"name": "cordova-plugin-background-mode",
"version": "0.7.2",
"description": "Prevent app from going to sleep in background.",
"version": "0.7.3",
"description": "Prevent apps from going to sleep in background.",
"cordova": {
"id": "cordova-plugin-background-mode",
"platforms": [
"ios",
"android",
"browser"
]
},
"repository": {

@@ -12,13 +20,15 @@ "type": "git",

"background",
"cordova",
"ecosystem:cordova"
"ecosystem:cordova",
"cordova-ios",
"cordova-android",
"cordova-browser"
],
"platforms": [
"ios",
"android"
],
"engines": [
{
"name": "cordova",
"version": ">=6.0.0"
"version": ">=3.0.0"
},
{
"name": "android-sdk",
"version": ">=16"
}

@@ -32,2 +42,2 @@ ],

"homepage": "https://github.com/katzer/cordova-plugin-background-mode#readme"
}
}

@@ -50,3 +50,3 @@

```javascript
```js
document.addEventListener('deviceready', function () {

@@ -60,3 +60,3 @@ // cordova.plugins.backgroundMode is now available

```javascript
```js
cordova.plugins.backgroundMode.enable();

@@ -68,3 +68,3 @@ // or

To disable the background mode:
```javascript
```js
cordova.plugins.backgroundMode.disable();

@@ -78,3 +78,3 @@ // or

```javascript
```js
cordova.plugins.backgroundMode.isActive(); // => boolean

@@ -88,3 +88,3 @@ ```

```javascript
```js
cordova.plugins.backgroundMode.on('EVENT', function);

@@ -94,3 +94,3 @@ ```

To remove an event listeners:
```javascript
```js
cordova.plugins.backgroundMode.un('EVENT', function);

@@ -105,3 +105,3 @@ ```

```javascript
```js
cordova.plugins.backgroundMode.moveToBackground();

@@ -115,3 +115,3 @@ // or

```javascript
```js
cordova.plugins.backgroundMode.overrideBackButton();

@@ -123,6 +123,25 @@ ```

```javascript
```js
cordova.plugins.backgroundMode.excludeFromTaskList();
```
### Detect screen status
The method works async instead of _isActive()_ or _isEnabled()_.
```js
cordova.plugins.backgroundMode.isScreenOff(function(bool) {
...
});
```
### Unlock and wake-up
A wake-up turns on the screen while unlocking moves the app to foreground even the device is locked.
```js
// Turn screen on
cordova.plugins.backgroundMode.wakeUp();
// Turn screen on and show app even locked
cordova.plugins.backgroundMode.unlock();
```
### Notification

@@ -134,3 +153,3 @@ To indicate that the app is executing tasks in background and being paused would disrupt the user, the plug-in has to create a notification while in background - like a download progress bar.

```javascript
```js
cordova.plugins.backgroundMode.setDefaults({

@@ -148,3 +167,3 @@ title: String,

To modify the currently displayed notification
```javascript
```js
cordova.plugins.backgroundMode.configure({ ... });

@@ -158,4 +177,4 @@ ```

```javascript
cordova.plugins.backgroundMode.configure({ silent: true });
```js
cordova.plugins.backgroundMode.setDefaults({ silent: true });
```

@@ -168,3 +187,3 @@

```javascript
```js
cordova.plugins.backgroundMode.on('activate', function() {

@@ -193,3 +212,3 @@ cordova.plugins.backgroundMode.disableWebViewOptimizations();

© 2017 [appPlant GmbH][appplant]
? 2017 [appPlant GmbH][appplant] & [meshfields][meshfields]

@@ -203,1 +222,2 @@

[appplant]: http://appplant.de
[meshfields]: http://meshfields.de
/*
Copyright 2013-2017 appPlant GmbH
Copyright 2013 Sebastián Katzer
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/

@@ -21,0 +21,0 @@

@@ -25,7 +25,2 @@ /*

/*************
* INTERFACE *
*************/
/**

@@ -38,10 +33,11 @@ * Activates the background mode. When activated the application

*/
exports.enable = function () {
exports.enable = function()
{
if (this.isEnabled())
return;
var fn = function () {
exports._isEnabled = true;
exports.fireEvent('enable');
};
var fn = function() {
exports._isEnabled = true;
exports.fireEvent('enable');
};

@@ -57,10 +53,11 @@ cordova.exec(fn, null, 'BackgroundMode', 'enable', []);

*/
exports.disable = function () {
exports.disable = function()
{
if (!this.isEnabled())
return;
var fn = function () {
exports._isEnabled = false;
exports.fireEvent('disable');
};
var fn = function() {
exports._isEnabled = false;
exports.fireEvent('disable');
};

@@ -77,3 +74,4 @@ cordova.exec(fn, null, 'BackgroundMode', 'disable', []);

*/
exports.setEnabled = function (enable) {
exports.setEnabled = function (enable)
{
if (enable) {

@@ -91,3 +89,4 @@ this.enable();

*/
exports.getDefaults = function () {
exports.getDefaults = function()
{
return this._defaults;

@@ -97,2 +96,12 @@ };

/**
* The actual applied settings.
*
* @return [ Object ]
*/
exports.getSettings = function()
{
return this._settings || {};
};
/**
* Overwrite the default settings.

@@ -104,7 +113,10 @@ *

*/
exports.setDefaults = function (overrides) {
exports.setDefaults = function (overrides)
{
var defaults = this.getDefaults();
for (var key in defaults) {
if (overrides.hasOwnProperty(key)) {
for (var key in defaults)
{
if (overrides.hasOwnProperty(key))
{
defaults[key] = overrides[key];

@@ -114,3 +126,4 @@ }

if (this._isAndroid) {
if (this._isAndroid)
{
cordova.exec(null, null, 'BackgroundMode', 'configure', [defaults, false]);

@@ -124,12 +137,25 @@ }

*
* @param [ Object ] overrides Dict of options to be overridden.
* @param [ Object ] options Dict of options to be overridden.
*
* @return [ Void ]
*/
exports.configure = function (options) {
var settings = this.mergeWithDefaults(options);
exports.configure = function (options)
{
var settings = this.getSettings(),
defaults = this.getDefaults();
if (this._isAndroid) {
cordova.exec(null, null, 'BackgroundMode', 'configure', [settings, true]);
if (!this._isAndroid)
return;
if (!this._isActive)
{
console.log('BackgroundMode is not active, skipped...');
return;
}
this._mergeObjects(options, settings);
this._mergeObjects(options, defaults);
this._settings = options;
cordova.exec(null, null, 'BackgroundMode', 'configure', [options, true]);
};

@@ -142,5 +168,7 @@

*/
exports.disableWebViewOptimizations = function () {
if (this._isAndroid) {
cordova.exec(null, null, 'BackgroundMode', 'optimizations', []);
exports.disableWebViewOptimizations = function()
{
if (this._isAndroid)
{
cordova.exec(null, null, 'BackgroundModeExt', 'webview', []);
}

@@ -150,2 +178,32 @@ };

/**
* Disables battery optimazation mode for the app.
*
* @return [ Void ]
*/
exports.disableBatteryOptimizations = function()
{
if (this._isAndroid)
{
cordova.exec(null, null, 'BackgroundModeExt', 'battery', []);
}
};
/**
* Opens the system settings dialog where the user can tweak or turn off any
* custom app start settings added by the manufacturer if available.
*
* @param [ Object|Bool ] options Set to false if you dont want to display an
* alert dialog first.
*
* @return [ Void ]
*/
exports.openAppStartSettings = function (options)
{
if (this._isAndroid)
{
cordova.exec(null, null, 'BackgroundModeExt', 'appstart', [options]);
}
};
/**
* Move app to background (Android only).

@@ -155,5 +213,7 @@ *

*/
exports.moveToBackground = function () {
if (this._isAndroid) {
cordova.exec(null, null, 'BackgroundMode', 'background', []);
exports.moveToBackground = function()
{
if (this._isAndroid)
{
cordova.exec(null, null, 'BackgroundModeExt', 'background', []);
}

@@ -167,5 +227,7 @@ };

*/
exports.moveToForeground = function () {
if (this.isActive() && this._isAndroid) {
cordova.exec(null, null, 'BackgroundMode', 'foreground', []);
exports.moveToForeground = function()
{
if (this.isActive() && this._isAndroid)
{
cordova.exec(null, null, 'BackgroundModeExt', 'foreground', []);
}

@@ -179,5 +241,7 @@ };

*/
exports.excludeFromTaskList = function () {
if (this._isAndroid) {
cordova.exec(null, null, 'BackgroundMode', 'tasklist', []);
exports.excludeFromTaskList = function()
{
if (this._isAndroid)
{
cordova.exec(null, null, 'BackgroundModeExt', 'tasklist', []);
}

@@ -192,3 +256,4 @@ };

*/
exports.overrideBackButton = function () {
exports.overrideBackButton = function()
{
document.addEventListener('backbutton', function() {

@@ -200,2 +265,47 @@ exports.moveToBackground();

/**
* If the screen is off.
*
* @param [ Function ] fn Callback function to invoke with boolean arg.
*
* @return [ Void ]
*/
exports.isScreenOff = function (fn)
{
if (this._isAndroid)
{
cordova.exec(fn, null, 'BackgroundModeExt', 'dimmed', []);
}
else
{
fn(undefined);
}
};
/**
* Wake up the device.
*
* @return [ Void ]
*/
exports.wakeUp = function()
{
if (this._isAndroid)
{
cordova.exec(null, null, 'BackgroundModeExt', 'wakeup', []);
}
};
/**
* Wake up and unlock the device.
*
* @return [ Void ]
*/
exports.unlock = function()
{
if (this._isAndroid)
{
cordova.exec(null, null, 'BackgroundModeExt', 'unlock', []);
}
};
/**
* If the mode is enabled or disabled.

@@ -205,3 +315,4 @@ *

*/
exports.isEnabled = function () {
exports.isEnabled = function()
{
return this._isEnabled !== false;

@@ -215,11 +326,7 @@ };

*/
exports.isActive = function () {
exports.isActive = function()
{
return this._isActive !== false;
};
/**********
* EVENTS *
**********/
exports._listener = {};

@@ -235,3 +342,4 @@

*/
exports.fireEvent = function (event) {
exports.fireEvent = function (event)
{
var args = Array.apply(null, arguments).slice(1),

@@ -243,3 +351,4 @@ listener = this._listener[event];

for (var i = 0; i < listener.length; i++) {
for (var i = 0; i < listener.length; i++)
{
var fn = listener[i][0],

@@ -261,8 +370,9 @@ scope = listener[i][1];

*/
exports.on = function (event, callback, scope) {
exports.on = function (event, callback, scope)
{
if (typeof callback !== "function")
return;
if (!this._listener[event]) {
if (!this._listener[event])
{
this._listener[event] = [];

@@ -284,3 +394,4 @@ }

*/
exports.un = function (event, callback) {
exports.un = function (event, callback)
{
var listener = this._listener[event];

@@ -291,6 +402,8 @@

for (var i = 0; i < listener.length; i++) {
for (var i = 0; i < listener.length; i++)
{
var fn = listener[i][0];
if (fn == callback) {
if (fn == callback)
{
listener.splice(i, 1);

@@ -303,30 +416,32 @@ break;

/**
* @deprecated
* @private
*
* Called when the background mode has been activated.
* Flag indicates if the mode is enabled.
*/
exports.onactivate = function () {};
exports._isEnabled = false;
/**
* @deprecated
* @private
*
* Called when the background mode has been deaktivated.
* Flag indicates if the mode is active.
*/
exports.ondeactivate = function () {};
exports._isActive = false;
/**
* @deprecated
* @private
*
* Called when the background mode could not been activated.
*
* @param {Integer} errorCode
* Error code which describes the error
* Default values of all available options.
*/
exports.onfailure = function () {};
exports._defaults =
{
title: 'App is running in background',
text: 'Doing heavy tasks.',
bigText: false,
resume: true,
silent: false,
hidden: true,
color: undefined,
icon: 'icon'
};
/*********
* UTILS *
*********/
/**

@@ -338,11 +453,13 @@ * @private

* @param [ Object ] options The custom options.
* @param [ Object ] toMergeIn The options to merge in.
*
* @return [ Object ] Default values merged with custom values.
*/
exports.mergeWithDefaults = function (options) {
var defaults = this.getDefaults();
for (var key in defaults) {
if (!options.hasOwnProperty(key)) {
options[key] = defaults[key];
exports._mergeObjects = function (options, toMergeIn)
{
for (var key in toMergeIn)
{
if (!options.hasOwnProperty(key))
{
options[key] = toMergeIn[key];
continue;

@@ -358,2 +475,21 @@ }

*
* Setter for the isActive flag. Resets the
* settings if the mode isnt active anymore.
*
* @param [ Boolean] value The new value for the flag.
*
* @return [ Void ]
*/
exports._setActive = function(value)
{
if (this._isActive == value)
return;
this._isActive = value;
this._settings = value ? this._mergeObjects({}, this._defaults) : {};
};
/**
* @private
*
* Initialize the plugin.

@@ -366,7 +502,9 @@ *

*/
exports.pluginInitialize = function () {
exports._pluginInitialize = function()
{
this._isAndroid = device.platform.match(/^android|amazon/i) !== null;
this.setDefaults({});
if (device.platform == 'browser') {
if (device.platform == 'browser')
{
this.enable();

@@ -379,41 +517,7 @@ this._isEnabled = true;

/***********
* PRIVATE *
***********/
/**
* @private
*
* Flag indicates if the mode is enabled.
*/
exports._isEnabled = false;
/**
* @private
*
* Flag indicates if the mode is active.
*/
exports._isActive = false;
/**
* @private
*
* Default values of all available options.
*/
exports._defaults = {
title: 'App is running in background',
text: 'Doing heavy tasks.',
bigText: false,
resume: true,
silent: false,
hidden: true,
color: undefined,
icon: 'icon'
};
// Called before 'deviceready' listener will be called
channel.onCordovaReady.subscribe(function () {
channel.onCordovaInfoReady.subscribe(function () {
exports.pluginInitialize();
channel.onCordovaReady.subscribe(function()
{
channel.onCordovaInfoReady.subscribe(function() {
exports._pluginInitialize();
});

@@ -423,10 +527,13 @@ });

// Called after 'deviceready' event
channel.deviceready.subscribe(function () {
if (exports.isEnabled()) {
channel.deviceready.subscribe(function()
{
if (exports.isEnabled())
{
exports.fireEvent('enable');
}
if (exports.isActive()) {
if (exports.isActive())
{
exports.fireEvent('activate');
}
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc