mirror of
https://bitbucket.org/TheBosZ/cordova-plugin-run-in-background
synced 2024-11-14 19:44:53 +00:00
Added Windows 10 support
This commit is contained in:
parent
2538983691
commit
ffdd29d55a
@ -31,6 +31,7 @@ The plugin focuses on enterprise-only distribution and may not compliant with al
|
|||||||
- __iOS__ (_including iOS8_)
|
- __iOS__ (_including iOS8_)
|
||||||
- __Android__ _(SDK >=11)_
|
- __Android__ _(SDK >=11)_
|
||||||
- __WP8__
|
- __WP8__
|
||||||
|
- __Windows 10__
|
||||||
|
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
@ -137,21 +138,21 @@ The `backgroundMode.isEnabled` interface can be used to get the information if t
|
|||||||
cordova.plugins.backgroundMode.isEnabled(); // => boolean
|
cordova.plugins.backgroundMode.isEnabled(); // => boolean
|
||||||
```
|
```
|
||||||
|
|
||||||
### Receive if the background mode is active
|
### Receive if the background mode is active (Android/iOS only)
|
||||||
The `backgroundMode.isActive` interface can be used to get the information if the background mode is active.
|
The `backgroundMode.isActive` interface can be used to get the information if the background mode is active.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
cordova.plugins.backgroundMode.isActive(); // => boolean
|
cordova.plugins.backgroundMode.isActive(); // => boolean
|
||||||
```
|
```
|
||||||
|
|
||||||
### Get informed when the background mode has been activated
|
### Get informed when the background mode has been activated (Android/iOS only)
|
||||||
The `backgroundMode.onactivate` interface can be used to get notified when the background mode has been activated.
|
The `backgroundMode.onactivate` interface can be used to get notified when the background mode has been activated.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
cordova.plugins.backgroundMode.onactivate = function() {};
|
cordova.plugins.backgroundMode.onactivate = function() {};
|
||||||
```
|
```
|
||||||
|
|
||||||
### Get informed when the background mode has been deactivated
|
### Get informed when the background mode has been deactivated (Android/iOS only)
|
||||||
The `backgroundMode.ondeactivate` interface can be used to get notified when the background mode has been deactivated.
|
The `backgroundMode.ondeactivate` interface can be used to get notified when the background mode has been deactivated.
|
||||||
|
|
||||||
#### Further informations
|
#### Further informations
|
||||||
@ -162,7 +163,7 @@ cordova.plugins.backgroundMode.ondeactivate = function() {};
|
|||||||
```
|
```
|
||||||
|
|
||||||
### Get informed when the background mode could not been activated
|
### Get informed when the background mode could not been activated
|
||||||
The `backgroundMode.onfailure` interface can be used to get notified when the background mode could not been activated.
|
The `backgroundMode.onfailure` interface can be used to get notified when the background mode could not be activated (Android/iOS) or enabled (Windows 10).
|
||||||
|
|
||||||
The listener has to be a function and takes the following arguments:
|
The listener has to be a function and takes the following arguments:
|
||||||
- errorCode: Error code which describes the error
|
- errorCode: Error code which describes the error
|
||||||
|
15
plugin.xml
15
plugin.xml
@ -108,4 +108,19 @@
|
|||||||
|
|
||||||
<source-file src="src/wp8/BackgroundMode.cs" />
|
<source-file src="src/wp8/BackgroundMode.cs" />
|
||||||
</platform>
|
</platform>
|
||||||
|
|
||||||
|
|
||||||
|
<!-- windows -->
|
||||||
|
<platform name="windows">
|
||||||
|
<config-file target="config.xml" parent="/*">
|
||||||
|
<feature name="BackgroundMode" >
|
||||||
|
<param name="windows-package" value="BackgroundMode"/>
|
||||||
|
</feature>
|
||||||
|
</config-file>
|
||||||
|
|
||||||
|
<js-module src="src/windows/backgroundmodeProxy.js" name="backgroundmodeProxy">
|
||||||
|
<merges target="" />
|
||||||
|
</js-module>
|
||||||
|
</platform>
|
||||||
|
|
||||||
</plugin>
|
</plugin>
|
||||||
|
90
src/windows/backgroundmodeProxy.js
Normal file
90
src/windows/backgroundmodeProxy.js
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
/**
|
||||||
|
* BackgroundMode plugin for Windows 10 Universal
|
||||||
|
*
|
||||||
|
* Copyright (c) 2015 Next Wave Software, Inc.
|
||||||
|
**/
|
||||||
|
var backgroundMode = {
|
||||||
|
extendedSession: null,
|
||||||
|
settings: { text: "Background processing" },
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called internally to enable background execution.
|
||||||
|
*/
|
||||||
|
requestExtendedExecution: function () {
|
||||||
|
|
||||||
|
// Release the current active extended session if we have one.
|
||||||
|
backgroundMode.releaseExtendedExecution();
|
||||||
|
|
||||||
|
// Set up to request an extended session
|
||||||
|
backgroundMode.extendedSession = new Windows.ApplicationModel.ExtendedExecution.ExtendedExecutionSession();
|
||||||
|
backgroundMode.extendedSession.description = backgroundMode.settings.text;
|
||||||
|
backgroundMode.extendedSession.reason = Windows.ApplicationModel.ExtendedExecution.ExtendedExecutionReason.unspecified;
|
||||||
|
|
||||||
|
// When our app is running in the background and returns to the foreground, Windows will revoke our extended session permission.
|
||||||
|
// This is normal, so just request another session.
|
||||||
|
backgroundMode.extendedSession.onrevoked = function (args) {
|
||||||
|
backgroundMode.requestExtendedExecution();
|
||||||
|
};
|
||||||
|
|
||||||
|
// Request the session
|
||||||
|
backgroundMode.extendedSession.requestExtensionAsync().done(
|
||||||
|
function success() {
|
||||||
|
cordova.plugins.backgroundMode.onactivate();
|
||||||
|
},
|
||||||
|
function error(error) {
|
||||||
|
cordova.plugins.backgroundMode.onfailure(0);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called internally to disable background execution.
|
||||||
|
*/
|
||||||
|
releaseExtendedExecution: function () {
|
||||||
|
|
||||||
|
if (backgroundMode.extendedSession != null) {
|
||||||
|
backgroundMode.extendedSession.close();
|
||||||
|
backgroundMode.extendedSession = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
cordova.commandProxy.add("BackgroundMode", {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enables background execution.
|
||||||
|
*/
|
||||||
|
// exec(null, null, 'BackgroundMode', 'enable', []);
|
||||||
|
enable: function () {
|
||||||
|
|
||||||
|
// Whenever our app is launched, request permission to continue running in the background the next time Windows wants to suspend us.
|
||||||
|
WinJS.Application.addEventListener("activated", function (args) {
|
||||||
|
if (args.detail.kind === Windows.ApplicationModel.Activation.ActivationKind.launch)
|
||||||
|
backgroundMode.requestExtendedExecution();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Whenever Windows tries to suspend us, again request permission to continue running in the background.
|
||||||
|
WinJS.Application.addEventListener("checkpoint", function (args) {
|
||||||
|
backgroundMode.requestExtendedExecution();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disables background execution.
|
||||||
|
*/
|
||||||
|
// exec(null, null, 'BackgroundMode', 'disable', []);
|
||||||
|
disable: function () {
|
||||||
|
|
||||||
|
backgroundMode.releaseExtendedExecution();
|
||||||
|
cordova.plugins.backgroundMode.ondeactivate();
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets configuration values.
|
||||||
|
*/
|
||||||
|
// exec(null, null, 'BackgroundMode', 'configure', [settingsObject, isUpdate]);
|
||||||
|
configure: function (args) {
|
||||||
|
|
||||||
|
backgroundMode.settings = args[0];
|
||||||
|
}
|
||||||
|
});
|
@ -112,7 +112,7 @@ exports.setDefaults = function (overrides) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (device.platform == 'Android') {
|
if ((device.platform == 'Android') || (device.platform == 'Windows')){
|
||||||
cordova.exec(null, null, 'BackgroundMode', 'configure', [defaults, false]);
|
cordova.exec(null, null, 'BackgroundMode', 'configure', [defaults, false]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -127,7 +127,7 @@ exports.setDefaults = function (overrides) {
|
|||||||
exports.configure = function (options) {
|
exports.configure = function (options) {
|
||||||
var settings = this.mergeWithDefaults(options);
|
var settings = this.mergeWithDefaults(options);
|
||||||
|
|
||||||
if (device.platform == 'Android') {
|
if ((device.platform == 'Android') || (device.platform == 'Windows')){
|
||||||
cordova.exec(null, null, 'BackgroundMode', 'configure', [settings, true]);
|
cordova.exec(null, null, 'BackgroundMode', 'configure', [settings, true]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user