mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-22 18:00:18 +01:00
21 lines
712 B
JavaScript
21 lines
712 B
JavaScript
|
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;
|
||
|
}
|
||
|
});
|
||
|
}
|