mirror of
https://github.com/Microsoft/calculator.git
synced 2025-08-20 13:23:13 -07:00
update launch utils
This commit is contained in:
parent
7258237c8a
commit
3e45a394ce
2 changed files with 25 additions and 18 deletions
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue