Browse Source

Fixed discord rp not showing after first PixiEditor startup

CPKreuz 4 years ago
parent
commit
ec372f531c

+ 7 - 2
PixiEditor/ViewModels/SubViewModels/Main/DiscordViewModel.cs

@@ -5,7 +5,7 @@ using PixiEditor.Models.UserPreferences;
 
 namespace PixiEditor.ViewModels.SubViewModels.Main
 {
-    public class DiscordViewModel : SubViewModel<ViewModelMain>
+    public class DiscordViewModel : SubViewModel<ViewModelMain>, IDisposable
     {
         private DiscordRpcClient client;
         private string clientId;
@@ -86,7 +86,6 @@ namespace PixiEditor.ViewModels.SubViewModels.Main
             IPreferences.Current.AddCallback(nameof(ShowDocumentName), x => ShowDocumentName = (bool)x);
             IPreferences.Current.AddCallback(nameof(ShowDocumentSize), x => ShowDocumentSize = (bool)x);
             IPreferences.Current.AddCallback(nameof(ShowLayerCount), x => ShowLayerCount = (bool)x);
-
             AppDomain.CurrentDomain.ProcessExit += (_, _) => Enabled = false;
         }
 
@@ -142,6 +141,12 @@ namespace PixiEditor.ViewModels.SubViewModels.Main
             client.SetPresence(richPresence);
         }
 
+        public void Dispose()
+        {
+            Enabled = false;
+            GC.SuppressFinalize(this);
+        }
+
         private static RichPresence NewDefaultRP()
         {
             return new RichPresence

+ 5 - 0
PixiEditor/Views/MainWindow.xaml.cs

@@ -37,6 +37,11 @@ namespace PixiEditor
             viewModel.CloseAction = Close;
         }
 
+        protected override void OnClosing(CancelEventArgs e)
+        {
+            viewModel.DiscordViewModel.Dispose();
+        }
+
         private void CommandBinding_CanExecute(object sender, CanExecuteRoutedEventArgs e)
         {
             e.CanExecute = true;