diff --git a/src/Calculator/App.xaml.cs b/src/Calculator/App.xaml.cs index 78254322..13fe4a6f 100644 --- a/src/Calculator/App.xaml.cs +++ b/src/Calculator/App.xaml.cs @@ -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) diff --git a/src/Calculator/Common/LaunchArguments.cs b/src/Calculator/Common/LaunchArguments.cs index 0686e1aa..ee643fab 100644 --- a/src/Calculator/Common/LaunchArguments.cs +++ b/src/Calculator/Common/LaunchArguments.cs @@ -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; + } } }