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;
|
||||||
using System.Linq;
|
|
||||||
|
|
||||||
using Windows.ApplicationModel.Activation;
|
using Windows.ApplicationModel.Activation;
|
||||||
using Windows.ApplicationModel.UserActivities;
|
using Windows.ApplicationModel.UserActivities;
|
||||||
|
@ -17,35 +16,29 @@ namespace CalculatorApp
|
||||||
public static bool IsSnapshotProtocol(this IActivatedEventArgs args) =>
|
public static bool IsSnapshotProtocol(this IActivatedEventArgs args) =>
|
||||||
args is IProtocolActivatedEventArgs protoArgs &&
|
args is IProtocolActivatedEventArgs protoArgs &&
|
||||||
protoArgs.Uri != null &&
|
protoArgs.Uri != null &&
|
||||||
protoArgs.Uri.AbsolutePath == "/snapshot" &&
|
protoArgs.Uri.Segments != null &&
|
||||||
!string.IsNullOrEmpty(protoArgs.Uri.Query);
|
protoArgs.Uri.Segments.Length == 2 &&
|
||||||
|
protoArgs.Uri.Segments[0] == "snapshots/";
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// GetActivityId() requires the parameter `launchUri` to be a well-formed
|
/// GetActivityId() requires the parameter `launchUri` to be a well-formed
|
||||||
/// snapshot URI.
|
/// snapshot URI.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="launchUri"></param>
|
/// <param name="launchUri">the Uri to launch with a snapshot context.</param>
|
||||||
/// <returns></returns>
|
/// <returns>Activity ID</returns>
|
||||||
public static string GetActivityId(this Uri launchUri)
|
public static string GetActivityId(this Uri launchUri)
|
||||||
{
|
{
|
||||||
const string ActivityIdKey = "activityId=";
|
return launchUri.Segments[1].Trim();
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool VerifyIncomingActivity(this SnapshotLaunchArguments launchArgs, UserActivity activity)
|
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 == null ||
|
||||||
activity.ActivationUri.AbsolutePath != "/snapshot" ||
|
activity.ActivationUri.Segments == null ||
|
||||||
string.IsNullOrEmpty(activity.ActivationUri.Query))
|
activity.ActivationUri.Segments.Length != 2 ||
|
||||||
|
activity.ActivationUri.Segments[0] != "snapshots/")
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,13 +66,12 @@ namespace CalculatorApp
|
||||||
}
|
}
|
||||||
var channel = UserActivityChannel.GetDefault();
|
var channel = UserActivityChannel.GetDefault();
|
||||||
var activity = await channel.GetOrCreateUserActivityAsync($"{Guid.NewGuid()}");
|
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.ContentInfo = UserActivityContentInfo.FromJson(Model.SaveApplicationSnapshot().Stringify());
|
||||||
|
activity.IsRoamable = false;
|
||||||
var resProvider = AppResourceProvider.GetInstance();
|
var resProvider = AppResourceProvider.GetInstance();
|
||||||
activity.VisualElements.DisplayText =
|
activity.VisualElements.DisplayText =
|
||||||
$"{resProvider.GetResourceString("AppName")} - {resProvider.GetResourceString(NavCategoryStates.GetNameResourceKey(Model.Mode))}";
|
$"{resProvider.GetResourceString("AppName")} - {resProvider.GetResourceString(NavCategoryStates.GetNameResourceKey(Model.Mode))}";
|
||||||
|
|
||||||
await activity.SaveAsync();
|
await activity.SaveAsync();
|
||||||
args.Request.SetUserActivity(activity);
|
args.Request.SetUserActivity(activity);
|
||||||
deferral.Complete();
|
deferral.Complete();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue