diff --git a/README.md b/README.md index dd4f6e7..43fa1d5 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ yarn add @w6s/open-desktop-application npm install @w6s/open-desktop-application -S ``` -可以直接通过`script`标签引入,全局暴露`openDesktopApplication`方法,使用方法和参数跟下面的一致,详情请查看`example/index.html`。 +可以直接通过`script`标签引入,全局暴露`openDesktopApplication`方法,使用方法和参数跟下面的一致,详情请查看[example/index.html](https://github.com/WorkPlusFE/open-desktop-application/blob/master/example/index.html)。 脚本资源请从[release页面](https://github.com/WorkPlusFE/open-desktop-application/releases)下载。 diff --git a/example/index.html b/example/index.html index c894cc4..c072d58 100644 --- a/example/index.html +++ b/example/index.html @@ -8,29 +8,27 @@
- +
open-desktop-application
diff --git a/index.js b/index.js index 25b1319..dd2f993 100644 --- a/index.js +++ b/index.js @@ -22,7 +22,7 @@ import isObject from 'lodash.isobject'; */ function openDesktopApplication(params) { try { - const { target, protocol, action, query, fail, success } = params; + const { protocol, action, query, fail, success } = params; invariant(isString(protocol), '[protocol] Must be a non-empty string'); invariant(isString(action), '[action] Must be a non-empty string'); diff --git a/lib/@w6s/open-desktop-application.js b/lib/@w6s/open-desktop-application.js index 2ef6586..b266698 100644 --- a/lib/@w6s/open-desktop-application.js +++ b/lib/@w6s/open-desktop-application.js @@ -1,5 +1,5 @@ /*! - * @w6s/open-desktop-application.js v1.0.0 + * @w6s/open-desktop-application.js v1.1.0 * (c) 2019 WorkPlusFE */ @@ -375,6 +375,171 @@ var lodash_isstring = isString; + var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; + + /** + * Lodash (Custom Build) + * Build: `lodash modularize exports="npm" -o ./` + * Copyright JS Foundation and other contributors + * Released under MIT license + * Based on Underscore.js 1.8.3 + * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors + */ + + /** `Object#toString` result references. */ + + var asyncTag = '[object AsyncFunction]', + funcTag = '[object Function]', + genTag = '[object GeneratorFunction]', + nullTag = '[object Null]', + proxyTag = '[object Proxy]', + undefinedTag = '[object Undefined]'; + /** Detect free variable `global` from Node.js. */ + + var freeGlobal = typeof commonjsGlobal == 'object' && commonjsGlobal && commonjsGlobal.Object === Object && commonjsGlobal; + /** Detect free variable `self`. */ + + var freeSelf = typeof self == 'object' && self && self.Object === Object && self; + /** Used as a reference to the global object. */ + + var root = freeGlobal || freeSelf || Function('return this')(); + /** Used for built-in method references. */ + + var objectProto$1 = Object.prototype; + /** Used to check objects for own properties. */ + + var hasOwnProperty = objectProto$1.hasOwnProperty; + /** + * Used to resolve the + * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring) + * of values. + */ + + var nativeObjectToString = objectProto$1.toString; + /** Built-in value references. */ + + var Symbol = root.Symbol, + symToStringTag = Symbol ? Symbol.toStringTag : undefined; + /** + * The base implementation of `getTag` without fallbacks for buggy environments. + * + * @private + * @param {*} value The value to query. + * @returns {string} Returns the `toStringTag`. + */ + + function baseGetTag(value) { + if (value == null) { + return value === undefined ? undefinedTag : nullTag; + } + + return symToStringTag && symToStringTag in Object(value) ? getRawTag(value) : objectToString$1(value); + } + /** + * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values. + * + * @private + * @param {*} value The value to query. + * @returns {string} Returns the raw `toStringTag`. + */ + + + function getRawTag(value) { + var isOwn = hasOwnProperty.call(value, symToStringTag), + tag = value[symToStringTag]; + + try { + value[symToStringTag] = undefined; + var unmasked = true; + } catch (e) {} + + var result = nativeObjectToString.call(value); + + if (unmasked) { + if (isOwn) { + value[symToStringTag] = tag; + } else { + delete value[symToStringTag]; + } + } + + return result; + } + /** + * Converts `value` to a string using `Object.prototype.toString`. + * + * @private + * @param {*} value The value to convert. + * @returns {string} Returns the converted string. + */ + + + function objectToString$1(value) { + return nativeObjectToString.call(value); + } + /** + * Checks if `value` is classified as a `Function` object. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a function, else `false`. + * @example + * + * _.isFunction(_); + * // => true + * + * _.isFunction(/abc/); + * // => false + */ + + + function isFunction(value) { + if (!isObject(value)) { + return false; + } // The use of `Object#toString` avoids issues with the `typeof` operator + // in Safari 9 which returns 'object' for typed arrays and other constructors. + + + var tag = baseGetTag(value); + return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag; + } + /** + * Checks if `value` is the + * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types) + * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`) + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is an object, else `false`. + * @example + * + * _.isObject({}); + * // => true + * + * _.isObject([1, 2, 3]); + * // => true + * + * _.isObject(_.noop); + * // => true + * + * _.isObject(null); + * // => false + */ + + + function isObject(value) { + var type = typeof value; + return value != null && (type == 'object' || type == 'function'); + } + + var lodash_isfunction = isFunction; + /** * lodash 3.0.2 (Custom Build) * Build: `lodash modern modularize exports="npm" -o ./` @@ -404,14 +569,14 @@ * _.isObject(1); * // => false */ - function isObject(value) { + function isObject$1(value) { // Avoid a V8 JIT bug in Chrome 19-20. // See https://code.google.com/p/v8/issues/detail?id=2291 for more details. var type = typeof value; return !!value && (type == 'object' || type == 'function'); } - var lodash_isobject = isObject; + var lodash_isobject = isObject$1; /** * open-desktop-application @@ -432,7 +597,7 @@ var protocol = params.protocol, action = params.action, query = params.query, - fail = params.fail, + _fail = params.fail, success = params.success; invariant_1(lodash_isstring(protocol), '[protocol] Must be a non-empty string'); invariant_1(lodash_isstring(action), '[action] Must be a non-empty string'); @@ -443,15 +608,16 @@ } customProtocolDetection(openUri, function failCb(e) { - lodash_isstring(fail) && fail(e); + lodash_isfunction(_fail) && _fail(e); }, function successCb() { - lodash_isstring(success) && success(); + lodash_isfunction(success) && success(); }, function unsupportedCb() { - lodash_isstring(fail) && fail({ + lodash_isfunction(_fail) && _fail({ supported: false }); }); } catch (error) { + lodash_isfunction(fail) && fail(error); console.log(error); } } diff --git a/lib/@w6s/open-desktop-application.min.js b/lib/@w6s/open-desktop-application.min.js index ec29e49..088c70b 100644 --- a/lib/@w6s/open-desktop-application.min.js +++ b/lib/@w6s/open-desktop-application.min.js @@ -1,8 +1,8 @@ /*! - * @w6s/open-desktop-application.js v1.0.0 + * @w6s/open-desktop-application.js v1.1.0 * (c) 2019 WorkPlusFE */ -!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e=e||self).openDesktopApplication=n()}(this,function(){"use strict";function f(e,n,t){return e.addEventListener?(e.addEventListener(n,t),{remove:function(){e.removeEventListener(n,t)}}):(e.attachEvent(n,t),{remove:function(){e.detachEvent(n,t)}})}function d(e,n){var t=document.createElement("iframe");return t.src=n,t.id="hiddenIframe",t.style.display="none",e.appendChild(t),t}function s(e,n,t){var o=setTimeout(function(){n(),i.remove()},1e3),r=document.querySelector("#hiddenIframe");r=r||d(document.body,"about:blank");var i=f(window,"blur",function(){clearTimeout(o),i.remove(),t()});r.contentWindow.location.href=e}function l(e,n,t){var o,r,i,a;10===c()?function(e,n,t){var o=setTimeout(n,1e3);window.addEventListener("blur",function(){clearTimeout(o),t()});var r=document.querySelector("#hiddenIframe");r=r||d(document.body,"about:blank");try{r.contentWindow.location.href=e}catch(e){n(),clearTimeout(o)}}(e,n,t):9===c()||11===c()?s(e,n,t):(o=e,r=n,i=t,(a=window.open("","","width=0,height=0")).document.write(""),setTimeout(function(){try{a.setTimeout("window.close()",1e3),i()}catch(e){a.close(),r()}},1e3))}function c(){var e=-1;if("Microsoft Internet Explorer"===navigator.appName){var n=navigator.userAgent;null!=/MSIE ([0-9]{1,}[.0-9]{0,})/.exec(n)&&(e=parseFloat(RegExp.$1))}else if("Netscape"===navigator.appName){n=navigator.userAgent;null!=/Trident\/.*rv:([0-9]{1,}[.0-9]{0,})/.exec(n)&&(e=parseFloat(RegExp.$1))}return e}function u(e,n,t,o){function r(){n&&n()}function i(){t&&t()}if(navigator.msLaunchUri)navigator.msLaunchUri(e,t,n);else{var a=(c=!!window.opera||!!~navigator.userAgent.indexOf(" OPR/"),u=navigator.userAgent.toLowerCase(),{isOpera:c,isFirefox:"undefined"!=typeof InstallTrigger,isSafari:~u.indexOf("safari")&&!~u.indexOf("chrome")||0"),setTimeout(function(){try{a.setTimeout("window.close()",1e3),i()}catch(e){a.close(),r()}},1e3))}function c(){var e=-1;if("Microsoft Internet Explorer"===navigator.appName){var n=navigator.userAgent;null!=/MSIE ([0-9]{1,}[.0-9]{0,})/.exec(n)&&(e=parseFloat(RegExp.$1))}else if("Netscape"===navigator.appName){n=navigator.userAgent;null!=/Trident\/.*rv:([0-9]{1,}[.0-9]{0,})/.exec(n)&&(e=parseFloat(RegExp.$1))}return e}function u(e,n,t,o){function r(){n&&n()}function i(){t&&t()}if(navigator.msLaunchUri)navigator.msLaunchUri(e,t,n);else{var a=(c=!!window.opera||!!~navigator.userAgent.indexOf(" OPR/"),u=navigator.userAgent.toLowerCase(),{isOpera:c,isFirefox:"undefined"!=typeof InstallTrigger,isSafari:~u.indexOf("safari")&&!~u.indexOf("chrome")||0 workplus://joinchat/?id=1&name=test - */return function(e){try{var n=e.protocol,t=e.action,o=e.query,r=e.fail,i=e.success;m(v(n),"[protocol] Must be a non-empty string"),m(v(t),"[action] Must be a non-empty string");var a="".concat(n,"://").concat(t);p(o)&&(a+="?".concat(function(e){var t=0 + * Build: `lodash modularize exports="npm" -o ./` + * Copyright JS Foundation and other contributors + * Released under MIT license + * Based on Underscore.js 1.8.3 + * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors + */ + +/** `Object#toString` result references. */ + +var asyncTag = '[object AsyncFunction]', + funcTag = '[object Function]', + genTag = '[object GeneratorFunction]', + nullTag = '[object Null]', + proxyTag = '[object Proxy]', + undefinedTag = '[object Undefined]'; +/** Detect free variable `global` from Node.js. */ + +var freeGlobal = typeof commonjsGlobal == 'object' && commonjsGlobal && commonjsGlobal.Object === Object && commonjsGlobal; +/** Detect free variable `self`. */ + +var freeSelf = typeof self == 'object' && self && self.Object === Object && self; +/** Used as a reference to the global object. */ + +var root = freeGlobal || freeSelf || Function('return this')(); +/** Used for built-in method references. */ + +var objectProto$1 = Object.prototype; +/** Used to check objects for own properties. */ + +var hasOwnProperty = objectProto$1.hasOwnProperty; +/** + * Used to resolve the + * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring) + * of values. + */ + +var nativeObjectToString = objectProto$1.toString; +/** Built-in value references. */ + +var Symbol = root.Symbol, + symToStringTag = Symbol ? Symbol.toStringTag : undefined; +/** + * The base implementation of `getTag` without fallbacks for buggy environments. + * + * @private + * @param {*} value The value to query. + * @returns {string} Returns the `toStringTag`. + */ + +function baseGetTag(value) { + if (value == null) { + return value === undefined ? undefinedTag : nullTag; + } + + return symToStringTag && symToStringTag in Object(value) ? getRawTag(value) : objectToString$1(value); +} +/** + * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values. + * + * @private + * @param {*} value The value to query. + * @returns {string} Returns the raw `toStringTag`. + */ + + +function getRawTag(value) { + var isOwn = hasOwnProperty.call(value, symToStringTag), + tag = value[symToStringTag]; + + try { + value[symToStringTag] = undefined; + var unmasked = true; + } catch (e) {} + + var result = nativeObjectToString.call(value); + + if (unmasked) { + if (isOwn) { + value[symToStringTag] = tag; + } else { + delete value[symToStringTag]; + } + } + + return result; +} +/** + * Converts `value` to a string using `Object.prototype.toString`. + * + * @private + * @param {*} value The value to convert. + * @returns {string} Returns the converted string. + */ + + +function objectToString$1(value) { + return nativeObjectToString.call(value); +} +/** + * Checks if `value` is classified as a `Function` object. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a function, else `false`. + * @example + * + * _.isFunction(_); + * // => true + * + * _.isFunction(/abc/); + * // => false + */ + + +function isFunction(value) { + if (!isObject(value)) { + return false; + } // The use of `Object#toString` avoids issues with the `typeof` operator + // in Safari 9 which returns 'object' for typed arrays and other constructors. + + + var tag = baseGetTag(value); + return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag; +} +/** + * Checks if `value` is the + * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types) + * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`) + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is an object, else `false`. + * @example + * + * _.isObject({}); + * // => true + * + * _.isObject([1, 2, 3]); + * // => true + * + * _.isObject(_.noop); + * // => true + * + * _.isObject(null); + * // => false + */ + + +function isObject(value) { + var type = typeof value; + return value != null && (type == 'object' || type == 'function'); +} + +var lodash_isfunction = isFunction; + /** * lodash 3.0.2 (Custom Build) * Build: `lodash modern modularize exports="npm" -o ./` @@ -398,14 +563,14 @@ var lodash_isstring = isString; * _.isObject(1); * // => false */ -function isObject(value) { +function isObject$1(value) { // Avoid a V8 JIT bug in Chrome 19-20. // See https://code.google.com/p/v8/issues/detail?id=2291 for more details. var type = typeof value; return !!value && (type == 'object' || type == 'function'); } -var lodash_isobject = isObject; +var lodash_isobject = isObject$1; /** * open-desktop-application @@ -426,7 +591,7 @@ function openDesktopApplication(params) { var protocol = params.protocol, action = params.action, query = params.query, - fail = params.fail, + _fail = params.fail, success = params.success; invariant_1(lodash_isstring(protocol), '[protocol] Must be a non-empty string'); invariant_1(lodash_isstring(action), '[action] Must be a non-empty string'); @@ -437,15 +602,16 @@ function openDesktopApplication(params) { } customProtocolDetection(openUri, function failCb(e) { - lodash_isstring(fail) && fail(e); + lodash_isfunction(_fail) && _fail(e); }, function successCb() { - lodash_isstring(success) && success(); + lodash_isfunction(success) && success(); }, function unsupportedCb() { - lodash_isstring(fail) && fail({ + lodash_isfunction(_fail) && _fail({ supported: false }); }); } catch (error) { + lodash_isfunction(fail) && fail(error); console.log(error); } } diff --git a/package.json b/package.json index c13d9ba..4d7664a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@w6s/open-desktop-application", - "version": "1.1.0", + "version": "1.2.0", "description": "通过 URL协议 打开桌面应用", "main": "lib/@w6s/open-desktop-application.js", "main:min": "lib/@w6s/open-desktop-application.min.js",