1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-23 02:10:12 +01:00
metamask-extension/shared/lib/deep-linking.js

21 lines
712 B
JavaScript
Raw Normal View History

export function openCustomProtocol(protocolLink) {
return new Promise((resolve, reject) => {
// msLaunchUri is windows specific. It will open and app or service
// that handles a given protocol
if (window?.navigator?.msLaunchUri) {
window.navigator.msLaunchUri(protocolLink, resolve, () => {
reject(new Error('Failed to open custom protocol link'));
});
} else {
const timeoutId = window.setTimeout(function () {
reject(new Error('Timeout opening custom protocol link'));
}, 500);
window.addEventListener('blur', function () {
window.clearTimeout(timeoutId);
resolve();
});
window.location = protocolLink;
}
});
}