/// <inheritdoc />
 /// <summary>
 ///     Called to ask the package if the shell can be closed. By default this method returns canClose as true and S_OK.
 /// </summary>
 /// <param name="canClose">Returns true if the shell can be closed, otherwise false.</param>
 /// <returns>S_OK(0) if the method succeeded, otherwise an error code.</returns>
 protected override int QueryClose(out bool canClose)
 {
     DiscordRPC.Shutdown();
     return(base.QueryClose(out canClose));
 }
#pragma warning disable VSTHRD100 // Avoid async void methods
        /// <summary>
        ///     When switching between windows
        /// </summary>
        /// <param name="windowActivated"></param>
        /// <param name="lastWindow"></param>
        private async void OnWindowSwitch(Window windowActivated, Window lastWindow)
#pragma warning restore VSTHRD100 // Avoid async void methods
        {
            try {
                await JoinableTaskFactory.SwitchToMainThreadAsync(DisposalToken);

                // Get Extension
                string ext = "";

                if (windowActivated.Document != null)
                {
                    ext = Path.GetExtension(windowActivated.Document.FullName);
                }

                // Update the RichPresence Images based on config.
                DiscordController.Presence = Settings.IsLanguageImageLarge
                    ? new DiscordRPC.RichPresence {
                    largeImageKey  = _languages.ContainsKey(ext) ? _languages[ext] : "visualstudio",
                    largeImageText = _languages.ContainsKey(ext) ? _languages[ext] : "",
                    smallImageKey  = "visualstudio",
                    smallImageText = "Visual Studio 2019"
                }
                    : new DiscordRPC.RichPresence {
                    largeImageKey  = "visualstudio",
                    largeImageText = "Visual Studio 2019",
                    smallImageKey  = _languages.ContainsKey(ext) ? _languages[ext] : "visualstudio",
                    smallImageText = _languages.ContainsKey(ext) ? _languages[ext] : ""
                };

                // Add things to the presence based on config.
                if (Settings.IsFileNameShown && windowActivated.Document != null)
                {
                    DiscordController.Presence.details = Path.GetFileName(GetExactPathName(windowActivated.Document.FullName));
                }

                if (Settings.IsSolutionNameShown && _dte.Solution != null)
                {
                    DiscordController.Presence.state = "Developing " + Path.GetFileNameWithoutExtension(_dte.Solution.FileName);
                }

                // Initialize timestamp
                if (Settings.IsTimestampShown && !InitializedTimestamp)
                {
                    DiscordController.Presence.startTimestamp = (int)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds;
                    InitialTimestamp     = DiscordController.Presence.startTimestamp;
                    InitializedTimestamp = true;
                }

                // Reset it
                if (Settings.IsTimestampResetEnabled && InitializedTimestamp && Settings.IsTimestampShown)
                {
                    DiscordController.Presence.startTimestamp = (int)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds;
                }
                // Set it equal to the initial timestamp (To not reset)
                else if (Settings.IsTimestampShown && !Settings.IsTimestampResetEnabled)
                {
                    DiscordController.Presence.startTimestamp = InitialTimestamp;
                }

                if (Settings.IsPresenceEnabled)
                {
                    DiscordController.Initialize();
                    DiscordRPC.UpdatePresence(ref DiscordController.Presence);
                }
                else
                {
                    DiscordRPC.Shutdown();
                }
            }
            catch (Exception) {
                // ignored
            }
        }