Browse Source

Made self-updating work

flabbet 2 months ago
parent
commit
8bc5aa47dd

+ 1 - 3
src/PixiEditor.Linux/LinuxProcessUtility.cs

@@ -9,9 +9,7 @@ public class LinuxProcessUtility : IProcessUtility
 {
 {
     public Process RunAsAdmin(string path, string args)
     public Process RunAsAdmin(string path, string args)
     {
     {
-        // polkit 
-        
-        return Execute("pkexec", $"env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY {path} {args}");
+        throw new NotSupportedException("Running as admin is not supported on Linux.");
     }
     }
 
 
     public bool IsRunningAsAdministrator()
     public bool IsRunningAsAdministrator()

+ 1 - 1
src/PixiEditor.OperatingSystem/IProcessUtility.cs

@@ -7,6 +7,6 @@ public interface IProcessUtility
     public Process RunAsAdmin(string path, string? args);
     public Process RunAsAdmin(string path, string? args);
     public bool IsRunningAsAdministrator();
     public bool IsRunningAsAdministrator();
     public Process ShellExecute(string toExecute);
     public Process ShellExecute(string toExecute);
-    public Process ShellExecute(string toExecute, string args);
+    public Process ShellExecute(string toExecute, string? args);
     public Process Execute(string path, string args);
     public Process Execute(string path, string args);
 }
 }

+ 34 - 3
src/PixiEditor/ViewModels/SubViewModels/UpdateViewModel.cs

@@ -125,7 +125,6 @@ internal class UpdateViewModel : SubViewModel<ViewModelMain>
     public UpdateViewModel(ViewModelMain owner)
     public UpdateViewModel(ViewModelMain owner)
         : base(owner)
         : base(owner)
     {
     {
-        IOperatingSystem.Current.ProcessUtility.RunAsAdmin("whoami", null);
         if (IOperatingSystem.Current.IsLinux)
         if (IOperatingSystem.Current.IsLinux)
         {
         {
             if (File.Exists("no-updates"))
             if (File.Exists("no-updates"))
@@ -290,7 +289,26 @@ internal class UpdateViewModel : SubViewModel<ViewModelMain>
     {
     {
         try
         try
         {
         {
-            ProcessHelper.RunAsAdmin(updaterPath, startAfterUpdate ? "--startOnSuccess" : null);
+            if (IOperatingSystem.Current.IsLinux)
+            {
+                bool hasWritePermissions = !InstallDirReadOnly();
+                if (hasWritePermissions)
+                {
+                    IOperatingSystem.Current.ProcessUtility.ShellExecute(updaterPath, startAfterUpdate ? "--startOnSuccess" : null);
+                }
+                else
+                {
+                    NoticeDialog.Show(
+                        "COULD_NOT_UPDATE_WITHOUT_ADMIN",
+                        "INSUFFICIENT_PERMISSIONS");
+                    return;
+                }
+            }
+            else
+            {
+                ProcessHelper.RunAsAdmin(updaterPath, startAfterUpdate ? "--startOnSuccess" : null);
+            }
+
             Shutdown();
             Shutdown();
         }
         }
         catch (Win32Exception)
         catch (Win32Exception)
@@ -327,7 +345,20 @@ internal class UpdateViewModel : SubViewModel<ViewModelMain>
     {
     {
         try
         try
         {
         {
-            IOperatingSystem.Current.ProcessUtility.RunAsAdmin(updateExeFile, null);
+            
+            if (IOperatingSystem.Current.IsLinux)
+            {
+                bool hasWritePermissions = !InstallDirReadOnly();
+                if (hasWritePermissions)
+                {
+                    IOperatingSystem.Current.ProcessUtility.ShellExecute(updateExeFile, null);
+                }
+            }
+            else
+            {
+                IOperatingSystem.Current.ProcessUtility.RunAsAdmin(updateExeFile, null);
+            }
+
             Shutdown();
             Shutdown();
         }
         }
         catch (Win32Exception)
         catch (Win32Exception)