79406418

Date: 2025-02-02 10:41:04
Score: 2
Natty:
Report link

Solution was:

// In your App.xaml.cs

public partial class App : MauiWinUIApplication
{
    // ...

    protected override async void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)
    {
        var appInstance = AppInstance.GetCurrent();
        var e = appInstance.GetActivatedEventArgs();

        // If it's not a Protocol activation, just launch the app normally
        if (e.Kind != ExtendedActivationKind.Protocol ||
            e.Data is not ProtocolActivatedEventArgs protocol)
        {
            appInstance.Activated += AppInstance_Activated;

            base.OnLaunched(args);
            return;
        }

        // If it's a Protocol activation, redirect it to other instances
        var instances = AppInstance.GetInstances();
        await Task.WhenAll(instances
            .Select(async q => await q.RedirectActivationToAsync(e)));

        return;
    }

    private void AppInstance_Activated(object? sender, AppActivationArguments e)
    {
        if (e.Kind != ExtendedActivationKind.Protocol ||
            e.Data is not ProtocolActivatedEventArgs protocol)        
        {
            return;
        }

        // Process your activation here
        Debug.WriteLine("URI activated: " + protocol.Uri);
    }

}

Also answered here: https://stackoverflow.com/a/79123126/17302880

Reasons:
  • Blacklisted phrase (1): stackoverflow
  • Probably link only (1):
  • Long answer (-1):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: SoldatXwing