diff --git a/src/UIFramework/Util/Clipboard.cs b/src/UIFramework/Util/Clipboard.cs index 0c2721f..245672f 100644 --- a/src/UIFramework/Util/Clipboard.cs +++ b/src/UIFramework/Util/Clipboard.cs @@ -6,53 +6,46 @@ 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(); + 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(); } 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() {