mirror of
https://github.com/ayufan/steam-deck-tools.git
synced 2026-03-28 15:35:02 +01:00
94 lines
2.8 KiB
C#
94 lines
2.8 KiB
C#
using Microsoft.Gaming.XboxGameBar;
|
|
using System;
|
|
using Windows.ApplicationModel;
|
|
using Windows.ApplicationModel.Activation;
|
|
using Windows.UI.Xaml;
|
|
using Windows.UI.Xaml.Controls;
|
|
using Windows.UI.Xaml.Navigation;
|
|
|
|
namespace SteamDeckToolsGameBarWidget
|
|
{
|
|
sealed partial class App : Application
|
|
{
|
|
private XboxGameBarWidget widget = null;
|
|
|
|
public App()
|
|
{
|
|
InitializeComponent();
|
|
Suspending += OnSuspending;
|
|
}
|
|
|
|
protected override void OnActivated(IActivatedEventArgs args)
|
|
{
|
|
XboxGameBarWidgetActivatedEventArgs widgetArgs = null;
|
|
|
|
if (args.Kind == ActivationKind.Protocol)
|
|
{
|
|
var protocolArgs = args as IProtocolActivatedEventArgs;
|
|
if (protocolArgs != null && protocolArgs.Uri.Scheme.Equals("ms-gamebarwidget", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
widgetArgs = args as XboxGameBarWidgetActivatedEventArgs;
|
|
}
|
|
}
|
|
|
|
if (widgetArgs == null)
|
|
return;
|
|
|
|
if (widgetArgs.IsLaunchActivation)
|
|
{
|
|
var rootFrame = new Frame();
|
|
rootFrame.NavigationFailed += OnNavigationFailed;
|
|
Window.Current.Content = rootFrame;
|
|
|
|
widget = new XboxGameBarWidget(
|
|
widgetArgs,
|
|
Window.Current.CoreWindow,
|
|
rootFrame
|
|
);
|
|
|
|
rootFrame.Navigate(typeof(WidgetPage));
|
|
Window.Current.Closed += WidgetWindow_Closed;
|
|
Window.Current.Activate();
|
|
}
|
|
}
|
|
|
|
protected override void OnLaunched(LaunchActivatedEventArgs e)
|
|
{
|
|
var rootFrame = Window.Current.Content as Frame;
|
|
|
|
if (rootFrame == null)
|
|
{
|
|
rootFrame = new Frame();
|
|
rootFrame.NavigationFailed += OnNavigationFailed;
|
|
Window.Current.Content = rootFrame;
|
|
}
|
|
|
|
if (!e.PrelaunchActivated)
|
|
{
|
|
if (rootFrame.Content == null)
|
|
rootFrame.Navigate(typeof(MainPage), e.Arguments);
|
|
|
|
Window.Current.Activate();
|
|
}
|
|
}
|
|
|
|
private void WidgetWindow_Closed(object sender, Windows.UI.Core.CoreWindowEventArgs e)
|
|
{
|
|
widget = null;
|
|
Window.Current.Closed -= WidgetWindow_Closed;
|
|
}
|
|
|
|
private void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
|
|
{
|
|
throw new Exception("Failed to load page " + e.SourcePageType.FullName);
|
|
}
|
|
|
|
private void OnSuspending(object sender, SuspendingEventArgs e)
|
|
{
|
|
var deferral = e.SuspendingOperation.GetDeferral();
|
|
widget = null;
|
|
deferral.Complete();
|
|
}
|
|
}
|
|
}
|