/// <summary>
        /// The Game Bar Widget activations happen as a Protocol Activation
        /// with its URI scheme being "ms-gamebarwidget".
        ///
        /// If it is the desired kind and equals to the string mentioned above we'll cast
        /// the received arguments to XboxGameBarWidgetActivatedEventArgs type, initialize the communication
        /// between Xbox Game Bar and the Widget, then navigate to the desired page on our current window.
        /// </summary>
        /// <param name="args"></param>
        protected override void OnActivated(IActivatedEventArgs args)
        {
            XboxGameBarWidgetActivatedEventArgs widgetArgs = null;

            if (args.Kind == ActivationKind.Protocol)
            {
                var    protocolArgs   = args as IProtocolActivatedEventArgs;
                string protocolScheme = protocolArgs.Uri.Scheme;

                if (protocolScheme.Equals("ms-gamebarwidget"))
                {
                    widgetArgs = args as XboxGameBarWidgetActivatedEventArgs;
                }
            }

            if (widgetArgs != null)
            {
                if (widgetArgs.IsLaunchActivation)
                {
                    var rootFrame = new Frame();
                    rootFrame.NavigationFailed += OnNavigationFailed;
                    Window.Current.Content      = rootFrame;

                    ytgbw = new XboxGameBarWidget(widgetArgs, Window.Current.CoreWindow, rootFrame);
                    rootFrame.Navigate(typeof(MainPage));

                    Window.Current.Closed += WidgetWindow_Closed;
                    Window.Current.Activate();
                }
            }
        }
Exemple #2
0
        private void OnXboxGameBarActivated(XboxGameBarWidgetActivatedEventArgs xbox)
        {
            Analytics.TrackEvent("Unicord_LaunchForGameBar");

            if (xbox.IsLaunchActivation)
            {
                var name  = xbox.Uri.LocalPath;
                var frame = new Frame();
                frame.NavigationFailed += OnNavigationFailed;
                Window.Current.Content  = frame;

                Logger.Log(xbox.Uri.LocalPath);

                if (name == "unicord-friendslist")
                {
                    _friendsListWidget     = new XboxGameBarWidget(xbox, Window.Current.CoreWindow, frame);
                    Window.Current.Closed += OnFrendsListWidgetClosed;

                    frame.Navigate(typeof(GameBarMainPage), new GameBarPageParameters(_friendsListWidget, typeof(GameBarFriendsPage), xbox.Uri));
                }

                if (name == "unicord-channel")
                {
                    _chatListWidget        = new XboxGameBarWidget(xbox, Window.Current.CoreWindow, frame);
                    Window.Current.Closed += OnChatListWidgetClosed;

                    frame.Navigate(typeof(GameBarMainPage), new GameBarPageParameters(_chatListWidget, typeof(GameBarChannelListPage), xbox.Uri));
                }
            }
        }
        protected override void OnActivated(IActivatedEventArgs args)
        {
            XboxGameBarWidgetActivatedEventArgs widgetArgs = null;

            if (args.Kind == ActivationKind.Protocol)
            {
                var    protocolArgs = args as IProtocolActivatedEventArgs;
                string scheme       = protocolArgs.Uri.Scheme;
                if (scheme.Equals("ms-gamebarwidget"))
                {
                    widgetArgs = args as XboxGameBarWidgetActivatedEventArgs;
                }
            }
            if (widgetArgs != null)
            {
                if (widgetArgs.IsLaunchActivation)
                {
                    var rootFrame = new Frame();
                    rootFrame.NavigationFailed += OnNavigationFailed;
                    Window.Current.Content      = rootFrame;

                    if (widgetArgs.AppExtensionId == "Crosshair")
                    {
                        crosshair = new XboxGameBarWidget(
                            widgetArgs,
                            Window.Current.CoreWindow,
                            rootFrame);
                        rootFrame.Navigate(typeof(Crosshair), crosshair);

                        Window.Current.Closed += CrosshairWindow_Closed;
                    }
                    else if (widgetArgs.AppExtensionId == "Settings")
                    {
                        settings = new XboxGameBarWidget(
                            widgetArgs,
                            Window.Current.CoreWindow,
                            rootFrame);
                        rootFrame.Navigate(typeof(Settings));

                        Window.Current.Closed += SettingsWindow_Closed;
                    }
                    else
                    {
                        return;
                    }

                    Window.Current.Activate();
                }
            }
        }
        protected override void OnActivated(IActivatedEventArgs args)
        {
            XboxGameBarWidgetActivatedEventArgs widgetArgs = null;

            if (args.Kind == ActivationKind.Protocol)
            {
                var    protocolArgs = args as IProtocolActivatedEventArgs;
                string scheme       = protocolArgs.Uri.Scheme;
                if (scheme.Equals("ms-gamebarwidget"))
                {
                    widgetArgs = args as XboxGameBarWidgetActivatedEventArgs;
                }
            }
            if (widgetArgs != null)
            {
                if (widgetArgs.IsLaunchActivation)
                {
                    var rootFrame = new Frame();
                    rootFrame.NavigationFailed += OnNavigationFailed;
                    Window.Current.Content      = rootFrame;

                    // Create Game Bar widget object which bootstraps the connection with Game Bar
                    crosshair = new XboxGameBarWidget(
                        widgetArgs,
                        Window.Current.CoreWindow,
                        rootFrame);
                    rootFrame.Navigate(typeof(Crosshair));

                    Window.Current.Closed += CrosshairWindow_Closed;

                    Window.Current.Activate();
                }
                else
                {
                    // TODO perform whatever behavior you need based on the URI payload.
                }
            }
        }
Exemple #5
0
        protected override void OnActivated(IActivatedEventArgs args)
        {
            XboxGameBarWidgetActivatedEventArgs widgetArgs = null;

            if (args.Kind == ActivationKind.Protocol)
            {
                var    protocolArgs = args as IProtocolActivatedEventArgs;
                string scheme       = protocolArgs.Uri.Scheme;
                if (scheme.Equals("ms-gamebarwidget"))
                {
                    widgetArgs = args as XboxGameBarWidgetActivatedEventArgs;
                }
            }

            if (widgetArgs != null)
            {
                if (widgetArgs.IsLaunchActivation)
                {
                    var rootFrame = new Frame();
                    rootFrame.NavigationFailed += OnNavigationFailed;
                    Window.Current.Content      = rootFrame;

                    // Create gamebar widget object here
                    widget = new XboxGameBarWidget(widgetArgs, Window.Current.CoreWindow, rootFrame);
                    rootFrame.Navigate(typeof(MainPage), widget);

                    Window.Current.Closed += MainPage_Closed;

                    Window.Current.Activate();
                }
                else
                {
                    // perform behaviour based on URI payload
                }
            }
        }
        public static void GameBarActivated(Frame rootFrame, XboxGameBarWidgetActivatedEventArgs xboxGameBarWidgetActivatedEventArgs)
        {
            LoggingService.LogInfo($"[XboxGameBarWidgetActivated] AppExtensionId: {xboxGameBarWidgetActivatedEventArgs.AppExtensionId}");

            if (xboxGameBarWidgetActivatedEventArgs != null)
            {
                if (xboxGameBarWidgetActivatedEventArgs.IsLaunchActivation)
                {
                    var xboxGameBarWidget = new XboxGameBarWidget(
                        xboxGameBarWidgetActivatedEventArgs,
                        Window.Current.CoreWindow,
                        rootFrame);

                    if (xboxGameBarWidgetActivatedEventArgs.AppExtensionId == "Notepads")
                    {
                        rootFrame.Navigate(typeof(NotepadsMainPage), xboxGameBarWidget);
                    }
                    else if (xboxGameBarWidgetActivatedEventArgs.AppExtensionId == "NotepadsSettings")
                    {
                        rootFrame.Navigate(typeof(SettingsPage), xboxGameBarWidget);
                    }
                }
            }
        }
Exemple #7
0
        protected override void OnActivated(IActivatedEventArgs args)
        {
            XboxGameBarWidgetActivatedEventArgs widgetArgs = null;

            if (args.Kind == ActivationKind.Protocol)
            {
                var    protocolArgs = args as IProtocolActivatedEventArgs;
                string scheme       = protocolArgs.Uri.Scheme;
                if (scheme.Equals("ms-gamebarwidget"))
                {
                    widgetArgs = args as XboxGameBarWidgetActivatedEventArgs;
                }
            }
            if (widgetArgs != null)
            {
                //
                // Activation Notes:
                //
                //    If IsLaunchActivation is true, this is Game Bar launching a new instance
                // of our widget. This means we have a NEW CoreWindow with corresponding UI
                // dispatcher, and we MUST create and hold onto a new XboxGameBarWidget.
                //
                // Otherwise this is a subsequent activation coming from Game Bar. We MUST
                // continue to hold the XboxGameBarWidget created during initial activation
                // and ignore this repeat activation, or just observe the URI command here and act
                // accordingly.  It is ok to perform a navigate on the root frame to switch
                // views/pages if needed.  Game Bar lets us control the URI for sending widget to
                // widget commands or receiving a command from another non-widget process.
                //
                // Important Cleanup Notes:
                //    When our widget is closed--by Game Bar or us calling XboxGameBarWidget.Close()-,
                // the CoreWindow will get a closed event.  We can register for Window.Closed
                // event to know when our particular widget has shutdown, and cleanup accordingly.
                //
                // NOTE: If a widget's CoreWindow is the LAST CoreWindow being closed for the process
                // then we won't get the Window.Closed event.  However, we will get the OnSuspending
                // call and can use that for cleanup.
                //
                if (widgetArgs.IsLaunchActivation)
                {
                    var rootFrame = new Frame();
                    rootFrame.NavigationFailed += OnNavigationFailed;
                    Window.Current.Content      = rootFrame;

                    // Create Game Bar widget object which bootstraps the connection with Game Bar
                    widget1 = new XboxGameBarWidget(
                        widgetArgs,
                        Window.Current.CoreWindow,
                        rootFrame);
                    rootFrame.Navigate(typeof(Widget1), widget1);

                    Window.Current.Closed += Widget1Window_Closed;

                    Window.Current.Activate();
                }
                else
                {
                    // You can perform whatever behavior you need based on the URI payload.
                }
            }
        }
        protected override void OnActivated(IActivatedEventArgs args)
        {
            XboxGameBarWidgetActivatedEventArgs widgetArgs = null;

            if (args.Kind == ActivationKind.Protocol)
            {
                var    protocolArgs = args as IProtocolActivatedEventArgs;
                string scheme       = protocolArgs.Uri.Scheme;
                if (scheme.Equals("ms-gamebarwidget"))
                {
                    widgetArgs = args as XboxGameBarWidgetActivatedEventArgs;
                }
            }
            if (widgetArgs != null)
            {
                //
                // Activation Notes:
                //
                //    If IsLaunchActivation is true, this is Game Bar launching a new instance
                // of our widget. This means we have a NEW CoreWindow with corresponding UI
                // dispatcher, and we MUST create and hold onto a new XboxGameBarWidget.
                //
                // Otherwise this is a subsequent activation coming from Game Bar. We MUST
                // continue to hold the XboxGameBarWidget created during initial activation
                // and ignore this repeat activation, or just observe the URI command here and act
                // accordingly.  It is ok to perform a navigate on the root frame to switch
                // views/pages if needed.  Game Bar lets us control the URI for sending widget to
                // widget commands or receiving a command from another non-widget process.
                //
                // Important Cleanup Notes:
                //    When our widget is closed--by Game Bar or us calling XboxGameBarWidget.Close()-,
                // the CoreWindow will get a closed event.  We can register for Window.Closed
                // event to know when our partucular widget has shutdown, and cleanup accordingly.
                //
                // NOTE: If a widget's CoreWindow is the LAST CoreWindow being closed for the process
                // then we won't get the Window.Closed event.  However, we will get the OnSuspending
                // call and can use that for cleanup.
                //
                if (widgetArgs.IsLaunchActivation)
                {
                    var rootFrame = new Frame();
                    rootFrame.NavigationFailed += OnNavigationFailed;
                    Window.Current.Content      = rootFrame;

                    // Navigate to correct view
                    if (widgetArgs.AppExtensionId == "Widget1")
                    {
                        widget1 = new XboxGameBarWidget(
                            widgetArgs,
                            Window.Current.CoreWindow,
                            rootFrame);
                        rootFrame.Navigate(typeof(Widget1), widget1);

                        Window.Current.Closed += Widget1Window_Closed;
                    }
                    else if (widgetArgs.AppExtensionId == "Widget1Settings")
                    {
                        widget1Settings = new XboxGameBarWidget(
                            widgetArgs,
                            Window.Current.CoreWindow,
                            rootFrame);
                        rootFrame.Navigate(typeof(Widget1Settings));

                        Window.Current.Closed += Widget1SettingsWindow_Closed;
                    }
                    else if (widgetArgs.AppExtensionId == "Widget2")
                    {
                        widget2 = new XboxGameBarWidget(
                            widgetArgs,
                            Window.Current.CoreWindow,
                            rootFrame);
                        rootFrame.Navigate(typeof(Widget2), widgetArgs.Uri);

                        Window.Current.Closed += Widget2Window_Closed;
                    }
                    else
                    {
                        // Unknown - Game Bar should never send you an unknown App Extension Id
                        return;
                    }

                    Window.Current.Activate();
                }
                else if (widgetArgs.AppExtensionId == "Widget2")
                {
                    // You can perform whatever behavior you need based on the URI payload. In our case
                    // we're simply renavigating to Widget2 and displaying the absolute URI.  You
                    // define your URI schema (subpath + query + fragment).
                    Frame rootFrame = null;
                    var   content   = Window.Current.Content;
                    if (content != null)
                    {
                        rootFrame = content as Frame;
                    }
                    rootFrame.NavigationFailed += OnNavigationFailed;
                    rootFrame.Navigate(typeof(Widget2), widgetArgs.Uri);
                }
            }
        }