This commit is contained in:
Skylar Ittner 2023-06-29 02:46:09 -06:00
commit 9bfaf229e2
6 changed files with 58 additions and 69 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.idea

View File

@ -20,6 +20,11 @@ Install the plugin using the cordova command line utility:
`$ cordova plugin add https://github.com/boltex/cordova-plugin-powermanagement.git` `$ cordova plugin add https://github.com/boltex/cordova-plugin-powermanagement.git`
OR
---
`npm i cordova-plugin-powermanagement2`
Usage Usage
----- -----

View File

@ -1,6 +1,6 @@
{ {
"name": "@netsyms/cordova-plugin-powermanagement", "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", "description": "Plugin for managing the power state (i.e. idle switching) for cordova",
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1" "test": "echo \"Error: no test specified\" && exit 1"
@ -9,7 +9,7 @@
"type": "git", "type": "git",
"url": "git+https://source.netsyms.com/Netsyms/cordova-plugin-powermanagement.git" "url": "git+https://source.netsyms.com/Netsyms/cordova-plugin-powermanagement.git"
}, },
"author": "Viras-", "contributors": ["Netsyms Technologies", "Viras-", "Sitronik"],
"license": "Apache-2.0", "license": "Apache-2.0",
"bugs": { "bugs": {
"url": "https://source.netsyms.com/Netsyms/cordova-plugin-powermanagement/issues" "url": "https://source.netsyms.com/Netsyms/cordova-plugin-powermanagement/issues"
@ -18,9 +18,7 @@
"keywords": [ "keywords": [
"ecosystem:cordova", "ecosystem:cordova",
"cordova-android", "cordova-android",
"cordova-ios", "cordova-ios"
"cordova-wp7",
"cordova-wp8"
], ],
"main": "index.js" "main": "index.js"
} }

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://cordova.apache.org/ns/plugins/1.0" <plugin xmlns="http://cordova.apache.org/ns/plugins/1.0"
id="@netsyms/cordova-plugin-powermanagement" id="@netsyms/cordova-plugin-powermanagement"
version="1.1.2"> version="1.1.3">
<name>PowerManagement</name> <name>PowerManagement</name>
<description>PowerManagement plugin for Cordova</description> <description>PowerManagement plugin for Cordova</description>
<license>Apache 2.0</license> <license>Apache 2.0</license>

View File

@ -58,7 +58,7 @@ public class PowerManagement extends CordovaPlugin {
public void run() { public void run() {
try { try {
//Log.d("PowerManagementPlugin", "About to declare ourselves VISIBLE"); //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 sdk is 23 (android 6) or greater
if(android.os.Build.VERSION.SDK_INT > 22){ 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 @Override
public boolean execute(String action, JSONArray args, public boolean execute(String action, JSONArray args,
CallbackContext callbackContext) throws JSONException { CallbackContext callbackContext) throws JSONException {
@ -115,12 +122,9 @@ public class PowerManagement extends CordovaPlugin {
try { try {
if( action.equals("acquire") ) { if( action.equals("acquire") ) {
if( args.length() > 0 && args.getBoolean(0) ) { if( args.length() > 0 && args.getBoolean(0) ) {
Log.d("PowerManagementPlugin", "Partial wake lock" ); result = partialWakeLock();
result = this.acquire( PowerManager.PARTIAL_WAKE_LOCK ); } else {
handler.postDelayed(heartbeat, 10000); result = partialWakeLock();
}
else {
result = this.acquire( PowerManager.FULL_WAKE_LOCK );
} }
} else if( action.equals("release") ) { } else if( action.equals("release") ) {
result = this.release(); result = this.release();

View File

@ -25,48 +25,29 @@
@implementation PowerManagement @implementation PowerManagement
- (void) acquire:(CDVInvokedUrlCommand*)command - (void) acquire:(CDVInvokedUrlCommand*)command
{ {
CDVPluginResult* result = nil;
NSString* jsString = nil;
NSString* callbackId = command.callbackId;
// Acquire a reference to the local UIApplication singleton // Acquire a reference to the local UIApplication singleton
UIApplication* app = [UIApplication sharedApplication]; UIApplication* app = [UIApplication sharedApplication];
CDVPluginResult *pluginResult = nil;
if( ![app isIdleTimerDisabled] ) { if( ![app isIdleTimerDisabled] ) {
[app setIdleTimerDisabled:true]; [app setIdleTimerDisabled:true];
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
jsString = [result toSuccessCallbackString:callbackId];
} }
else { pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ILLEGAL_ACCESS_EXCEPTION messageAsString:@"IdleTimer already disabled"]; [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
jsString = [result toErrorCallbackString:callbackId];
}
[self writeJavascript:jsString];
} }
- (void) release:(CDVInvokedUrlCommand*)command - (void) release:(CDVInvokedUrlCommand*)command
{ {
CDVPluginResult* result = nil;
NSString* jsString = nil;
NSString* callbackId = command.callbackId;
// Acquire a reference to the local UIApplication singleton // Acquire a reference to the local UIApplication singleton
UIApplication* app = [UIApplication sharedApplication]; UIApplication* app = [UIApplication sharedApplication];
CDVPluginResult *pluginResult = nil;
if( [app isIdleTimerDisabled] ) { if( [app isIdleTimerDisabled] ) {
[app setIdleTimerDisabled:false]; [app setIdleTimerDisabled:false];
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
jsString = [result toSuccessCallbackString:callbackId];
} }
else { pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ILLEGAL_ACCESS_EXCEPTION messageAsString:@"IdleTimer not disabled"]; [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
jsString = [result toErrorCallbackString:callbackId];
}
[self writeJavascript:jsString];
} }
@end @end