浏览代码

Restart function fixes

Ruben 11 月之前
父节点
当前提交
fc22406a58
共有 1 个文件被更改,包括 27 次插入1 次删除
  1. 27 1
      src/PicView.Avalonia/UI/FunctionsHelper.cs

+ 27 - 1
src/PicView.Avalonia/UI/FunctionsHelper.cs

@@ -140,6 +140,7 @@ public static class FunctionsHelper
             "GalleryClick" => GalleryClick,
             "GalleryClick" => GalleryClick,
             "Slideshow" => Slideshow,
             "Slideshow" => Slideshow,
             "ColorPicker" => ColorPicker,
             "ColorPicker" => ColorPicker,
+            "Restart" => Restart,
 
 
             _ => null
             _ => null
         });
         });
@@ -1046,7 +1047,32 @@ public static class FunctionsHelper
     
     
     public static async Task Restart()
     public static async Task Restart()
     {
     {
-        ProcessHelper.RestartApp(Environment.GetCommandLineArgs()?.ToString());
+        var openFile = string.Empty;
+        var getFromArgs = false;
+        if (Vm?.FileInfo is not null)
+        {
+            if (Vm.FileInfo.Exists)
+            {
+                openFile = Vm.FileInfo.FullName;
+            }
+            else
+            {
+                getFromArgs = true;
+            }
+        }
+        else
+        {
+            getFromArgs = true;
+        }
+        if (getFromArgs)
+        {
+            var args = Environment.GetCommandLineArgs();
+            if (args is not null && args.Length > 0)
+            {
+                openFile = args[1];
+            }
+        }
+        ProcessHelper.RestartApp(openFile);
 
 
         if (Application.Current?.ApplicationLifetime is not IClassicDesktopStyleApplicationLifetime desktop)
         if (Application.Current?.ApplicationLifetime is not IClassicDesktopStyleApplicationLifetime desktop)
         {
         {