EddyVerbruggen / Custom-URL-scheme

:link: Launch your Cordova/PhoneGap app by a Custom URL scheme like mycoolapp://
1.03k stars 365 forks source link

Windows 10 UWP + Cordova 7.1.0 - "activated" fired before plugin registered #327

Open FBNitro opened 3 years ago

FBNitro commented 3 years ago
cordova.define("cordova-plugin-customurlscheme.LaunchMyApp", function(require, exports, module) {
(function () {
    function activatedHandler(e) {
        if (typeof handleOpenURL === "function" && e.uri) {
            handleOpenURL(e.uri.rawUri);
        }
    };

    document.addEventListener("activated", activatedHandler, false);
}());

});

I've traced through the UWP Cordova launch sequence, and I've found that in cordova.js, line 1392: cordova.fireDocumentEvent('activated', platform.activationContext, true); is fired before the customurlscheme plugin has registered.

So the call to handleOpenURL never occurs, because the event listener was added after the event has already fired.

dharmendra-verma commented 3 years ago

I am also experience same issue. @FBNitro any luck in resolving this?

FBNitro commented 3 years ago

In my index.js, before the 'deviceready' event, I added a listener for activated:

let activatedURI;
function activatedHandler(e) {
    if (e.uri) {
        activatedURI = e.uri.rawUri;
    }
}
document.addEventListener('activated', activatedHandler, false);

Then in the deviceready handler, before doing anything else, I removed the listener for activated, and dealt with the value if it was populated by calling window.handleOpenUrl(activatedUri); directly.