Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix protocol activation #1304

Merged
merged 13 commits into from
Nov 1, 2023
80 changes: 29 additions & 51 deletions WinUIGallery/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,18 @@
using Microsoft.UI.Xaml.Navigation;
using WinUIGallery.DesktopWap.DataModel;
using WASDK = Microsoft.WindowsAppSDK;

using Microsoft.Windows.AppLifecycle;
using System.IO;

namespace AppUIBasics
{
/// <summary>
/// Provides application-specific behavior to supplement the default Application class.
/// </summary>
sealed partial class App : Application
{
private static Window startupWindow;
private static Window startupWindow;

public static string WinAppSdkDetails
{
// TODO: restore patch number and version tag when WinAppSDK supports them both
Expand Down Expand Up @@ -78,11 +80,6 @@ public App()
this.Resuming += App_Resuming;
this.RequiresPointerMode = ApplicationRequiresPointerMode.WhenRequested;
#endif

if (ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 6))
{
this.FocusVisualKind = AnalyticsInfo.VersionInfo.DeviceFamily == "Xbox" ? FocusVisualKind.Reveal : FocusVisualKind.HighVisibility;
}
}

public void EnableSound(bool withSpatial = false)
Expand Down Expand Up @@ -170,46 +167,31 @@ private async void EnsureWindow(IActivatedEventArgs args = null)

targetPageArguments = ((Windows.ApplicationModel.Activation.LaunchActivatedEventArgs)args).Arguments;
}
else if (args.Kind == ActivationKind.Protocol)
{
Match match;

string targetId = string.Empty;

switch (((ProtocolActivatedEventArgs)args).Uri?.AbsoluteUri)
{
case string s when IsMatching(s, "(/*)category/(.*)"):
targetId = match.Groups[2]?.ToString();
if (targetId == "AllControls")
{
targetPageType = typeof(AllControlsPage);
}
else if (targetId == "HomePage")
{
targetPageType = typeof(HomePage);
}
else if (ControlInfoDataSource.Instance.Groups.Any(g => g.UniqueId == targetId))
{
targetPageType = typeof(SectionPage);
}
break;

case string s when IsMatching(s, "(/*)item/(.*)"):
targetId = match.Groups[2]?.ToString();
if (ControlInfoDataSource.Instance.Groups.Any(g => g.Items.Any(i => i.UniqueId == targetId)))
{
targetPageType = typeof(ItemPage);
}
break;
}
}
var eventargs = Microsoft.Windows.AppLifecycle.AppInstance.GetCurrent().GetActivatedEventArgs();
if (eventargs != null && eventargs.Kind is ExtendedActivationKind.Protocol && eventargs.Data is ProtocolActivatedEventArgs)
{
ProtocolActivatedEventArgs ProtocolArgs = eventargs.Data as ProtocolActivatedEventArgs;
var uri = ProtocolArgs.Uri.LocalPath.Replace("/", "");

targetPageArguments = targetId;
targetPageArguments = uri;
string targetId = string.Empty;

bool IsMatching(string parent, string expression)
{
match = Regex.Match(parent, expression);
return match.Success;
}
if (uri == "AllControls")
{
targetPageType = typeof(AllControlsPage);
}
else if (uri == "NewControls")
{
targetPageType = typeof(HomePage);
}
else if (ControlInfoDataSource.Instance.Groups.Any(g => g.UniqueId == uri))
{
targetPageType = typeof(SectionPage);
}
else if (ControlInfoDataSource.Instance.Groups.Any(g => g.Items.Any(i => i.UniqueId == uri)))
{
targetPageType = typeof(ItemPage);
}
}

Expand All @@ -220,13 +202,9 @@ bool IsMatching(string parent, string expression)
{
((Microsoft.UI.Xaml.Controls.NavigationViewItem)((NavigationRootPage)App.StartupWindow.Content).NavigationView.MenuItems[0]).IsSelected = true;
}
else if (targetPageType == typeof(ItemPage))
{
NavigationRootPage.GetForElement(this).EnsureNavigationSelection(targetPageArguments);
}

// Ensure the current window is active
StartupWindow.Activate();
StartupWindow.Activate();
}

public Frame GetRootFrame()
Expand Down
Binary file modified WinUIGallery/Assets/CopyLinkTeachingTip.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
55 changes: 27 additions & 28 deletions WinUIGallery/Navigation/NavigationRootPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -195,50 +195,49 @@
<NavigationViewItem
x:Name="DesignGuidanceItem"
AutomationProperties.AutomationId="Design_Guidance"
Content="Design Guidance"
Tag="Design_Guidance">
Content="Design guidance"
Tag="Design Guidance">
<NavigationViewItem.Icon>
<FontIcon Glyph="&#xEB3C;" />
</NavigationViewItem.Icon>
<NavigationViewItem.MenuItems>
<NavigationViewItem x:Name="TypographyItem" AutomationProperties.AutomationId="Typography" Content="Typography">
<NavigationViewItem x:Name="TypographyItem" AutomationProperties.AutomationId="Typography" Content="Typography" Tag="Typography">
<NavigationViewItem.Icon>
<FontIcon Glyph="&#xE8D2;" />
</NavigationViewItem.Icon>
</NavigationViewItem>
<NavigationViewItem x:Name="IconsItem" AutomationProperties.AutomationId="Icons" Content="Icons">
<NavigationViewItem x:Name="IconsItem" AutomationProperties.AutomationId="Icons" Content="Icons" Tag="Icons">
<NavigationViewItem.Icon>
<FontIcon Glyph="&#xED58;" />
</NavigationViewItem.Icon>
</NavigationViewItem>
<NavigationViewItem x:Name="ColorsItem" AutomationProperties.AutomationId="Colors" Content="Colors">
<NavigationViewItem x:Name="ColorsItem" AutomationProperties.AutomationId="Colors" Content="Colors" Tag="Colors">
<NavigationViewItem.Icon>
<FontIcon Glyph="&#xE790;" />
</NavigationViewItem.Icon>
</NavigationViewItem>
</NavigationViewItem.MenuItems>
</NavigationViewItem>

<NavigationViewItem x:Name="AccessibilityItem" AutomationProperties.AutomationId="AccessibilityItem" Content="Accessibility">
<NavigationViewItem.Icon>
<FontIcon Glyph="&#xE776;" />
</NavigationViewItem.Icon>
<NavigationViewItem.MenuItems>
<NavigationViewItem
x:Name="AccessibilityScreenReaderPage"
AutomationProperties.AutomationId="AccessibilityScreenReader"
Content="Screen reader support"
Tag="AccessibilityScreenReader" />
<NavigationViewItem
x:Name="AccessibilityKeyboardPage"
AutomationProperties.AutomationId="AccessibilityKeyboard"
Content="Keyboard support"
Tag="AccessibilityKeyboard" />
<NavigationViewItem
x:Name="AccessibilityContrastPage"
AutomationProperties.AutomationId="AccessibilityColorContrast"
Content="Color contrast"
Tag="AccessibilityColorContrast" />
<NavigationViewItem x:Name="AccessibilityItem" AutomationProperties.AutomationId="AccessibilityItem" Content="Accessibility" Tag="Accessibility">
<NavigationViewItem.Icon>
<FontIcon Glyph="&#xE776;" />
</NavigationViewItem.Icon>
<NavigationViewItem.MenuItems>
<NavigationViewItem
x:Name="AccessibilityScreenReaderPage"
AutomationProperties.AutomationId="AccessibilityScreenReader"
Content="Screen reader support"
Tag="AccessibilityScreenReader" />
<NavigationViewItem
x:Name="AccessibilityKeyboardPage"
AutomationProperties.AutomationId="AccessibilityKeyboard"
Content="Keyboard support"
Tag="AccessibilityKeyboard" />
<NavigationViewItem
x:Name="AccessibilityContrastPage"
AutomationProperties.AutomationId="AccessibilityColorContrast"
Content="Color contrast"
Tag="AccessibilityColorContrast" />
</NavigationViewItem.MenuItems>
</NavigationViewItem>
</NavigationViewItem.MenuItems>
</NavigationViewItem>

Expand Down