update launch utils

This commit is contained in:
Tian Liao 2024-10-17 16:45:19 +08:00
commit 3e45a394ce
2 changed files with 25 additions and 18 deletions

View file

@ -73,23 +73,19 @@ namespace CalculatorApp
protected override void OnActivated(IActivatedEventArgs args)
{
if (args.Kind != ActivationKind.Protocol) return;
if (args.IsSnapshotProtocol())
if (args.Kind != ActivationKind.Protocol)
{
var protoArgs = (IProtocolActivatedEventArgs)args;
OnAppLaunch(args,
new SnapshotLaunchArguments
{
Snapshot = null // TODO:
},
false);
return;
}
else if (args.TryGetSnapshotProtocol(out var protoArgs))
{
OnAppLaunch(args, protoArgs.GetSnapshotLaunchArgs(), false);
}
else
{
// handle any unknown protocol launch as a normal app launch.
OnAppLaunch(args, null, false);
}
}
}
private void OnAppLaunch(IActivatedEventArgs args, object arguments, bool isPreLaunch)

View file

@ -7,16 +7,27 @@ namespace CalculatorApp
{
internal class SnapshotLaunchArguments
{
public ApplicationSnapshot Snapshot;
public bool HasError { get; set; }
public ApplicationSnapshot Snapshot { get; set; }
}
internal static class LaunchExtensions
{
public static bool IsSnapshotProtocol(this IActivatedEventArgs args) =>
args is IProtocolActivatedEventArgs protoArgs &&
protoArgs.Uri != null &&
protoArgs.Uri.Segments != null &&
protoArgs.Uri.Segments.Length == 2 &&
protoArgs.Uri.Segments[0] == "snapshot/";
public static bool TryGetSnapshotProtocol(this IActivatedEventArgs args, out IProtocolActivatedEventArgs result)
{
result = null;
var protoArgs = args as IProtocolActivatedEventArgs;
if (protoArgs == null || protoArgs.Uri == null)
{
return false;
}
result = protoArgs;
return true;
}
public static SnapshotLaunchArguments GetSnapshotLaunchArgs(this IProtocolActivatedEventArgs args)
{
return null;
}
}
}