mirror of
https://github.com/Microsoft/calculator.git
synced 2025-08-20 21:33:10 -07:00
Merged PR 10772614: Recall | Update the LaunchURI design
## What Since `System.Uri` already has the `Segment` property which contains the parsed path blocks, Query in Uri looks too heavy and intrusive in implementation to retrieve the activity id. ## Changes Changed the launch URI from something like `ms-calculator:///snapshot?activityId=<a guid>` to `ms-calculator:snapshots/<a guid>` Related work items: #50854714
This commit is contained in:
parent
c4be28fbfc
commit
2bfb4c0a7e
2 changed files with 13 additions and 21 deletions
|
@ -1,5 +1,4 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
|
||||
using Windows.ApplicationModel.Activation;
|
||||
using Windows.ApplicationModel.UserActivities;
|
||||
|
@ -17,35 +16,29 @@ namespace CalculatorApp
|
|||
public static bool IsSnapshotProtocol(this IActivatedEventArgs args) =>
|
||||
args is IProtocolActivatedEventArgs protoArgs &&
|
||||
protoArgs.Uri != null &&
|
||||
protoArgs.Uri.AbsolutePath == "/snapshot" &&
|
||||
!string.IsNullOrEmpty(protoArgs.Uri.Query);
|
||||
protoArgs.Uri.Segments != null &&
|
||||
protoArgs.Uri.Segments.Length == 2 &&
|
||||
protoArgs.Uri.Segments[0] == "snapshots/";
|
||||
|
||||
/// <summary>
|
||||
/// GetActivityId() requires the parameter `launchUri` to be a well-formed
|
||||
/// snapshot URI.
|
||||
/// </summary>
|
||||
/// <param name="launchUri"></param>
|
||||
/// <returns></returns>
|
||||
/// <param name="launchUri">the Uri to launch with a snapshot context.</param>
|
||||
/// <returns>Activity ID</returns>
|
||||
public static string GetActivityId(this Uri launchUri)
|
||||
{
|
||||
const string ActivityIdKey = "activityId=";
|
||||
var segment = launchUri.Query.Split('?', '&').FirstOrDefault(x => x.StartsWith(ActivityIdKey));
|
||||
if (segment != null)
|
||||
{
|
||||
segment = segment.Trim();
|
||||
return segment.Length > ActivityIdKey.Length ?
|
||||
segment.Substring(ActivityIdKey.Length) :
|
||||
string.Empty;
|
||||
}
|
||||
return string.Empty;
|
||||
return launchUri.Segments[1].Trim();
|
||||
}
|
||||
|
||||
public static bool VerifyIncomingActivity(this SnapshotLaunchArguments launchArgs, UserActivity activity)
|
||||
{
|
||||
if (string.IsNullOrEmpty(activity.ActivityId) ||
|
||||
if (activity.State != UserActivityState.Published ||
|
||||
string.IsNullOrEmpty(activity.ActivityId) ||
|
||||
activity.ActivationUri == null ||
|
||||
activity.ActivationUri.AbsolutePath != "/snapshot" ||
|
||||
string.IsNullOrEmpty(activity.ActivationUri.Query))
|
||||
activity.ActivationUri.Segments == null ||
|
||||
activity.ActivationUri.Segments.Length != 2 ||
|
||||
activity.ActivationUri.Segments[0] != "snapshots/")
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -66,13 +66,12 @@ namespace CalculatorApp
|
|||
}
|
||||
var channel = UserActivityChannel.GetDefault();
|
||||
var activity = await channel.GetOrCreateUserActivityAsync($"{Guid.NewGuid()}");
|
||||
activity.ActivationUri = new Uri($"ms-calculator:///snapshot?activityId={activity.ActivityId}");
|
||||
activity.ActivationUri = new Uri($"ms-calculator:snapshots/{activity.ActivityId}");
|
||||
activity.ContentInfo = UserActivityContentInfo.FromJson(Model.SaveApplicationSnapshot().Stringify());
|
||||
|
||||
activity.IsRoamable = false;
|
||||
var resProvider = AppResourceProvider.GetInstance();
|
||||
activity.VisualElements.DisplayText =
|
||||
$"{resProvider.GetResourceString("AppName")} - {resProvider.GetResourceString(NavCategoryStates.GetNameResourceKey(Model.Mode))}";
|
||||
|
||||
await activity.SaveAsync();
|
||||
args.Request.SetUserActivity(activity);
|
||||
deferral.Complete();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue