OnLaunch always starts a new instance of Uno ? #12933
-
On Windows, I'm running into an issue where it seems like the OnLaunch() function always starts up a new instance of the application, with all variables reverting to their default values. In the following example, when the application is activated by a uri scheme redirection (defined in the appxmanifest's "Declarations" section), the OnLaunch function is raised. As pointed out in other threads, the WinUI OnActivated fuction doesn't exist, so I'm trying to workaround this by checking why the protected async override void OnLaunched(LaunchActivatedEventArgs args)
{
#if !HAS_UNO
var activatedArgs = AppInstance.GetCurrent().GetActivatedEventArgs();
var activationKind = activatedArgs.Kind;
if (activationKind == ExtendedActivationKind.Protocol) // true when redirecting. Else = "Launch" when starting app
{
OnApplicationActivated();
return;
}
#endif
SetupHosting();
InitializeAndActivateWindow();
} When the application is first started up, the For instance, the private void OnApplicationActivated()
{
#if !HAS_UNO
var activatedEventArgs = AppInstance.GetCurrent().GetActivatedEventArgs();
if (activatedEventArgs.Data is ProtocolActivatedEventArgs protocolArgs)
{
UriSchemeActivated?.Invoke(this, protocolArgs.Uri);
}
#endif
} I don't know if this is expected behaviour, or if I'm doing something wrong, but a new process seems to be started up, despite the fact that the application identifies this as being a To sum things up, my question is : is this expected behaviour ? And more importantly, is there a way that I can receive an activation of the application without the OnLaunched function creating a whole new instance ? Thanks ! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Thanks for the feedback. To be sure of the scope of the question, when you're saying "On Windows", do you mean the |
Beta Was this translation helpful? Give feedback.
Okay so after some digging, this is apparently normal in WinUI3. There is a workaround solution provided in this repo in which the application registers itself with a key and any subsequent launches are checked against it. If it detects that an application instance is already running, the arguments are forwarded to that instance and the new process is killed.
Here's the gist of it :