Skip to content

Commit

Permalink
fix: callback not trigger bug
Browse files Browse the repository at this point in the history
  • Loading branch information
hejianxian committed Dec 13, 2019
1 parent 8d4d8d8 commit 0a40423
Show file tree
Hide file tree
Showing 7 changed files with 358 additions and 28 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)下载。

Expand Down
14 changes: 6 additions & 8 deletions example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,27 @@
</head>
<body>
<div>
<button id="open-app">open-desktop-application</button>
<div id="open-app">open-desktop-application</div>
</div>
<script>
window.onload = function() {
function handle() {
function handle(event) {
const params = {
protocol: 'workplus',
action: 'joinchat',
protocol: 'mailto',
action: '[email protected]',
query: {
id: 1,
name: 'test',
},
fail: function(err) {
console.log(err);
alert('err');
},
success: function() {
console.log('success');
alert('success');
},
};

openDesktopApplication(params);
};

document.getElementById('open-app').addEventListener('click', handle, false);
};
</script>
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
180 changes: 173 additions & 7 deletions lib/@w6s/open-desktop-application.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* @w6s/open-desktop-application.js v1.0.0
* @w6s/open-desktop-application.js v1.1.0
* (c) 2019 WorkPlusFE
*/

Expand Down Expand Up @@ -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) <https://lodash.com/>
* Build: `lodash modularize exports="npm" -o ./`
* Copyright JS Foundation and other contributors <https://js.foundation/>
* Released under MIT license <https://lodash.com/license>
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
* 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) <https://lodash.com/>
* Build: `lodash modern modularize exports="npm" -o ./`
Expand Down Expand Up @@ -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
Expand All @@ -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');
Expand All @@ -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);
}
}
Expand Down
6 changes: 3 additions & 3 deletions lib/@w6s/open-desktop-application.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0a40423

Please sign in to comment.