Change some formats

This commit is contained in:
Sebastián Katzer 2019-02-08 18:33:54 +01:00
parent 4c157f4509
commit 9fb7257297

View File

@ -22,11 +22,6 @@
var exec = require('cordova/exec'), var exec = require('cordova/exec'),
channel = require('cordova/channel'); channel = require('cordova/channel');
/*************
* INTERFACE *
*************/
/** /**
* 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
@ -34,7 +29,8 @@ var exec = require('cordova/exec'),
* *
* @return [ Void ] * @return [ Void ]
*/ */
exports.enable = function() { exports.enable = function()
{
if (this.isEnabled()) if (this.isEnabled())
return; return;
@ -52,7 +48,8 @@ exports.enable = function() {
* *
* @return [ Void ] * @return [ Void ]
*/ */
exports.disable = function() { exports.disable = function()
{
if (!this.isEnabled()) if (!this.isEnabled())
return; return;
@ -71,7 +68,8 @@ exports.disable = function() {
* *
* @return [ Void ] * @return [ Void ]
*/ */
exports.setEnabled = function (enable) { exports.setEnabled = function (enable)
{
if (enable) { if (enable) {
this.enable(); this.enable();
} else { } else {
@ -84,7 +82,8 @@ exports.setEnabled = function (enable) {
* *
* @return [ Object ] * @return [ Object ]
*/ */
exports.getDefaults = function() { exports.getDefaults = function()
{
return this._defaults; return this._defaults;
}; };
@ -93,7 +92,8 @@ exports.getDefaults = function() {
* *
* @return [ Object ] * @return [ Object ]
*/ */
exports.getSettings = function() { exports.getSettings = function()
{
return this._settings || {}; return this._settings || {};
}; };
@ -104,16 +104,20 @@ exports.getSettings = function() {
* *
* @return [ Void ] * @return [ Void ]
*/ */
exports.setDefaults = function (overrides) { exports.setDefaults = function (overrides)
{
var defaults = this.getDefaults(); var defaults = this.getDefaults();
for (var key in defaults) { for (var key in defaults)
if (overrides.hasOwnProperty(key)) { {
if (overrides.hasOwnProperty(key))
{
defaults[key] = overrides[key]; defaults[key] = overrides[key];
} }
} }
if (this._isAndroid) { if (this._isAndroid)
{
cordova.exec(null, null, 'BackgroundMode', 'configure', [defaults, false]); cordova.exec(null, null, 'BackgroundMode', 'configure', [defaults, false]);
} }
}; };
@ -126,14 +130,16 @@ exports.setDefaults = function (overrides) {
* *
* @return [ Void ] * @return [ Void ]
*/ */
exports.configure = function (options) { exports.configure = function (options)
{
var settings = this.getSettings(), var settings = this.getSettings(),
defaults = this.getDefaults(); defaults = this.getDefaults();
if (!this._isAndroid) if (!this._isAndroid)
return; return;
if (!this._isActive) { if (!this._isActive)
{
console.log('BackgroundMode is not active, skipped...'); console.log('BackgroundMode is not active, skipped...');
return; return;
} }
@ -150,8 +156,10 @@ exports.configure = function (options) {
* *
* @return [ Void ] * @return [ Void ]
*/ */
exports.disableWebViewOptimizations = function() { exports.disableWebViewOptimizations = function()
if (this._isAndroid) { {
if (this._isAndroid)
{
cordova.exec(null, null, 'BackgroundMode', 'optimizations', []); cordova.exec(null, null, 'BackgroundMode', 'optimizations', []);
} }
}; };
@ -161,8 +169,10 @@ exports.disableWebViewOptimizations = function() {
* *
* @return [ Void ] * @return [ Void ]
*/ */
exports.moveToBackground = function() { exports.moveToBackground = function()
if (this._isAndroid) { {
if (this._isAndroid)
{
cordova.exec(null, null, 'BackgroundMode', 'background', []); cordova.exec(null, null, 'BackgroundMode', 'background', []);
} }
}; };
@ -172,8 +182,10 @@ exports.moveToBackground = function() {
* *
* @return [ Void ] * @return [ Void ]
*/ */
exports.moveToForeground = function() { exports.moveToForeground = function()
if (this.isActive() && this._isAndroid) { {
if (this.isActive() && this._isAndroid)
{
cordova.exec(null, null, 'BackgroundMode', 'foreground', []); cordova.exec(null, null, 'BackgroundMode', 'foreground', []);
} }
}; };
@ -183,8 +195,10 @@ exports.moveToForeground = function() {
* *
* @return [ Void ] * @return [ Void ]
*/ */
exports.excludeFromTaskList = function() { exports.excludeFromTaskList = function()
if (this._isAndroid) { {
if (this._isAndroid)
{
cordova.exec(null, null, 'BackgroundMode', 'tasklist', []); cordova.exec(null, null, 'BackgroundMode', 'tasklist', []);
} }
}; };
@ -195,7 +209,8 @@ exports.excludeFromTaskList = function() {
* *
* @return [ Void ] * @return [ Void ]
*/ */
exports.overrideBackButton = function() { exports.overrideBackButton = function()
{
document.addEventListener('backbutton', function() { document.addEventListener('backbutton', function() {
exports.moveToBackground(); exports.moveToBackground();
}, false); }, false);
@ -208,10 +223,14 @@ exports.overrideBackButton = function() {
* *
* @return [ Void ] * @return [ Void ]
*/ */
exports.isScreenOff = function (fn) { exports.isScreenOff = function (fn)
if (this._isAndroid) { {
if (this._isAndroid)
{
cordova.exec(fn, null, 'BackgroundMode', 'dimmed', []); cordova.exec(fn, null, 'BackgroundMode', 'dimmed', []);
} else { }
else
{
fn(undefined); fn(undefined);
} }
}; };
@ -221,8 +240,10 @@ exports.isScreenOff = function (fn) {
* *
* @return [ Void ] * @return [ Void ]
*/ */
exports.wakeUp = function() { exports.wakeUp = function()
if (this._isAndroid) { {
if (this._isAndroid)
{
cordova.exec(null, null, 'BackgroundMode', 'wakeup', []); cordova.exec(null, null, 'BackgroundMode', 'wakeup', []);
} }
}; };
@ -232,8 +253,10 @@ exports.wakeUp = function() {
* *
* @return [ Void ] * @return [ Void ]
*/ */
exports.unlock = function() { exports.unlock = function()
if (this._isAndroid) { {
if (this._isAndroid)
{
cordova.exec(null, null, 'BackgroundMode', 'unlock', []); cordova.exec(null, null, 'BackgroundMode', 'unlock', []);
} }
}; };
@ -243,7 +266,8 @@ exports.unlock = function() {
* *
* @return [ Boolean ] * @return [ Boolean ]
*/ */
exports.isEnabled = function() { exports.isEnabled = function()
{
return this._isEnabled !== false; return this._isEnabled !== false;
}; };
@ -252,15 +276,11 @@ exports.isEnabled = function() {
* *
* @return [ Boolean ] * @return [ Boolean ]
*/ */
exports.isActive = function() { exports.isActive = function()
{
return this._isActive !== false; return this._isActive !== false;
}; };
/**********
* EVENTS *
**********/
exports._listener = {}; exports._listener = {};
/** /**
@ -271,14 +291,16 @@ exports._listener = {};
* *
* @return [ Void ] * @return [ Void ]
*/ */
exports.fireEvent = function (event) { exports.fireEvent = function (event)
{
var args = Array.apply(null, arguments).slice(1), var args = Array.apply(null, arguments).slice(1),
listener = this._listener[event]; listener = this._listener[event];
if (!listener) if (!listener)
return; return;
for (var i = 0; i < listener.length; i++) { for (var i = 0; i < listener.length; i++)
{
var fn = listener[i][0], var fn = listener[i][0],
scope = listener[i][1]; scope = listener[i][1];
@ -295,12 +317,13 @@ exports.fireEvent = function (event) {
* *
* @return [ Void ] * @return [ Void ]
*/ */
exports.on = function (event, callback, scope) { exports.on = function (event, callback, scope)
{
if (typeof callback !== "function") if (typeof callback !== "function")
return; return;
if (!this._listener[event]) { if (!this._listener[event])
{
this._listener[event] = []; this._listener[event] = [];
} }
@ -317,51 +340,25 @@ exports.on = function (event, callback, scope) {
* *
* @return [ Void ] * @return [ Void ]
*/ */
exports.un = function (event, callback) { exports.un = function (event, callback)
{
var listener = this._listener[event]; var listener = this._listener[event];
if (!listener) if (!listener)
return; return;
for (var i = 0; i < listener.length; i++) { for (var i = 0; i < listener.length; i++)
{
var fn = listener[i][0]; var fn = listener[i][0];
if (fn == callback) { if (fn == callback)
{
listener.splice(i, 1); listener.splice(i, 1);
break; break;
} }
} }
}; };
/**
* @deprecated
*
* Called when the background mode has been activated.
*/
exports.onactivate = function() {};
/**
* @deprecated
*
* Called when the background mode has been deaktivated.
*/
exports.ondeactivate = function() {};
/**
* @deprecated
*
* Called when the background mode could not been activated.
*
* @param {Integer} errorCode
* Error code which describes the error
*/
exports.onfailure = function() {};
/***********
* PRIVATE *
***********/
/** /**
* @private * @private
* *
@ -381,7 +378,8 @@ exports._isActive = false;
* *
* Default values of all available options. * Default values of all available options.
*/ */
exports._defaults = { exports._defaults =
{
title: 'App is running in background', title: 'App is running in background',
text: 'Doing heavy tasks.', text: 'Doing heavy tasks.',
bigText: false, bigText: false,
@ -402,9 +400,12 @@ exports._defaults = {
* *
* @return [ Object ] Default values merged with custom values. * @return [ Object ] Default values merged with custom values.
*/ */
exports._mergeObjects = function (options, toMergeIn) { exports._mergeObjects = function (options, toMergeIn)
for (var key in toMergeIn) { {
if (!options.hasOwnProperty(key)) { for (var key in toMergeIn)
{
if (!options.hasOwnProperty(key))
{
options[key] = toMergeIn[key]; options[key] = toMergeIn[key];
continue; continue;
} }
@ -423,7 +424,8 @@ exports._mergeObjects = function (options, toMergeIn) {
* *
* @return [ Void ] * @return [ Void ]
*/ */
exports._setActive = function(value) { exports._setActive = function(value)
{
if (this._isActive == value) if (this._isActive == value)
return; return;
@ -441,11 +443,13 @@ exports._setActive = function(value) {
* *
* @return [ Void ] * @return [ Void ]
*/ */
exports._pluginInitialize = function() { exports._pluginInitialize = function()
{
this._isAndroid = device.platform.match(/^android|amazon/i) !== null; this._isAndroid = device.platform.match(/^android|amazon/i) !== null;
this.setDefaults({}); this.setDefaults({});
if (device.platform == 'browser') { if (device.platform == 'browser')
{
this.enable(); this.enable();
this._isEnabled = true; this._isEnabled = true;
} }
@ -454,19 +458,23 @@ exports._pluginInitialize = function() {
}; };
// 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._pluginInitialize(); exports._pluginInitialize();
}); });
}); });
// Called after 'deviceready' event // Called after 'deviceready' event
channel.deviceready.subscribe(function() { channel.deviceready.subscribe(function()
if (exports.isEnabled()) { {
if (exports.isEnabled())
{
exports.fireEvent('enable'); exports.fireEvent('enable');
} }
if (exports.isActive()) { if (exports.isActive())
{
exports.fireEvent('activate'); exports.fireEvent('activate');
} }
}); });