From b2ed89a3e664062ef60b9568fb03f0d6a4813d82 Mon Sep 17 00:00:00 2001 From: Infina <49457443+InfinaMii@users.noreply.github.com> Date: Fri, 15 May 2026 19:24:12 +0100 Subject: [PATCH 1/2] Update Clipboard to work across platforms - Make Run method in Shell.cs public - Modify Clipboard.SetText and Clipboard.GetText to reuse Shell.Run rather than duplicating Process code - Remove Clipboard.Copy (unused) and move its platform checks to SetText - Update Linux copy functions to use Bash + correct commands based on session type - Add macOS and Linux functionality to Clipboard.Paste --- src/UIFramework/Util/Clipboard.cs | 56 +++++++++++++------------------ src/UIFramework/Util/Shell.cs | 2 +- 2 files changed, 25 insertions(+), 33 deletions(-) diff --git a/src/UIFramework/Util/Clipboard.cs b/src/UIFramework/Util/Clipboard.cs index 0c2721f..351ae7c 100644 --- a/src/UIFramework/Util/Clipboard.cs +++ b/src/UIFramework/Util/Clipboard.cs @@ -6,53 +6,45 @@ namespace MapStudio.UI { public static class Clipboard { - public static void Copy(string val) + public static void SetText(string text) { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { - $"echo {val} | clip".Bat(); + Shell.Run("powershell", $"-command \"Set-Clipboard -Value \\\"{text}\\\"\""); } if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { - $"echo {val} | clip".Bat(); + if ("echo $XDG_SESSION_TYPE".Bash() == "wayland") + $"echo {text} | wl-copy".Bash(); + else + $"echo {text} | xclip -selection clipboard".Bash(); } if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { - $"echo \"{val}\" | pbcopy".Bash(); + $"echo \"{text}\" | pbcopy".Bash(); } } - - public static void SetText(string text) - { - var powershell = new Process - { - StartInfo = new ProcessStartInfo - { - FileName = "powershell", - Arguments = $"-command \"Set-Clipboard -Value \\\"{text}\\\"\"" - } - }; - powershell.Start(); - powershell.WaitForExit(); - } - + public static string GetText() { - var powershell = new Process + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { - StartInfo = new ProcessStartInfo - { - RedirectStandardOutput = true, - FileName = "powershell", - Arguments = "-command \"Get-Clipboard\"" - } - }; + var text = Shell.Run("powershell", "-command \"Get-Clipboard\""); + return text.TrimEnd(); + } + if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + if ("echo $XDG_SESSION_TYPE".Bash() == "wayland") + return "wl-paste".Bash(); + else + return "xclip -o -selection clipboard".Bash(); + } + if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + { + return "pbpaste".Bash(); + } - powershell.Start(); - string text = powershell.StandardOutput.ReadToEnd(); - powershell.StandardOutput.Close(); - powershell.WaitForExit(); - return text.TrimEnd(); + return null; } } } diff --git a/src/UIFramework/Util/Shell.cs b/src/UIFramework/Util/Shell.cs index bef0574..4280b56 100644 --- a/src/UIFramework/Util/Shell.cs +++ b/src/UIFramework/Util/Shell.cs @@ -20,7 +20,7 @@ public static string Bat(this string cmd) return result; } - private static string Run(string filename, string arguments) + public static string Run(string filename, string arguments) { var process = new Process() { From 93f39c24f084829c68c327b147f251bad688e160 Mon Sep 17 00:00:00 2001 From: Infina <49457443+InfinaMii@users.noreply.github.com> Date: Mon, 24 Aug 2026 12:34:30 +0100 Subject: [PATCH 2/2] Fixes for Linux platform - Use StartsWith rather than == for Wayland detection in case output contains newline - Add quotes around text to ensure it gets fed to wl-copy and xclip correctly --- src/UIFramework/Util/Clipboard.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/UIFramework/Util/Clipboard.cs b/src/UIFramework/Util/Clipboard.cs index 351ae7c..245672f 100644 --- a/src/UIFramework/Util/Clipboard.cs +++ b/src/UIFramework/Util/Clipboard.cs @@ -14,10 +14,11 @@ public static void SetText(string text) } if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { - if ("echo $XDG_SESSION_TYPE".Bash() == "wayland") - $"echo {text} | wl-copy".Bash(); + var script = "echo $XDG_SESSION_TYPE".Bash(); + if ("echo $XDG_SESSION_TYPE".Bash().StartsWith("wayland")) + $"echo \"{text}\" | wl-copy".Bash(); else - $"echo {text} | xclip -selection clipboard".Bash(); + $"echo \"{text}\" | xclip -selection clipboard".Bash(); } if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) {