mirror of
https://bitbucket.org/TheBosZ/cordova-plugin-run-in-background
synced 2024-11-21 23:04:53 +00:00
enable/disable event
This commit is contained in:
parent
6dabe3427d
commit
337e39b2db
@ -101,35 +101,31 @@ public class BackgroundMode extends CordovaPlugin {
|
|||||||
boolean update = args.getBoolean(1);
|
boolean update = args.getBoolean(1);
|
||||||
|
|
||||||
configure(settings, update);
|
configure(settings, update);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (action.equalsIgnoreCase("disableWebViewOptimizations")) {
|
if (action.equalsIgnoreCase("disableWebViewOptimizations")) {
|
||||||
disableWebViewOptimizations();
|
disableWebViewOptimizations();
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (action.equalsIgnoreCase("background")) {
|
if (action.equalsIgnoreCase("background")) {
|
||||||
moveToBackground();
|
moveToBackground();
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (action.equalsIgnoreCase("foreground")) {
|
if (action.equalsIgnoreCase("foreground")) {
|
||||||
moveToForeground();
|
moveToForeground();
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (action.equalsIgnoreCase("enable")) {
|
if (action.equalsIgnoreCase("enable")) {
|
||||||
enableMode();
|
enableMode();
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (action.equalsIgnoreCase("disable")) {
|
if (action.equalsIgnoreCase("disable")) {
|
||||||
disableMode();
|
disableMode();
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
callback.success();
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -33,8 +33,14 @@ var exec = require('cordova/exec'),
|
|||||||
* for the next time.
|
* for the next time.
|
||||||
*/
|
*/
|
||||||
exports.enable = function () {
|
exports.enable = function () {
|
||||||
|
if (this.isEnabled())
|
||||||
|
return;
|
||||||
|
|
||||||
|
var me = this,
|
||||||
|
fireEvent = function () { me.fireEvent('enable'); };
|
||||||
|
|
||||||
this._isEnabled = true;
|
this._isEnabled = true;
|
||||||
cordova.exec(null, null, 'BackgroundMode', 'enable', []);
|
cordova.exec(fireEvent, null, 'BackgroundMode', 'enable', []);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -42,8 +48,14 @@ exports.enable = function () {
|
|||||||
* will not stay awake while in background.
|
* will not stay awake while in background.
|
||||||
*/
|
*/
|
||||||
exports.disable = function () {
|
exports.disable = function () {
|
||||||
|
if (!this.isEnabled())
|
||||||
|
return;
|
||||||
|
|
||||||
|
var me = this,
|
||||||
|
fireEvent = function () { me.fireEvent('disable'); };
|
||||||
|
|
||||||
this._isEnabled = false;
|
this._isEnabled = false;
|
||||||
cordova.exec(null, null, 'BackgroundMode', 'disable', []);
|
cordova.exec(fireEvent, null, 'BackgroundMode', 'disable', []);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user