Skip to content

Commit

Permalink
refactor: use Promises over callback functions.
Browse files Browse the repository at this point in the history
BREAKING CHANGE: signature changed to Promises from callbacks
  • Loading branch information
timbru31 committed Dec 13, 2017
1 parent 1423911 commit e21473d
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 12 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
.DS_Store
node_modules/
dist/
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
os: osx
osx_image: xcode9.1
osx_image: xcode9.2

language: node_js
node_js:
Expand Down
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,28 @@

### Installation

#### from npm (recommended)
`$ cordova plugin add cordova-plugin-detect-webview-engine`

#### from git (unstable)
`$ cordova plugin add https://github.com/timbru31/cordova-plugin-detect-webview-engine.git`

### Usage

#### Check for UIWebView

```js
cordova.plugins.webviewEngine.isUIWebView(isUIWebView => {
cordova.plugins.webviewEngine.isUIWebView().then(isUIWebView => {
// returns true or false
})
});
```

#### Check for WKWebView

```js
cordova.plugins.webviewEngine.isWKWebView(isWKWebView => {
cordova.plugins.webviewEngine.isWKWebView().then(isWKWebView => {
// returns true or false
})
});
```
---
Built by (c) Tim Brust and contributors. Released under the MIT license.
18 changes: 18 additions & 0 deletions dist/www/detect-webview-engine.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"use strict";
var cordova_1 = require("cordova");
var DetectWebViewEngine = (function () {
function DetectWebViewEngine() {
}
DetectWebViewEngine.isUIWebView = function () {
return new Promise(function (resolve, reject) {
cordova_1.exec(resolve, reject, 'DetectWebViewEngine', 'isUIWebView', []);
});
};
DetectWebViewEngine.isWKWebView = function () {
return new Promise(function (resolve, reject) {
cordova_1.exec(resolve, reject, 'DetectWebViewEngine', 'isWKWebView', []);
});
};
return DetectWebViewEngine;
}());
module.exports = DetectWebViewEngine;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"scripts": {
"lint": "tslint -c tslint.json 'www/**/*.ts' && swiftlint",
"prebulish": "rm -rf dist && tsc",
"prepublish": "rm -rf dist && tsc",
"prerelease": "rm -rf dist && tsc",
"release": "standard-version"
},
Expand Down
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" id="cordova-plugin-detect-webview-engine" version="0.1.0">
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" id="cordova-plugin-detect-webview-engine" version="1.0.0">
<name>DetectWebViewEngine</name>
<description>Cordova plugin to determine whether the application is using UIWebView or WKWebView engine</description>
<author>Tim Brust</author>
Expand Down
12 changes: 8 additions & 4 deletions www/detect-webview-engine.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { exec } from 'cordova';

class DetectWebViewEngine {
static isUIWebView(successCallback: any, errorCallback: any) {
exec(successCallback, errorCallback, 'DetectWebViewEngine', 'isUIWebView', []);
static isUIWebView() {
return new Promise<boolean>((resolve, reject) => {
exec(resolve, reject, 'DetectWebViewEngine', 'isUIWebView', []);
});
}

static isWKWebView(successCallback: any, errorCallback: any) {
exec(successCallback, errorCallback, 'DetectWebViewEngine', 'isWKWebView', []);
static isWKWebView() {
return new Promise<boolean>((resolve, reject) => {
exec(resolve, reject, 'DetectWebViewEngine', 'isWKWebView', []);
});
}
}

Expand Down

0 comments on commit e21473d

Please sign in to comment.