From 71695ca851e670c2809748e7a80891fc63c0995b Mon Sep 17 00:00:00 2001 From: Denis Date: Fri, 27 Aug 2021 22:01:37 +0300 Subject: [PATCH 1/4] fix --- .gitignore | 1 + package.json | 10 ++--- src/android/PowerManagement.java | 70 +++++++++++++++++--------------- 3 files changed, 43 insertions(+), 38 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..485dee6 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea diff --git a/package.json b/package.json index dfbfc8e..d123b52 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "cordova-plugin-powermanagement-orig", + "name": "cordova-plugin-powermanagement2", "version": "1.1.0", "description": "Plugin for managing the power state (i.e. idle switching) for cordova", "scripts": { @@ -7,14 +7,14 @@ }, "repository": { "type": "git", - "url": "git+https://github.com/boltex/cordova-plugin-powermanagement.git" + "url": "git+https://github.com/sitronik/cordova-plugin-powermanagement2.git" }, - "author": "Viras-", + "author": "Sitronik", "license": "Apache-2.0", "bugs": { - "url": "https://github.com/boltex/cordova-plugin-powermanagement/issues" + "url": "https://github.com/sitronik/cordova-plugin-powermanagement2/issues" }, - "homepage": "https://github.com/boltex/cordova-plugin-powermanagement#readme", + "homepage": "https://github.com/sitronik/cordova-plugin-powermanagement2#readme", "keywords": [ "ecosystem:cordova", "cordova-android", diff --git a/src/android/PowerManagement.java b/src/android/PowerManagement.java index 7bda6d7..d98ddf3 100644 --- a/src/android/PowerManagement.java +++ b/src/android/PowerManagement.java @@ -55,33 +55,33 @@ public class PowerManagement extends CordovaPlugin { private CordovaWebView webView; private final Runnable heartbeat = new Runnable() { - public void run() { - try { - //Log.d("PowerManagementPlugin", "About to declare ourselves VISIBLE"); - webView.getEngine().getView().dispatchWindowVisibilityChanged(View.VISIBLE); + public void run() { + try { + //Log.d("PowerManagementPlugin", "About to declare ourselves 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 (wakeLock != null && powerManager != null && powerManager.isDeviceIdleMode()) { - //Log.d("PowerManagementPlugin", "Poking location service"); - try { - wakeupIntent.send(); - } catch (SecurityException e) { - Log.d("PowerManagementPlugin", "SecurityException : Heartbeat location manager keep-alive failed"); - } catch (PendingIntent.CanceledException e) { - Log.d("PowerManagementPlugin", "PendingIntent.CanceledException : Heartbeat location manager keep-alive failed"); - } - } - - } - - } finally { - if (handler != null) { - handler.postDelayed(this, 10000); - } - } - } + if (wakeLock != null && powerManager != null && powerManager.isDeviceIdleMode()) { + //Log.d("PowerManagementPlugin", "Poking location service"); + try { + wakeupIntent.send(); + } catch (SecurityException e) { + Log.d("PowerManagementPlugin", "SecurityException : Heartbeat location manager keep-alive failed"); + } catch (PendingIntent.CanceledException e) { + Log.d("PowerManagementPlugin", "PendingIntent.CanceledException : Heartbeat location manager keep-alive failed"); + } + } + + } + + } finally { + if (handler != null) { + handler.postDelayed(this, 10000); + } + } + } }; /** @@ -99,14 +99,21 @@ public class PowerManagement extends CordovaPlugin { this.powerManager = (PowerManager) cordova.getActivity().getSystemService(Context.POWER_SERVICE); handler = new Handler(); - wakeupIntent = PendingIntent.getBroadcast( context , 0, - new Intent("com.android.internal.location.ALARM_WAKEUP"), 0); + wakeupIntent = PendingIntent.getBroadcast( context , 0, + new Intent("com.android.internal.location.ALARM_WAKEUP"), 0); } + 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 { + CallbackContext callbackContext) throws JSONException { PluginResult result = null; Log.d("PowerManagementPlugin", "Plugin execute called - " + this.toString() ); @@ -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(); From dc8a177e150d3e5b49901d1c8f265db3ca047a58 Mon Sep 17 00:00:00 2001 From: Denis Date: Fri, 27 Aug 2021 22:10:56 +0300 Subject: [PATCH 2/4] update readme --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index d514947..b84f9a8 100644 --- a/README.md +++ b/README.md @@ -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 ----- From ffd278318746d25b52fe94364fcf7aeb334847af Mon Sep 17 00:00:00 2001 From: Denis Date: Sun, 29 Aug 2021 17:25:19 +0300 Subject: [PATCH 3/4] fix No visible @interface --- src/ios/PowerManagement.m | 45 +++++++++++---------------------------- 1 file changed, 13 insertions(+), 32 deletions(-) diff --git a/src/ios/PowerManagement.m b/src/ios/PowerManagement.m index 576238f..62ce952 100644 --- a/src/ios/PowerManagement.m +++ b/src/ios/PowerManagement.m @@ -1,12 +1,12 @@ /* * Copyright 2013 Wolfgang Koller - * + * * Licensed 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. @@ -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 From f989948aace7c4fbffa25443390a19a30d3a86f1 Mon Sep 17 00:00:00 2001 From: Denis Date: Sun, 29 Aug 2021 17:32:09 +0300 Subject: [PATCH 4/4] .. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d123b52..ca22276 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cordova-plugin-powermanagement2", - "version": "1.1.0", + "version": "1.1.1", "description": "Plugin for managing the power state (i.e. idle switching) for cordova", "scripts": { "test": "echo \"Error: no test specified\" && exit 1"