diff --git a/src/Calculator/App.xaml.cs b/src/Calculator/App.xaml.cs
index 8ca14222..78849c76 100644
--- a/src/Calculator/App.xaml.cs
+++ b/src/Calculator/App.xaml.cs
@@ -75,13 +75,26 @@ namespace CalculatorApp
{
if (args.Kind == ActivationKind.Protocol)
{
- // We currently don't pass the uri as an argument,
- // and handle any protocol launch as a normal app launch.
- OnAppLaunch(args, null, false);
+ if (args.IsSnapshotProtocol())
+ {
+ var protoArgs = (IProtocolActivatedEventArgs)args;
+ OnAppLaunch(args,
+ new SnapshotLaunchArguments
+ {
+ ActivityId = protoArgs.Uri.GetActivityId(),
+ LaunchUri = protoArgs.Uri
+ },
+ false);
+ }
+ else
+ {
+ // handle any unknown protocol launch as a normal app launch.
+ OnAppLaunch(args, null, false);
+ }
}
}
- private void OnAppLaunch(IActivatedEventArgs args, string argument, bool isPreLaunch)
+ private void OnAppLaunch(IActivatedEventArgs args, object arguments, bool isPreLaunch)
{
// Uncomment the following lines to display frame-rate and per-frame CPU usage info.
//#if DEBUG
@@ -132,7 +145,7 @@ namespace CalculatorApp
// When the navigation stack isn't restored navigate to the first page,
// configuring the new page by passing required information as a navigation
// parameter
- if (rootFrame.Content == null && !rootFrame.Navigate(typeof(MainPage), argument))
+ if (rootFrame.Content == null && !rootFrame.Navigate(typeof(MainPage), arguments))
{
// We couldn't navigate to the main page, kill the app so we have a good
// stack to debug
diff --git a/src/Calculator/Calculator.csproj b/src/Calculator/Calculator.csproj
index b92f52fd..236428aa 100644
--- a/src/Calculator/Calculator.csproj
+++ b/src/Calculator/Calculator.csproj
@@ -144,6 +144,7 @@
+
diff --git a/src/Calculator/Common/LaunchArguments.cs b/src/Calculator/Common/LaunchArguments.cs
new file mode 100644
index 00000000..80d4cc26
--- /dev/null
+++ b/src/Calculator/Common/LaunchArguments.cs
@@ -0,0 +1,56 @@
+using System;
+using System.Linq;
+
+using Windows.ApplicationModel.Activation;
+using Windows.ApplicationModel.UserActivities;
+
+namespace CalculatorApp
+{
+ internal class SnapshotLaunchArguments
+ {
+ public string ActivityId { get; set; }
+ public Uri LaunchUri { get; set; }
+ }
+
+ internal static class LaunchExtensions
+ {
+ public static bool IsSnapshotProtocol(this IActivatedEventArgs args) =>
+ args is IProtocolActivatedEventArgs protoArgs &&
+ protoArgs.Uri != null &&
+ protoArgs.Uri.AbsolutePath == "/snapshot" &&
+ !string.IsNullOrEmpty(protoArgs.Uri.Query);
+
+ ///
+ /// GetActivityId() requires the parameter `launchUri` to be a well-formed
+ /// snapshot URI.
+ ///
+ ///
+ ///
+ 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;
+ }
+
+ public static bool VerifyIncomingActivity(this SnapshotLaunchArguments launchArgs, UserActivity activity)
+ {
+ if (string.IsNullOrEmpty(activity.ActivityId) ||
+ activity.ActivationUri == null ||
+ activity.ActivationUri.AbsolutePath != "/snapshot" ||
+ string.IsNullOrEmpty(activity.ActivationUri.Query) ||
+ activity.ContentInfo == null)
+ {
+ return false;
+ }
+ return activity.ActivityId == GetActivityId(launchArgs.LaunchUri);
+ }
+ }
+}
diff --git a/src/Calculator/Views/MainPage.xaml.cs b/src/Calculator/Views/MainPage.xaml.cs
index bd4a56c4..c774e7e4 100644
--- a/src/Calculator/Views/MainPage.xaml.cs
+++ b/src/Calculator/Views/MainPage.xaml.cs
@@ -1,13 +1,9 @@
-using CalculatorApp.Common;
-using CalculatorApp.Converters;
-using CalculatorApp.ViewModel;
-using CalculatorApp.ViewModel.Common;
-using CalculatorApp.ViewModel.Common.Automation;
-
using System;
using System.Collections.Generic;
using System.ComponentModel;
+using Windows.ApplicationModel.UserActivities;
+using Windows.Data.Json;
using Windows.Foundation;
using Windows.Graphics.Display;
using Windows.Storage;
@@ -15,19 +11,19 @@ using Windows.UI.Core;
using Windows.UI.ViewManagement;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Automation;
-using Windows.UI.Xaml.Controls;
-using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Navigation;
+using Microsoft.UI.Xaml.Controls;
-using MUXC = Microsoft.UI.Xaml.Controls;
+using CalculatorApp.Common;
+using CalculatorApp.Converters;
+using CalculatorApp.ViewModel;
+using CalculatorApp.ViewModel.Common;
+using CalculatorApp.ViewModel.Common.Automation;
namespace CalculatorApp
{
- ///
- /// An empty page that can be used on its own or navigated to within a Frame.
- ///
- public sealed partial class MainPage : Page
+ public sealed partial class MainPage : Windows.UI.Xaml.Controls.Page
{
public static readonly DependencyProperty NavViewCategoriesSourceProperty =
DependencyProperty.Register(nameof(NavViewCategoriesSource), typeof(List