From fc6e6cf51dae23742d69efda37cc79f05b5ec011 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Katzer?= Date: Sun, 14 Dec 2014 13:52:38 +0100 Subject: [PATCH] Receive if the background mode is enabled --- CHANGELOG.md | 3 ++- README.md | 15 ++++++++++++--- www/background-mode.js | 18 ++++++++++++++++++ 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a34e7fd..a6bc52b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,15 +1,16 @@ ## ChangeLog #### Version 0.6.1 (not yet released) - [enhancement:] Set default settings through `setDefaults`. +- [enhancement:] New method `isEnabled` - [bugfix:] Events caused thread collision. #### Version 0.6.0 (14.12.2014) - [feature:] Android support -- [feature:] Get default settings through `getDefaults`. - [feature:] Change Android notification through `configure`. - [feature:] `onactivate`, `ondeactivate` and `onfailure` callbacks. - [___change___:] Disabled by default +- [enhancement:] Get default settings through `getDefaults`. - [enhancement:] iOS does not require user permissions, internet connection and geo location anymore. #### Version 0.5.0 (13.02.2014) diff --git a/README.md b/README.md index 2ad5f7e..b87392b 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ cordova plugin rm de.appplant.cordova.plugin.background-mode ### PhoneGap Build Add the following xml to your config.xml to always use the latest version of this plugin: ```xml - + ``` More informations can be found [here][PGB_plugin]. @@ -69,8 +69,9 @@ More informations can be found [here][PGB_plugin]. ## ChangeLog #### Version 0.6.1 (not yet released) -- [feature:] Get default settings through `getDefaults`. -- [feature:] Set default settings through `setDefaults`. +- [enhancement:] Set default settings through `setDefaults`. +- [enhancement:] New method `isEnabled` +- [bugfix:] Events caused thread collision. #### Further informations - The former `plugin.backgroundMode` namespace has been deprecated and will be removed with the next major release. @@ -85,6 +86,7 @@ The plugin creates the object ```cordova.plugins.backgroundMode``` with the fol 1. [backgroundMode.enable][enable] 2. [backgroundMode.disable][disable] +3. [backgroundMode.isEnabled][is_enabled] 3. [backgroundMode.getDefaults][android_specifics] 4. [backgroundMode.setDefaults][android_specifics] 2. [backgroundMode.configure][android_specifics] @@ -122,6 +124,13 @@ The background mode can be disabled through the `backgroundMode.disable` interfa cordova.plugins.backgroundMode.disable(); ``` +### Receive if the background mode is enabled +The `backgroundMode.isActivated` interface can be used to get the information if the background mode is enabled or disabled. + +```javascript +var enabled = cordova.plugins.backgroundMode.isEnabled(); +``` + ### Get informed when the background mode has been activated The `backgroundMode.onactivate` interface can be used to get notified when the background mode has been activated. diff --git a/www/background-mode.js b/www/background-mode.js index c345a2a..6c86b6e 100644 --- a/www/background-mode.js +++ b/www/background-mode.js @@ -41,6 +41,13 @@ channel.onCordovaReady.subscribe(function () { }); +/** + * @private + * + * Flag indicated if the mod is enabled. + */ +exports._isEnabled = true; + /** * @private * @@ -60,6 +67,7 @@ exports._defaults = { * for the next time. */ exports.enable = function () { + this._isEnabled = true; cordova.exec(null, null, 'BackgroundMode', 'enable', []); }; @@ -68,6 +76,7 @@ exports.enable = function () { * will not stay awake while in background. */ exports.disable = function () { + this._isEnabled = false; cordova.exec(null, null, 'BackgroundMode', 'disable', []); }; @@ -115,6 +124,15 @@ exports.configure = function (options) { } }; +/** + * If the mode is enabled or not. + * + * @return {Boolean} + */ +exports.isEnabled = function () { + return this._isEnabled; +}; + /** * Called when the background mode has been activated. */