Add support for the browser platform

This commit is contained in:
Sebastián Katzer 2017-01-27 10:23:46 +01:00
parent bcda9ed6a6
commit 0db148518e
7 changed files with 119 additions and 26 deletions

View File

@ -34,6 +34,9 @@ node_js:
notifications: notifications:
email: false email: false
matrix:
fast_finish: true
before_install: before_install:
- xcrun simctl delete 79C525D3-2383-4201-AC3A-81810F9F4E03 - xcrun simctl delete 79C525D3-2383-4201-AC3A-81810F9F4E03
@ -42,20 +45,22 @@ install:
- npm install -g cordova - npm install -g cordova
- brew install gradle - brew install gradle
- brew install android-sdk - 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: before_script:
- cordova create myApp org.apache.cordova.myApp myApp - cordova create myApp org.apache.cordova.myApp myApp
- cd 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 plugin add cordova-plugin-background-mode --searchpath $TRAVIS_BUILD_DIR
- cordova platform ls - cordova platform ls
- cordova plugin ls - cordova plugin ls
script: script:
- cordova build ios
- cordova build android - cordova build android
- cordova plugin add cordova-plugin-wkwebview-engine - cordova build browser
- cordova build ios
- cordova plugin add cordova-plugin-crosswalk-webview - cordova plugin add cordova-plugin-crosswalk-webview
- cordova build ios - cordova plugin add cordova-plugin-wkwebview-engine
- cordova build android - cordova build android
- cordova build ios

View File

@ -1,7 +1,8 @@
## ChangeLog ## ChangeLog
#### Version 0.7.0 (not yet released) #### Version 0.7.0 (not yet released)
- __Features__ - __Features__
- Support for Amazon FireOS - Support for tAmazon FireOS
- Support for the browser platform
- Ability to configure icon and color on Android - Ability to configure icon and color on Android
- Allow app to move to foreground on Android - Allow app to move to foreground on Android
- Allow app to move to background on Android - Allow app to move to background on Android

View File

@ -18,9 +18,9 @@ Use the plugin by your own risk!
## Supported Platforms ## Supported Platforms
- __Android/Amazon FireOS__
- __Browser__
- __iOS__ - __iOS__
- __Android__
- __Amazon FireOS__
- __Windows__ _(see #222)_ - __Windows__ _(see #222)_

View File

@ -105,4 +105,17 @@
</js-module> </js-module>
</platform> --> </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> </plugin>

View 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);

View File

@ -31,6 +31,8 @@ var exec = require('cordova/exec'),
* Activates the background mode. When activated the application * Activates the background mode. When activated the application
* will be prevented from going to sleep while in background * will be prevented from going to sleep while in background
* for the next time. * for the next time.
*
* @return [ Void ]
*/ */
exports.enable = function () { exports.enable = function () {
if (this.isEnabled()) if (this.isEnabled())
@ -47,6 +49,8 @@ exports.enable = function () {
/** /**
* Deactivates the background mode. When deactivated the application * Deactivates the background mode. When deactivated the application
* will not stay awake while in background. * will not stay awake while in background.
*
* @return [ Void ]
*/ */
exports.disable = function () { exports.disable = function () {
if (!this.isEnabled()) if (!this.isEnabled())
@ -78,17 +82,18 @@ exports.setEnabled = function (enable) {
/** /**
* List of all available options with their default value. * List of all available options with their default value.
* *
* @return {Object} * @return [ Object ]
*/ */
exports.getDefaults = function () { exports.getDefaults = function () {
return this._defaults; return this._defaults;
}; };
/** /**
* Overwrite default settings * Overwrite the default settings.
* *
* @param {Object} overrides * @param [ Object ] overrides Dict of options to be overridden.
* Dict of options which shall be overridden *
* @return [ Void ]
*/ */
exports.setDefaults = function (overrides) { exports.setDefaults = function (overrides) {
var defaults = this.getDefaults(); var defaults = this.getDefaults();
@ -108,8 +113,9 @@ exports.setDefaults = function (overrides) {
* Configures the notification settings for Android. * Configures the notification settings for Android.
* Will be merged with the defaults. * Will be merged with the defaults.
* *
* @param {Object} options * @param [ Object ] overrides Dict of options to be overridden.
* Dict with key/value pairs *
* @return [ Void ]
*/ */
exports.configure = function (options) { exports.configure = function (options) {
var settings = this.mergeWithDefaults(options); var settings = this.mergeWithDefaults(options);
@ -121,6 +127,8 @@ exports.configure = function (options) {
/** /**
* Enable GPS-tracking in background (Android). * Enable GPS-tracking in background (Android).
*
* @return [ Void ]
*/ */
exports.disableWebViewOptimizations = function () { exports.disableWebViewOptimizations = function () {
if (this._isAndroid) { if (this._isAndroid) {
@ -163,7 +171,7 @@ exports.overrideBackButton = function () {
/** /**
* If the mode is enabled or disabled. * If the mode is enabled or disabled.
* *
* @return {Boolean} * @return [ Boolean ]
*/ */
exports.isEnabled = function () { exports.isEnabled = function () {
return this._isEnabled !== false; return this._isEnabled !== false;
@ -172,7 +180,7 @@ exports.isEnabled = function () {
/** /**
* If the mode is active. * If the mode is active.
* *
* @return {Boolean} * @return [ Boolean ]
*/ */
exports.isActive = function () { exports.isActive = function () {
return this._isActive !== false; return this._isActive !== false;
@ -189,7 +197,7 @@ exports._listener = {};
* Fire event with given arguments. * Fire event with given arguments.
* *
* @param [ String ] event The event's name. * @param [ String ] event The event's name.
* @param {args*} The callback's arguments. * @param [ Array<Object> ] The callback's arguments.
* *
* @return [ Void ] * @return [ Void ]
*/ */
@ -289,12 +297,9 @@ exports.onfailure = function () {};
* *
* Merge settings with default values. * Merge settings with default values.
* *
* @param {Object} options * @param [ Object ] options The custom options.
* The custom options
* *
* @return {Object} * @return [ Object ] Default values merged with custom values.
* Default values merged
* with custom values
*/ */
exports.mergeWithDefaults = function (options) { exports.mergeWithDefaults = function (options) {
var defaults = this.getDefaults(); var defaults = this.getDefaults();
@ -309,6 +314,23 @@ exports.mergeWithDefaults = function (options) {
return 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 * * PRIVATE *
@ -347,14 +369,17 @@ exports._defaults = {
// Called before 'deviceready' listener will be called // Called before 'deviceready' listener will be called
channel.onCordovaReady.subscribe(function () { channel.onCordovaReady.subscribe(function () {
channel.onCordovaInfoReady.subscribe(function () { channel.onCordovaInfoReady.subscribe(function () {
exports._isAndroid = device.platform.match(/^android|amazon/i) !== null; exports.pluginInitialize();
exports.setDefaults({});
}); });
}); });
// Called after 'deviceready' event // Called after 'deviceready' event
channel.deviceready.subscribe(function () { channel.deviceready.subscribe(function () {
if (window.webkit && exports.isEnabled()) { if (exports.isEnabled()) {
exports.fireEvent('enable'); exports.fireEvent('enable');
} }
if (exports.isActive()) {
exports.fireEvent('activate');
}
}); });