Bladeren bron

Update startup logic #198

Ruben 6 maanden geleden
bovenliggende
commit
5dc81e76c0
2 gewijzigde bestanden met toevoegingen van 22 en 22 verwijderingen
  1. 8 9
      src/PicView.Avalonia.MacOS/App.axaml.cs
  2. 14 13
      src/PicView.Avalonia/StartUp/StartUpHelper.cs

+ 8 - 9
src/PicView.Avalonia.MacOS/App.axaml.cs

@@ -1,5 +1,4 @@
 using System.Diagnostics;
-using System.Runtime;
 using Avalonia;
 using Avalonia.Controls;
 using Avalonia.Controls.ApplicationLifetimes;
@@ -21,6 +20,9 @@ using PicView.Core.MacOS.FileAssociation;
 using PicView.Core.MacOS.Wallpaper;
 using PicView.Core.ProcessHandling;
 using PicView.Core.ViewModels;
+#if DEBUG
+using System.Runtime;
+#endif
 
 namespace PicView.Avalonia.MacOS;
 
@@ -38,8 +40,10 @@ public class App : Application, IPlatformSpecificService
 
     public override void Initialize()
     {
+#if DEBUG
         ProfileOptimization.SetProfileRoot(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Config/"));
         ProfileOptimization.StartProfile("ProfileOptimization");
+#endif
         base.OnFrameworkInitializationCompleted();
     }
 
@@ -57,21 +61,16 @@ public class App : Application, IPlatformSpecificService
             var settingsExists = await LoadSettingsAsync().ConfigureAwait(false);
         
             TranslationManager.Init();
-        
+            _vm = new MainViewModel(this);
+            
             await Dispatcher.UIThread.InvokeAsync(() =>
             {
                 ThemeManager.DetermineTheme(Current, settingsExists);
             
                 _mainWindow = new MacMainWindow();
                 desktop.MainWindow = _mainWindow;
-            },DispatcherPriority.Send);
-        
-            _vm = new MainViewModel(this);
-        
-            await Dispatcher.UIThread.InvokeAsync(() =>
-            {
-                
                 _mainWindow.DataContext = _vm;
+                
                 StartUpHelper.Start(_vm, settingsExists, desktop, _mainWindow);
             },DispatcherPriority.Send);
         }

+ 14 - 13
src/PicView.Avalonia/StartUp/StartUpHelper.cs

@@ -63,22 +63,13 @@ public static class StartUpHelper
                 }
             }
         }
-        Task.Run(() => LanguageUpdater.UpdateLanguageAsync(vm.Translation, vm.PicViewer, settingsExists));
-        if (settingsExists)
-        {
-            Task.Run(() => KeybindingManager.LoadKeybindings(vm.PlatformService));
-        }
-        else
-        {
-            Task.Run(() => KeybindingManager.SetDefaultKeybindings(vm.PlatformService));
-        }
         
         InitializeSettings(vm);
         
         if (Settings.WindowProperties.AutoFit)
         {
             ScreenHelper.UpdateScreenSize(window);
-            HandleAutoFit(vm);
+            HandleAutoFit(vm, window);
         }
         else
         {
@@ -89,6 +80,16 @@ public static class StartUpHelper
         
         HandleStartUpMenuOrImage(vm, args);
         ResourceLimits.LimitMemory(new Percentage(90));
+        
+        Task.Run(() => LanguageUpdater.UpdateLanguageAsync(vm.Translation, vm.PicViewer, settingsExists));
+        if (settingsExists)
+        {
+            Task.Run(() => KeybindingManager.LoadKeybindings(vm.PlatformService));
+        }
+        else
+        {
+            Task.Run(() => KeybindingManager.SetDefaultKeybindings(vm.PlatformService));
+        }
 
         HandleThemeUpdates(vm);
         
@@ -106,7 +107,6 @@ public static class StartUpHelper
             Dispatcher.UIThread.InvokeAsync(() =>
             {
                 WindowFunctions.Fullscreen(vm, desktop);
-                
             }, DispatcherPriority.Normal).Wait();
         }
         
@@ -199,15 +199,15 @@ public static class StartUpHelper
     {
         vm.CanResize = true;
         vm.IsAutoFit = false;
-        WindowFunctions.InitializeWindowSizeAndPosition(window);
         if (Settings.UIProperties.ShowInterface)
         {
             vm.IsTopToolbarShown = true;
             vm.IsBottomToolbarShown = Settings.UIProperties.ShowBottomNavBar;
         }
+        WindowFunctions.InitializeWindowSizeAndPosition(window);
     }
 
-    private static void HandleAutoFit(MainViewModel vm)
+    private static void HandleAutoFit(MainViewModel vm, Window window)
     {
         vm.SizeToContent = SizeToContent.WidthAndHeight;
         vm.CanResize = false;
@@ -217,6 +217,7 @@ public static class StartUpHelper
             vm.IsTopToolbarShown = true;
             vm.IsBottomToolbarShown = Settings.UIProperties.ShowBottomNavBar;
         }
+        window.WindowStartupLocation = WindowStartupLocation.CenterScreen;
     }
 
     private static void HandleMultipleInstances(string[] args)