Pull bugfix from https://github.com/Sitronik/cordova-plugin-powermanagement2
This commit is contained in:
commit
9bfaf229e2
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
.idea
|
@ -20,6 +20,11 @@ Install the plugin using the cordova command line utility:
|
||||
|
||||
`$ cordova plugin add https://github.com/boltex/cordova-plugin-powermanagement.git`
|
||||
|
||||
OR
|
||||
---
|
||||
|
||||
`npm i cordova-plugin-powermanagement2`
|
||||
|
||||
Usage
|
||||
-----
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@netsyms/cordova-plugin-powermanagement",
|
||||
"version": "1.1.2",
|
||||
"version": "1.1.3",
|
||||
"description": "Plugin for managing the power state (i.e. idle switching) for cordova",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
@ -9,7 +9,7 @@
|
||||
"type": "git",
|
||||
"url": "git+https://source.netsyms.com/Netsyms/cordova-plugin-powermanagement.git"
|
||||
},
|
||||
"author": "Viras-",
|
||||
"contributors": ["Netsyms Technologies", "Viras-", "Sitronik"],
|
||||
"license": "Apache-2.0",
|
||||
"bugs": {
|
||||
"url": "https://source.netsyms.com/Netsyms/cordova-plugin-powermanagement/issues"
|
||||
@ -18,9 +18,7 @@
|
||||
"keywords": [
|
||||
"ecosystem:cordova",
|
||||
"cordova-android",
|
||||
"cordova-ios",
|
||||
"cordova-wp7",
|
||||
"cordova-wp8"
|
||||
"cordova-ios"
|
||||
],
|
||||
"main": "index.js"
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<plugin xmlns="http://cordova.apache.org/ns/plugins/1.0"
|
||||
id="@netsyms/cordova-plugin-powermanagement"
|
||||
version="1.1.2">
|
||||
version="1.1.3">
|
||||
<name>PowerManagement</name>
|
||||
<description>PowerManagement plugin for Cordova</description>
|
||||
<license>Apache 2.0</license>
|
||||
|
@ -58,7 +58,7 @@ public class PowerManagement extends CordovaPlugin {
|
||||
public void run() {
|
||||
try {
|
||||
//Log.d("PowerManagementPlugin", "About to declare ourselves VISIBLE");
|
||||
webView.getEngine().getView().dispatchWindowVisibilityChanged(View.VISIBLE);
|
||||
webView.getView().dispatchWindowVisibilityChanged(View.VISIBLE);
|
||||
|
||||
// if sdk is 23 (android 6) or greater
|
||||
if(android.os.Build.VERSION.SDK_INT > 22){
|
||||
@ -104,6 +104,13 @@ public class PowerManagement extends CordovaPlugin {
|
||||
|
||||
}
|
||||
|
||||
public PluginResult partialWakeLock() {
|
||||
Log.d("PowerManagementPlugin", "Partial wake lock" );
|
||||
PluginResult result = this.acquire( PowerManager.PARTIAL_WAKE_LOCK );
|
||||
handler.postDelayed(heartbeat, 10000);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(String action, JSONArray args,
|
||||
CallbackContext callbackContext) throws JSONException {
|
||||
@ -115,12 +122,9 @@ public class PowerManagement extends CordovaPlugin {
|
||||
try {
|
||||
if( action.equals("acquire") ) {
|
||||
if( args.length() > 0 && args.getBoolean(0) ) {
|
||||
Log.d("PowerManagementPlugin", "Partial wake lock" );
|
||||
result = this.acquire( PowerManager.PARTIAL_WAKE_LOCK );
|
||||
handler.postDelayed(heartbeat, 10000);
|
||||
}
|
||||
else {
|
||||
result = this.acquire( PowerManager.FULL_WAKE_LOCK );
|
||||
result = partialWakeLock();
|
||||
} else {
|
||||
result = partialWakeLock();
|
||||
}
|
||||
} else if( action.equals("release") ) {
|
||||
result = this.release();
|
||||
|
@ -25,48 +25,29 @@
|
||||
@implementation PowerManagement
|
||||
- (void) acquire:(CDVInvokedUrlCommand*)command
|
||||
{
|
||||
CDVPluginResult* result = nil;
|
||||
NSString* jsString = nil;
|
||||
NSString* callbackId = command.callbackId;
|
||||
|
||||
// Acquire a reference to the local UIApplication singleton
|
||||
UIApplication* app = [UIApplication sharedApplication];
|
||||
|
||||
CDVPluginResult *pluginResult = nil;
|
||||
if( ![app isIdleTimerDisabled] ) {
|
||||
[app setIdleTimerDisabled:true];
|
||||
|
||||
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
|
||||
jsString = [result toSuccessCallbackString:callbackId];
|
||||
}
|
||||
else {
|
||||
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ILLEGAL_ACCESS_EXCEPTION messageAsString:@"IdleTimer already disabled"];
|
||||
jsString = [result toErrorCallbackString:callbackId];
|
||||
}
|
||||
|
||||
[self writeJavascript:jsString];
|
||||
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
|
||||
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
||||
}
|
||||
|
||||
|
||||
- (void) release:(CDVInvokedUrlCommand*)command
|
||||
{
|
||||
CDVPluginResult* result = nil;
|
||||
NSString* jsString = nil;
|
||||
NSString* callbackId = command.callbackId;
|
||||
|
||||
// Acquire a reference to the local UIApplication singleton
|
||||
UIApplication* app = [UIApplication sharedApplication];
|
||||
|
||||
|
||||
CDVPluginResult *pluginResult = nil;
|
||||
if( [app isIdleTimerDisabled] ) {
|
||||
[app setIdleTimerDisabled:false];
|
||||
|
||||
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
|
||||
jsString = [result toSuccessCallbackString:callbackId];
|
||||
}
|
||||
else {
|
||||
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ILLEGAL_ACCESS_EXCEPTION messageAsString:@"IdleTimer not disabled"];
|
||||
jsString = [result toErrorCallbackString:callbackId];
|
||||
}
|
||||
|
||||
[self writeJavascript:jsString];
|
||||
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
|
||||
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
||||
}
|
||||
@end
|
||||
|
Loading…
x
Reference in New Issue
Block a user