From 90f5f2531a6a354d8e8b889e707099b214d9e09d Mon Sep 17 00:00:00 2001 From: maverickmishra Date: Tue, 20 Sep 2016 10:36:36 -0700 Subject: [PATCH] Added promises to plugin --- www/screenorientation.js | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/www/screenorientation.js b/www/screenorientation.js index 77f1f9f..8aaa51f 100644 --- a/www/screenorientation.js +++ b/www/screenorientation.js @@ -1,3 +1,4 @@ +cordova.define("cordova-plugin-screen-orientation.screenorientation", function(require, exports, module) { /* * * Licensed to the Apache Software Foundation (ASF) under one @@ -72,12 +73,29 @@ } screenObject.lockOrientation = function(orientation) { - if (Orientations.indexOf(orientation) == -1) { - console.log('INVALID ORIENTATION', orientation); - return; - } - screenOrientation.currOrientation = screenObject.orientation = orientation; - screenOrientation.setOrientation(orientation); + + var p = new Promise(function(resolve,reject){ + if (Orientations.indexOf(orientation) == -1) { + // console.log('INVALID ORIENTATION', orientation); + var err = new Error(); + err.name = "NotSupportedError"; + + reject(err);//"cannot change orientation"); + + } + else { + screenOrientation.currOrientation = screenObject.orientation = orientation; + screenOrientation.setOrientation(orientation); + resolve("Orientation changed"); // orientation change successful + } + + + + + }); + return p; + + }; screenObject.unlockOrientation = function() { @@ -115,3 +133,5 @@ window.addEventListener("orientationchange", orientationChange, true); module.exports = screenOrientation; + +});