Ver Fonte

Process related implementations

flabbet há 5 meses atrás
pai
commit
c33f8c1c43

+ 12 - 5
src/PixiEditor.Linux/LinuxOperatingSystem.cs

@@ -11,18 +11,25 @@ public sealed class LinuxOperatingSystem : IOperatingSystem
     public string AnalyticsId => "Linux";
     public string AnalyticsName => LinuxOSInformation.FromReleaseFile().ToString();
     public IInputKeys InputKeys { get; } = new LinuxInputKeys();
-    public IProcessUtility ProcessUtility { get; }
+    public IProcessUtility ProcessUtility { get; } = new LinuxProcessUtility();
 
     public string ExecutableExtension { get; } = string.Empty;
 
     public void OpenUri(string uri)
     {
-        throw new NotImplementedException();
+        ProcessUtility.Execute($"xdg-open", uri);
     }
 
     public void OpenFolder(string path)
     {
-        throw new NotImplementedException();
+        try
+        {
+            ProcessUtility.Execute($"dbus-send", $"--session --dest=org.freedesktop.FileManager1 --type=method_call /org/freedesktop/FileManager1 org.freedesktop.FileManager1.ShowItems array:string:\"file://{path}\" string:\"\"");
+        }
+        catch (Exception e)
+        {
+            ProcessUtility.Execute($"xdg-open", Path.GetDirectoryName(path));
+        }
     }
 
     public bool HandleNewInstance(Dispatcher? dispatcher, Action<string, bool> openInExistingAction, IApplicationLifetime lifetime)
@@ -32,12 +39,12 @@ public sealed class LinuxOperatingSystem : IOperatingSystem
 
     public void HandleActivatedWithFile(FileActivatedEventArgs fileActivatedEventArgs)
     {
-        throw new NotImplementedException();
+        // TODO: Check if this is executed on Linux at all
     }
 
     public void HandleActivatedWithUri(ProtocolActivatedEventArgs openUriEventArgs)
     {
-        throw new NotImplementedException();
+        // TODO: Check if this is executed on Linux at all
     }
 
     class LinuxOSInformation

+ 56 - 0
src/PixiEditor.Linux/LinuxProcessUtility.cs

@@ -0,0 +1,56 @@
+using System.Diagnostics;
+using System.Net;
+using System.Security;
+using PixiEditor.OperatingSystem;
+
+namespace PixiEditor.Linux;
+
+public class LinuxProcessUtility : IProcessUtility
+{
+    public Process RunAsAdmin(string path)
+    {
+        throw new NotImplementedException("Running as admin is not supported on Linux");
+    }
+
+    public Process RunAsAdmin(string path, bool createWindow)
+    {
+        throw new NotImplementedException("Running as admin is not supported on Linux");
+    }
+
+    public bool IsRunningAsAdministrator()
+    {
+        return Environment.IsPrivilegedProcess;
+    }
+
+    public Process ShellExecute(string toExecute)
+    {
+        Process process = new Process();
+        process.StartInfo.FileName = toExecute;
+        process.StartInfo.UseShellExecute = true;
+        process.Start();
+        
+        return process;
+    }
+
+    public Process ShellExecute(string toExecute, string args)
+    {
+        Process process = new Process();
+        process.StartInfo.FileName = toExecute;
+        process.StartInfo.Arguments = args;
+        process.StartInfo.UseShellExecute = true;
+        process.Start();
+        
+        return process;
+    }
+
+    public Process Execute(string path, string args)
+    {
+        Process process = new Process();
+        process.StartInfo.FileName = path;
+        process.StartInfo.Arguments = args;
+        process.StartInfo.UseShellExecute = false;
+        process.Start();
+        
+        return process;
+    }
+}

+ 1 - 0
src/PixiEditor/ViewModels/ViewModelMain.cs

@@ -17,6 +17,7 @@ using PixiEditor.Models.Dialogs;
 using PixiEditor.Models.DocumentModels;
 using PixiEditor.Models.Files;
 using PixiEditor.Models.Handlers;
+using PixiEditor.OperatingSystem;
 using PixiEditor.ViewModels.Document;
 using PixiEditor.ViewModels.Menu;
 using PixiEditor.ViewModels.SubViewModels;

+ 7 - 2
src/PixiEditor/Views/MainWindow.axaml.cs

@@ -5,6 +5,7 @@ using Avalonia.Controls.ApplicationLifetimes;
 using Avalonia.Controls.Primitives;
 using Avalonia.Input;
 using Avalonia.Interactivity;
+using Avalonia.LogicalTree;
 using Avalonia.OpenGL;
 using Avalonia.Platform;
 using Avalonia.Rendering.Composition;
@@ -35,6 +36,8 @@ internal partial class MainWindow : Window
     private readonly IServiceProvider services;
     private static ExtensionLoader extLoader;
 
+    private MainTitleBar titleBar;
+
     public StartupPerformance StartupPerformance { get; } = new();
 
     public new ViewModels_ViewModelMain DataContext
@@ -134,9 +137,9 @@ internal partial class MainWindow : Window
     {
         base.OnLoaded(e);
         
+        titleBar = this.FindDescendantOfType<MainTitleBar>(true);
         if (System.OperatingSystem.IsLinux())
         {
-            MainTitleBar titleBar = this.FindDescendantOfType<MainTitleBar>(true);
             titleBar.PointerPressed += OnTitleBarPressed;
             
             PointerMoved += UpdateResizeCursor;
@@ -173,7 +176,9 @@ internal partial class MainWindow : Window
 
     private void OnTitleBarPressed(object? sender, PointerPressedEventArgs e)
     {
-        if (e.GetCurrentPoint(this).Properties.IsLeftButtonPressed)
+        bool withinTitleBar = e.GetPosition(this).Y <= titleBar.Bounds.Height;
+        bool sourceIsMenuItem = e.Source is Control ctrl && ctrl.GetLogicalParent() is MenuItem;
+        if (withinTitleBar && !sourceIsMenuItem && e.GetCurrentPoint(this).Properties.IsLeftButtonPressed)
         {
             if(e.ClickCount == 2)
             {