From c33f8c1c4347264c2ea1db9b2acda546a346ddb9 Mon Sep 17 00:00:00 2001 From: flabbet Date: Wed, 12 Feb 2025 13:32:23 +0000 Subject: [PATCH] Process related implementations --- src/PixiEditor.Linux/LinuxOperatingSystem.cs | 17 ++++-- src/PixiEditor.Linux/LinuxProcessUtility.cs | 56 ++++++++++++++++++++ src/PixiEditor/ViewModels/ViewModelMain.cs | 1 + src/PixiEditor/Views/MainWindow.axaml.cs | 9 +++- 4 files changed, 76 insertions(+), 7 deletions(-) create mode 100644 src/PixiEditor.Linux/LinuxProcessUtility.cs diff --git a/src/PixiEditor.Linux/LinuxOperatingSystem.cs b/src/PixiEditor.Linux/LinuxOperatingSystem.cs index 212fa7d8e..3ff029c36 100644 --- a/src/PixiEditor.Linux/LinuxOperatingSystem.cs +++ b/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 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 diff --git a/src/PixiEditor.Linux/LinuxProcessUtility.cs b/src/PixiEditor.Linux/LinuxProcessUtility.cs new file mode 100644 index 000000000..f6e6c3429 --- /dev/null +++ b/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; + } +} diff --git a/src/PixiEditor/ViewModels/ViewModelMain.cs b/src/PixiEditor/ViewModels/ViewModelMain.cs index 95070f471..276faff86 100644 --- a/src/PixiEditor/ViewModels/ViewModelMain.cs +++ b/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; diff --git a/src/PixiEditor/Views/MainWindow.axaml.cs b/src/PixiEditor/Views/MainWindow.axaml.cs index 06a6f0361..74859261c 100644 --- a/src/PixiEditor/Views/MainWindow.axaml.cs +++ b/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(true); if (System.OperatingSystem.IsLinux()) { - MainTitleBar titleBar = this.FindDescendantOfType(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) {