mirror of
https://bitbucket.org/TheBosZ/cordova-plugin-run-in-background
synced 2024-12-23 13:57:35 +00:00
Add support for the browser platform
This commit is contained in:
parent
bcda9ed6a6
commit
0db148518e
15
.travis.yml
15
.travis.yml
@ -34,6 +34,9 @@ node_js:
|
||||
notifications:
|
||||
email: false
|
||||
|
||||
matrix:
|
||||
fast_finish: true
|
||||
|
||||
before_install:
|
||||
- xcrun simctl delete 79C525D3-2383-4201-AC3A-81810F9F4E03
|
||||
|
||||
@ -42,20 +45,22 @@ install:
|
||||
- npm install -g cordova
|
||||
- brew install gradle
|
||||
- brew install android-sdk
|
||||
- ( sleep 5 && while [ 1 ]; do sleep 1; echo y; done ) | android update sdk -a -u -t "tools,platform-tools,build-tools-25.0.2,android-16"
|
||||
- ( sleep 5 && while [ 1 ]; do sleep 1; echo y; done ) | android update sdk -a -u -t "tools,platform-tools,build-tools-25.0.2,android-25,extra-android-m2repository"
|
||||
|
||||
before_script:
|
||||
- cordova create myApp org.apache.cordova.myApp myApp
|
||||
- cd myApp
|
||||
- cordova platform add ios@latest android@latest
|
||||
- sed -i -r 's:\(<content.*\):\1<preference name="android-targetSdkVersion" value="16" />:' config.xml
|
||||
- cordova platform add android@latest browser@latest ios@latest
|
||||
- cordova plugin add cordova-plugin-background-mode --searchpath $TRAVIS_BUILD_DIR
|
||||
- cordova platform ls
|
||||
- cordova plugin ls
|
||||
|
||||
script:
|
||||
- cordova build ios
|
||||
- cordova build android
|
||||
- cordova plugin add cordova-plugin-wkwebview-engine
|
||||
- cordova build browser
|
||||
- cordova build ios
|
||||
- cordova plugin add cordova-plugin-crosswalk-webview
|
||||
- cordova build ios
|
||||
- cordova plugin add cordova-plugin-wkwebview-engine
|
||||
- cordova build android
|
||||
- cordova build ios
|
||||
|
@ -1,7 +1,8 @@
|
||||
## ChangeLog
|
||||
#### Version 0.7.0 (not yet released)
|
||||
- __Features__
|
||||
- Support for Amazon FireOS
|
||||
- Support for tAmazon FireOS
|
||||
- Support for the browser platform
|
||||
- Ability to configure icon and color on Android
|
||||
- Allow app to move to foreground on Android
|
||||
- Allow app to move to background on Android
|
||||
|
@ -18,9 +18,9 @@ Use the plugin by your own risk!
|
||||
|
||||
|
||||
## Supported Platforms
|
||||
- __Android/Amazon FireOS__
|
||||
- __Browser__
|
||||
- __iOS__
|
||||
- __Android__
|
||||
- __Amazon FireOS__
|
||||
- __Windows__ _(see #222)_
|
||||
|
||||
|
||||
|
13
plugin.xml
13
plugin.xml
@ -105,4 +105,17 @@
|
||||
</js-module>
|
||||
</platform> -->
|
||||
|
||||
<!-- browser -->
|
||||
<platform name="browser">
|
||||
<config-file target="config.xml" parent="/*">
|
||||
<feature name="BackgroundMode">
|
||||
<param name="browser-package" value="BackgroundMode"/>
|
||||
</feature>
|
||||
</config-file>
|
||||
|
||||
<js-module src="src/browser/BackgroundModeProxy.js" name="BackgroundMode.Proxy">
|
||||
<runs />
|
||||
</js-module>
|
||||
</platform>
|
||||
|
||||
</plugin>
|
||||
|
49
src/browser/BackgroundModeProxy.js
Normal file
49
src/browser/BackgroundModeProxy.js
Normal file
@ -0,0 +1,49 @@
|
||||
/*
|
||||
Copyright 2013-2017 appPlant GmbH
|
||||
|
||||
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
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Activates the background mode. When activated the application
|
||||
* will be prevented from going to sleep while in background
|
||||
* for the next time.
|
||||
*
|
||||
* @param [ Function ] success The success callback to use.
|
||||
* @param [ Function ] error The error callback to use.
|
||||
*
|
||||
* @return [ Void ]
|
||||
*/
|
||||
exports.enable = function (success, error) {
|
||||
success();
|
||||
};
|
||||
|
||||
/**
|
||||
* Deactivates the background mode. When deactivated the application
|
||||
* will not stay awake while in background.
|
||||
*
|
||||
* @param [ Function ] success The success callback to use.
|
||||
* @param [ Function ] error The error callback to use.
|
||||
*
|
||||
* @return [ Void ]
|
||||
*/
|
||||
exports.disable = function (success, error) {
|
||||
success();
|
||||
};
|
||||
|
||||
cordova.commandProxy.add('BackgroundMode', exports);
|
@ -22,7 +22,7 @@
|
||||
#import <AVFoundation/AVFoundation.h>
|
||||
#import <Cordova/CDVPlugin.h>
|
||||
|
||||
@interface APPBackgroundMode : CDVPlugin {
|
||||
@interface APPBackgroundMode : CDVPlugin {
|
||||
AVAudioPlayer* audioPlayer;
|
||||
BOOL enabled;
|
||||
}
|
||||
|
@ -31,6 +31,8 @@ var exec = require('cordova/exec'),
|
||||
* Activates the background mode. When activated the application
|
||||
* will be prevented from going to sleep while in background
|
||||
* for the next time.
|
||||
*
|
||||
* @return [ Void ]
|
||||
*/
|
||||
exports.enable = function () {
|
||||
if (this.isEnabled())
|
||||
@ -47,6 +49,8 @@ exports.enable = function () {
|
||||
/**
|
||||
* Deactivates the background mode. When deactivated the application
|
||||
* will not stay awake while in background.
|
||||
*
|
||||
* @return [ Void ]
|
||||
*/
|
||||
exports.disable = function () {
|
||||
if (!this.isEnabled())
|
||||
@ -78,17 +82,18 @@ exports.setEnabled = function (enable) {
|
||||
/**
|
||||
* List of all available options with their default value.
|
||||
*
|
||||
* @return {Object}
|
||||
* @return [ Object ]
|
||||
*/
|
||||
exports.getDefaults = function () {
|
||||
return this._defaults;
|
||||
};
|
||||
|
||||
/**
|
||||
* Overwrite default settings
|
||||
* Overwrite the default settings.
|
||||
*
|
||||
* @param {Object} overrides
|
||||
* Dict of options which shall be overridden
|
||||
* @param [ Object ] overrides Dict of options to be overridden.
|
||||
*
|
||||
* @return [ Void ]
|
||||
*/
|
||||
exports.setDefaults = function (overrides) {
|
||||
var defaults = this.getDefaults();
|
||||
@ -108,8 +113,9 @@ exports.setDefaults = function (overrides) {
|
||||
* Configures the notification settings for Android.
|
||||
* Will be merged with the defaults.
|
||||
*
|
||||
* @param {Object} options
|
||||
* Dict with key/value pairs
|
||||
* @param [ Object ] overrides Dict of options to be overridden.
|
||||
*
|
||||
* @return [ Void ]
|
||||
*/
|
||||
exports.configure = function (options) {
|
||||
var settings = this.mergeWithDefaults(options);
|
||||
@ -121,6 +127,8 @@ exports.configure = function (options) {
|
||||
|
||||
/**
|
||||
* Enable GPS-tracking in background (Android).
|
||||
*
|
||||
* @return [ Void ]
|
||||
*/
|
||||
exports.disableWebViewOptimizations = function () {
|
||||
if (this._isAndroid) {
|
||||
@ -163,7 +171,7 @@ exports.overrideBackButton = function () {
|
||||
/**
|
||||
* If the mode is enabled or disabled.
|
||||
*
|
||||
* @return {Boolean}
|
||||
* @return [ Boolean ]
|
||||
*/
|
||||
exports.isEnabled = function () {
|
||||
return this._isEnabled !== false;
|
||||
@ -172,7 +180,7 @@ exports.isEnabled = function () {
|
||||
/**
|
||||
* If the mode is active.
|
||||
*
|
||||
* @return {Boolean}
|
||||
* @return [ Boolean ]
|
||||
*/
|
||||
exports.isActive = function () {
|
||||
return this._isActive !== false;
|
||||
@ -189,7 +197,7 @@ exports._listener = {};
|
||||
* Fire event with given arguments.
|
||||
*
|
||||
* @param [ String ] event The event's name.
|
||||
* @param {args*} The callback's arguments.
|
||||
* @param [ Array<Object> ] The callback's arguments.
|
||||
*
|
||||
* @return [ Void ]
|
||||
*/
|
||||
@ -289,12 +297,9 @@ exports.onfailure = function () {};
|
||||
*
|
||||
* Merge settings with default values.
|
||||
*
|
||||
* @param {Object} options
|
||||
* The custom options
|
||||
* @param [ Object ] options The custom options.
|
||||
*
|
||||
* @return {Object}
|
||||
* Default values merged
|
||||
* with custom values
|
||||
* @return [ Object ] Default values merged with custom values.
|
||||
*/
|
||||
exports.mergeWithDefaults = function (options) {
|
||||
var defaults = this.getDefaults();
|
||||
@ -309,6 +314,23 @@ exports.mergeWithDefaults = function (options) {
|
||||
return options;
|
||||
};
|
||||
|
||||
/**
|
||||
* @private
|
||||
*
|
||||
* Initialize the plugin.
|
||||
*
|
||||
* Method should be called after the 'deviceready' event
|
||||
* but before the event listeners will be called.
|
||||
*
|
||||
* @return [ Void ]
|
||||
*/
|
||||
exports.pluginInitialize = function () {
|
||||
this._isAndroid = device.platform.match(/^android|amazon/i) !== null;
|
||||
this._isEnabled = this._isEnabled || device.platform == 'browser';
|
||||
this._isActive = this._isActive || device.platform == 'browser';
|
||||
this.setDefaults({});
|
||||
};
|
||||
|
||||
|
||||
/***********
|
||||
* PRIVATE *
|
||||
@ -347,14 +369,17 @@ exports._defaults = {
|
||||
// Called before 'deviceready' listener will be called
|
||||
channel.onCordovaReady.subscribe(function () {
|
||||
channel.onCordovaInfoReady.subscribe(function () {
|
||||
exports._isAndroid = device.platform.match(/^android|amazon/i) !== null;
|
||||
exports.setDefaults({});
|
||||
exports.pluginInitialize();
|
||||
});
|
||||
});
|
||||
|
||||
// Called after 'deviceready' event
|
||||
channel.deviceready.subscribe(function () {
|
||||
if (window.webkit && exports.isEnabled()) {
|
||||
if (exports.isEnabled()) {
|
||||
exports.fireEvent('enable');
|
||||
}
|
||||
|
||||
if (exports.isActive()) {
|
||||
exports.fireEvent('activate');
|
||||
}
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user