summaryrefslogtreecommitdiff
path: root/plugins/nl.x-services.plugins.insomnia/src
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/nl.x-services.plugins.insomnia/src')
-rw-r--r--plugins/nl.x-services.plugins.insomnia/src/android/nl/xservices/plugins/Insomnia.java47
-rw-r--r--plugins/nl.x-services.plugins.insomnia/src/firefoxos/insomnia.js16
-rwxr-xr-xplugins/nl.x-services.plugins.insomnia/src/ios/Insomnia.h9
-rwxr-xr-xplugins/nl.x-services.plugins.insomnia/src/ios/Insomnia.m32
-rw-r--r--plugins/nl.x-services.plugins.insomnia/src/wp8/Insomnia.cs19
5 files changed, 123 insertions, 0 deletions
diff --git a/plugins/nl.x-services.plugins.insomnia/src/android/nl/xservices/plugins/Insomnia.java b/plugins/nl.x-services.plugins.insomnia/src/android/nl/xservices/plugins/Insomnia.java
new file mode 100644
index 00000000..95094938
--- /dev/null
+++ b/plugins/nl.x-services.plugins.insomnia/src/android/nl/xservices/plugins/Insomnia.java
@@ -0,0 +1,47 @@
+package nl.xservices.plugins;
+
+import android.view.WindowManager;
+import org.apache.cordova.CallbackContext;
+import org.apache.cordova.CordovaPlugin;
+import org.apache.cordova.PluginResult;
+import org.json.JSONArray;
+import org.json.JSONException;
+
+public class Insomnia extends CordovaPlugin {
+
+ private static final String ACTION_KEEP_AWAKE = "keepAwake";
+ private static final String ACTION_ALLOW_SLEEP_AGAIN = "allowSleepAgain";
+
+ @Override
+ public boolean execute(String action, JSONArray args, final CallbackContext callbackContext) throws JSONException {
+ try {
+ if (ACTION_KEEP_AWAKE.equals(action)) {
+ cordova.getActivity().runOnUiThread(
+ new Runnable() {
+ public void run() {
+ cordova.getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
+ callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK));
+ }
+ });
+ return true;
+
+ } else if (ACTION_ALLOW_SLEEP_AGAIN.equals(action)) {
+ cordova.getActivity().runOnUiThread(
+ new Runnable() {
+ public void run() {
+ cordova.getActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
+ callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK));
+ }
+ });
+ return true;
+
+ } else {
+ callbackContext.error("insomnia." + action + " is not a supported function. Did you mean '" + ACTION_KEEP_AWAKE + "'?");
+ return false;
+ }
+ } catch (Exception e) {
+ callbackContext.error(e.getMessage());
+ return false;
+ }
+ }
+}
diff --git a/plugins/nl.x-services.plugins.insomnia/src/firefoxos/insomnia.js b/plugins/nl.x-services.plugins.insomnia/src/firefoxos/insomnia.js
new file mode 100644
index 00000000..ed4ea3af
--- /dev/null
+++ b/plugins/nl.x-services.plugins.insomnia/src/firefoxos/insomnia.js
@@ -0,0 +1,16 @@
+var lock;
+
+module.exports = {
+ keepAwake: function() {
+ if (navigator.requestWakeLock) {
+ lock = navigator.requestWakeLock("screen");
+ }
+ },
+ allowSleepAgain: function() {
+ if (lock && typeof lock.unlock === "function") {
+ lock.unlock();
+ }
+ }
+};
+
+require("cordova/exec/proxy").add("Insomnia", module.exports);
diff --git a/plugins/nl.x-services.plugins.insomnia/src/ios/Insomnia.h b/plugins/nl.x-services.plugins.insomnia/src/ios/Insomnia.h
new file mode 100755
index 00000000..c13c07ba
--- /dev/null
+++ b/plugins/nl.x-services.plugins.insomnia/src/ios/Insomnia.h
@@ -0,0 +1,9 @@
+#import <Cordova/CDV.h>
+
+@interface Insomnia :CDVPlugin
+
+- (void) keepAwake:(CDVInvokedUrlCommand*)command;
+
+- (void) allowSleepAgain:(CDVInvokedUrlCommand*)command;
+
+@end
diff --git a/plugins/nl.x-services.plugins.insomnia/src/ios/Insomnia.m b/plugins/nl.x-services.plugins.insomnia/src/ios/Insomnia.m
new file mode 100755
index 00000000..7eca3b07
--- /dev/null
+++ b/plugins/nl.x-services.plugins.insomnia/src/ios/Insomnia.m
@@ -0,0 +1,32 @@
+#import "Insomnia.h"
+#import <Cordova/CDV.h>
+
+@implementation Insomnia
+
+- (void) keepAwake:(CDVInvokedUrlCommand*)command {
+ NSString *callbackId = command.callbackId;
+
+ // Acquire a reference to the local UIApplication singleton
+ UIApplication* app = [UIApplication sharedApplication];
+
+ if (![app isIdleTimerDisabled]) {
+ [app setIdleTimerDisabled:true];
+ }
+ CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
+ [self.commandDelegate sendPluginResult:result callbackId:callbackId];
+}
+
+- (void) allowSleepAgain:(CDVInvokedUrlCommand*)command {
+ NSString *callbackId = command.callbackId;
+
+ // Acquire a reference to the local UIApplication singleton
+ UIApplication* app = [UIApplication sharedApplication];
+
+ if([app isIdleTimerDisabled]) {
+ [app setIdleTimerDisabled:false];
+ }
+ CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
+ [self.commandDelegate sendPluginResult:result callbackId:callbackId];
+}
+
+@end \ No newline at end of file
diff --git a/plugins/nl.x-services.plugins.insomnia/src/wp8/Insomnia.cs b/plugins/nl.x-services.plugins.insomnia/src/wp8/Insomnia.cs
new file mode 100644
index 00000000..034d1711
--- /dev/null
+++ b/plugins/nl.x-services.plugins.insomnia/src/wp8/Insomnia.cs
@@ -0,0 +1,19 @@
+using Microsoft.Phone.Shell;
+
+namespace WPCordovaClassLib.Cordova.Commands
+{
+ public class Insomnia : BaseCommand
+ {
+ public void keepAwake(string options)
+ {
+ PhoneApplicationService.Current.UserIdleDetectionMode = IdleDetectionMode.Disabled;
+ DispatchCommandResult(new PluginResult(PluginResult.Status.OK));
+ }
+
+ public void allowSleepAgain(string options)
+ {
+ PhoneApplicationService.Current.UserIdleDetectionMode = IdleDetectionMode.Enabled;
+ DispatchCommandResult(new PluginResult(PluginResult.Status.OK));
+ }
+ }
+}