Permalink
Browse files

Updating PowerManagement plugin for iOS and Cordova 1.6

Updating Readme for Android & iOS
  • Loading branch information...
1 parent 8a54319 commit 0ee25747e4aa80261537d6535c062810983020af @Viras- Viras- committed May 2, 2012
@@ -20,14 +20,13 @@ Copy the *PowerManagement.java* file to your *src/* directory.
Edit your *AndroidManifest.xml* and add the following permission:
`<uses-permission android:name="android.permission.WAKE_LOCK" />`
-In addition you have to edit your *res/xml/plugins.xml* file to let PhoneGap know about the plugin:
+In addition you have to edit your *res/xml/plugins.xml* file to let Cordova know about the plugin:
`<plugin name="PowerManagement" value="org.apache.cordova.plugin.PowerManagement"/>`
### iOS
-Copy the *PowerManagement.h* and *PowerManagement.m* files to your project.
+Copy the *PowerManagement.h* and *PowerManagement.m* files to your projects "Plugins" folder.
-Add the PowerManagement plugin to the *PhoneGap.plist*:
-See http://wiki.phonegap.com/w/page/41733808/PhoneGap-iOS-Plugins-Problems
+Add the PowerManagement plugin to the *Cordova.plist* file (to the Plugins list). Both Key and Value are "PowerManagement".
License
File renamed without changes.
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2011 Wolfgang Koller
+ * Copyright (C) 2011-2012 Wolfgang Koller
*
* This file is part of GOFG Sports Computer - http://www.gofg.at/.
*
@@ -18,20 +18,19 @@
*/
/**
- * PhoneGap (iOS) plugin for accessing the power-management functions of the device
+ * Cordova (iOS) plugin for accessing the power-management functions of the device
*/
-#import <Foundation/Foundation.h>
-#import <UIKit/UIApplication.h>
-#ifdef PHONEGAP_FRAMEWORK
-#import <PhoneGap/PGPlugin.h>
+
+#ifdef CORDOVA_FRAMEWORK
+#import <CORDOVA/CDVPlugin.h>
#else
-#import "PGPlugin.h"
+#import "CORDOVA/CDVPlugin.h"
#endif
/**
* Interface which does the actual handling
*/
-@interface PowerManagement : PGPlugin {
+@interface PowerManagement :CDVPlugin {
}
/**
* Sets the idleTimerDisable property to true so that the idle timeout is disabled
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2011 Wolfgang Koller
+ * Copyright (C) 2011-2012 Wolfgang Koller
*
* This file is part of GOFG Sports Computer - http://www.gofg.at/.
*
@@ -18,7 +18,7 @@
*/
/**
- * PhoneGap (iOS) plugin for accessing the power-management functions of the device
+ * Cordova (iOS) plugin for accessing the power-management functions of the device
*/
#import "PowerManagement.h"
@@ -28,7 +28,7 @@
@implementation PowerManagement
- (void) acquire:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
{
- PluginResult* result = nil;
+ CDVPluginResult* result = nil;
NSString* jsString = nil;
NSString* callbackId = [arguments objectAtIndex:0];
@@ -38,11 +38,11 @@ - (void) acquire:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)optio
if( ![app isIdleTimerDisabled] ) {
[app setIdleTimerDisabled:true];
- result = [PluginResult resultWithStatus:PGCommandStatus_OK];
+ result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
jsString = [result toSuccessCallbackString:callbackId];
}
else {
- result = [PluginResult resultWithStatus:PGCommandStatus_ILLEGAL_ACCESS_EXCEPTION messageAsString:@"IdleTimer already disabled"];
+ result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ILLEGAL_ACCESS_EXCEPTION messageAsString:@"IdleTimer already disabled"];
jsString = [result toErrorCallbackString:callbackId];
}
@@ -52,7 +52,7 @@ - (void) acquire:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)optio
- (void) release:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
{
- PluginResult* result = nil;
+ CDVPluginResult* result = nil;
NSString* jsString = nil;
NSString* callbackId = [arguments objectAtIndex:0];
@@ -62,11 +62,11 @@ - (void) release:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)optio
if( [app isIdleTimerDisabled] ) {
[app setIdleTimerDisabled:false];
- result = [PluginResult resultWithStatus:PGCommandStatus_OK];
+ result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
jsString = [result toSuccessCallbackString:callbackId];
}
else {
- result = [PluginResult resultWithStatus:PGCommandStatus_ILLEGAL_ACCESS_EXCEPTION messageAsString:@"IdleTimer not disabled"];
+ result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ILLEGAL_ACCESS_EXCEPTION messageAsString:@"IdleTimer not disabled"];
jsString = [result toErrorCallbackString:callbackId];
}
@@ -1,6 +1,6 @@
PowerManagement
===============
-Plugin for PhoneGap
+Plugin for Cordova (1.6+)
The PowerManagement plugin offers access to the devices power-management functionality.
It should be used for applications which keep running for a long time without any user interaction.
@@ -14,12 +14,24 @@ Platforms
---------
Currently available on:
-* Android (don't forget android.permission.WAKE_LOCK in your AndroidManifest.xml)
-* iOS (don't forget to add it to your PhoneGap.plist)
+### Android
+Copy the *PowerManagement.java* file to your *src/* directory.
+
+Edit your *AndroidManifest.xml* and add the following permission:
+`<uses-permission android:name="android.permission.WAKE_LOCK" />`
+
+In addition you have to edit your *res/xml/plugins.xml* file to let Cordova know about the plugin:
+`<plugin name="PowerManagement" value="org.apache.cordova.plugin.PowerManagement"/>`
+
+### iOS
+Copy the *PowerManagement.h* and *PowerManagement.m* files to your projects "Plugins" folder.
+
+Add the PowerManagement plugin to the *Cordova.plist* file (to the Plugins list). Both Key and Value are "PowerManagement".
+
License
=======
-Copyright (C) 2011 Wolfgang Koller
+Copyright (C) 2011-2012 Wolfgang Koller
This file is part of GOFG Sports Computer - http://www.gofg.at/.
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2011-2012 Wolfgang Koller
+ *
+ * This file is part of GOFG Sports Computer - http://www.gofg.at/.
+ *
+ * GOFG Sports Computer is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GOFG Sports Computer is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GOFG Sports Computer. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+cordova.define("cordova/plugin/powermanagement", function(require, exports, module) {
+ var exec = require('cordova/exec');
+
+ var PowerManagement = function() {};
+
+ /**
+ * Acquire a new wake-lock (keep device awake)
+ *
+ * @param successCallback function to be called when the wake-lock was acquired successfully
+ * @param errorCallback function to be called when there was a problem with acquiring the wake-lock
+ */
+ PowerManagement.prototype.acquire = function(successCallback,failureCallback) {
+ exec(successCallback, failureCallback, 'PowerManagement', 'acquire', []);
+ }
+
+ /**
+ * Release the wake-lock
+ *
+ * @param successCallback function to be called when the wake-lock was released successfully
+ * @param errorCallback function to be called when there was a problem while releasing the wake-lock
+ */
+ PowerManagement.prototype.release = function(successCallback,failureCallback) {
+ exec(successCallback, failureCallback, 'PowerManagement', 'release', []);
+ }
+
+ /**
+ * Acquire a partial wake-lock, allowing the device to dim the screen
+ *
+ * @param successCallback function to be called when the wake-lock was acquired successfully
+ * @param errorCallback function to be called when there was a problem with acquiring the wake-lock
+ */
+ PowerManagement.prototype.dim = function(successCallback,failureCallback) {
+ exec(successCallback, failureCallback, 'PowerManagement', 'acquire', [true]);
+ }
+
+ var powermanagement = new PowerManagement();
+ module.exports = powermanagement;
+});
@@ -1,71 +0,0 @@
-/*
- * Copyright (C) 2011 Wolfgang Koller
- *
- * This file is part of GOFG Sports Computer - http://www.gofg.at/.
- *
- * GOFG Sports Computer is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * GOFG Sports Computer is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with GOFG Sports Computer. If not, see <http://www.gnu.org/licenses/>.
- */
-
-if( !PhoneGap.hasResource("powermanagement") ) {
- PhoneGap.addResource("powermanagement");
-
- /**
- * @returns instance of powermanagement
- */
- function PowerManagement() {
- };
-
- /**
- * Acquire a new wake-lock (keep device awake)
- *
- * @param successCallback function to be called when the wake-lock was acquired successfully
- * @param errorCallback function to be called when there was a problem with acquiring the wake-lock
- */
- PowerManagement.prototype.acquire = function(successCallback, errorCallback) {
- PhoneGap.exec(successCallback, errorCallback, "PowerManagement", "acquire", []);
- };
-
- /**
- * Release the wake-lock
- *
- * @param successCallback function to be called when the wake-lock was released successfully
- * @param errorCallback function to be called when there was a problem while releasing the wake-lock
- */
- PowerManagement.prototype.release = function(successCallback, errorCallback) {
- PhoneGap.exec(successCallback, errorCallback, "PowerManagement", "release", []);
- };
-
- /**
- * NOT SUPPORTED ON iOS (by design)
- *
- * @param successCallback function to be called when the wake-lock was acquired successfully
- * @param errorCallback function to be called when there was a problem with acquiring the wake-lock
- */
- PowerManagement.prototype.dim = function(successCallback, errorCallback) {
- errorCallback( "Not supported" );
- };
-
- /**
- * Register the plugin with PhoneGap
- */
- PowerManagement.install = function() {
- if(!window.plugins) window.plugins = {};
-
- window.plugins.PowerManagement = new PowerManagement();
-
- return window.plugins.PowerManagement;
- };
-
- PhoneGap.addConstructor(PowerManagement.install);
-}

0 comments on commit 0ee2574

Please sign in to comment.