/// <summary> /// Initialization of the package; this method is called right after the package is sited, so this is the place /// where you can put all the initialization code that rely on services provided by VisualStudio. /// </summary> protected override void Initialize() { // Try to deserialize the config file, it should throw an error if it doesn't exist. // in that case, we'll want to create a new instance and save it. Config = Configuration.Deserialize(); _dte = (DTE)GetService(typeof(SDTE)); _dteEvents = _dte.Events; _dteEvents.WindowEvents.WindowActivated += OnWindowSwitch; if (Config.PresenceEnabled) { DiscordController.Initialize(); DiscordRPC.UpdatePresence(ref DiscordController.presence); } base.Initialize(); TogglePresence.Initialize(this); ToggleFileNameDisplay.Initialize(this); ToggleProjectNameDisplay.Initialize(this); ToggleTimestampDisplay.Initialize(this); ToggleTimestampReset.Initialize(this); TogglePresence.Instance.SetPresence(DiscordController.presence); }
/// <summary> /// Initialization of the package; this method is called right after the package is sited, so this is the place /// where you can put all the initialization code that rely on services provided by VisualStudio. /// </summary> protected override void Initialize() { // Try to deserialize the config file, it should throw an error if it doesn't exist. // in that case, we'll want to create a new instance and save it. Config = Configuration.Deserialize(); _dte = (DTE)GetService(typeof(SDTE)); _dteEvents = _dte.Events; _dteEvents.WindowEvents.WindowActivated += OnWindowSwitch; DiscordController.Initialize(); DiscordController.presence = new DiscordRPC.RichPresence() { details = "Idle", state = "Looking for a project", largeImageKey = "visualstudio", largeImageText = "Visual Studio", smallImageKey = "smallvs", startTimestamp = (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds }; DiscordRPC.UpdatePresence(ref DiscordController.presence); base.Initialize(); ToggleFileNameDisplay.Initialize(this); ToggleProjectNameDisplay.Initialize(this); ToggleTimestampDisplay.Initialize(this); }
/// <inheritdoc /> /// <summary> /// Initialization of the package; this method is called right after the package is sited, so this is the place /// where you can put all the initialization code that rely on services provided by VisualStudio. /// </summary> protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress) { try { // Switches to the UI thread in order to consume some services used in command initialization await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); // Query service asynchronously from the UI thread _dte = await GetServiceAsync(typeof(SDTE)) as DTE; Assumes.Present(_dte); _dteEvents = _dte.Events; _dteEvents.WindowEvents.WindowActivated += OnWindowSwitch; if (Settings.IsPresenceEnabled) { DiscordController.Initialize(); DiscordRPC.UpdatePresence(ref DiscordController.Presence); } PresenceCommand.Initialize(this); await base.InitializeAsync(cancellationToken, progress); } catch (Exception) { //ignored } }
/// <summary> /// Initialization of the package; this method is called right after the package is sited, so this is the place /// where you can put all the initialization code that rely on services provided by VisualStudio. /// </summary> protected override void Initialize() { // Try to deserialize the config file, it should throw an error if it doesn't exist. // in that case, we'll want to create a new instance and save it. _dte = (DTE)GetService(typeof(SDTE)); _dteEvents = _dte.Events; _dteEvents.WindowEvents.WindowActivated += OnWindowSwitch; if (Settings.IsPresenceEnabled) { DiscordController.Initialize(); DiscordRPC.UpdatePresence(ref DiscordController.presence); } base.Initialize(); PresenceCommand.Initialize(this); }
#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 } }