linux: use managed system dialog instead of DBus file picker (it has an extra black background panel on Wayland).

This commit is contained in:
leo 2024-03-19 15:53:46 +08:00
parent 1c14f5ea88
commit 0b8740dc3a

View file

@ -1,105 +1,108 @@
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Runtime.Versioning; using System.Runtime.Versioning;
using Avalonia; using Avalonia;
using Avalonia.Dialogs;
namespace SourceGit.Native
{ namespace SourceGit.Native
[SupportedOSPlatform("linux")] {
internal class Linux : OS.IBackend [SupportedOSPlatform("linux")]
{ internal class Linux : OS.IBackend
public void SetupApp(AppBuilder builder) {
{ public void SetupApp(AppBuilder builder)
#if USE_FONT_INTER {
builder.WithInterFont(); #if USE_FONT_INTER
#endif builder.WithInterFont();
} #endif
// Free-desktop file picker has an extra black background panel.
public string FindGitExecutable() builder.UseManagedSystemDialogs();
{ }
if (File.Exists("/usr/bin/git")) return "/usr/bin/git";
return string.Empty; public string FindGitExecutable()
} {
if (File.Exists("/usr/bin/git")) return "/usr/bin/git";
public string FindVSCode() return string.Empty;
{ }
if (File.Exists("/usr/share/code/code")) return "/usr/share/code/code";
return string.Empty; public string FindVSCode()
} {
if (File.Exists("/usr/share/code/code")) return "/usr/share/code/code";
public void OpenBrowser(string url) return string.Empty;
{ }
if (!File.Exists("/usr/bin/xdg-open"))
{ public void OpenBrowser(string url)
App.RaiseException("", $"You should install xdg-open first!"); {
return; if (!File.Exists("/usr/bin/xdg-open"))
} {
App.RaiseException("", $"You should install xdg-open first!");
Process.Start("xdg-open", $"\"{url}\""); return;
} }
public void OpenInFileManager(string path, bool select) Process.Start("xdg-open", $"\"{url}\"");
{ }
if (!File.Exists("/usr/bin/xdg-open"))
{ public void OpenInFileManager(string path, bool select)
App.RaiseException("", $"You should install xdg-open first!"); {
return; if (!File.Exists("/usr/bin/xdg-open"))
} {
App.RaiseException("", $"You should install xdg-open first!");
if (Directory.Exists(path)) return;
{ }
Process.Start("xdg-open", $"\"{path}\"");
} if (Directory.Exists(path))
else {
{ Process.Start("xdg-open", $"\"{path}\"");
var dir = Path.GetDirectoryName(path); }
if (Directory.Exists(dir)) else
{ {
Process.Start("xdg-open", $"\"{dir}\""); var dir = Path.GetDirectoryName(path);
} if (Directory.Exists(dir))
} {
} Process.Start("xdg-open", $"\"{dir}\"");
}
public void OpenTerminal(string workdir) }
{ }
var dir = string.IsNullOrEmpty(workdir) ? "~" : workdir;
if (File.Exists("/usr/bin/gnome-terminal")) public void OpenTerminal(string workdir)
{ {
Process.Start("/usr/bin/gnome-terminal", $"--working-directory=\"{dir}\""); var dir = string.IsNullOrEmpty(workdir) ? "~" : workdir;
} if (File.Exists("/usr/bin/gnome-terminal"))
else if (File.Exists("/usr/bin/konsole")) {
{ Process.Start("/usr/bin/gnome-terminal", $"--working-directory=\"{dir}\"");
Process.Start("/usr/bin/konsole", $"--workdir \"{dir}\""); }
} else if (File.Exists("/usr/bin/konsole"))
else if (File.Exists("/usr/bin/xfce4-terminal")) {
{ Process.Start("/usr/bin/konsole", $"--workdir \"{dir}\"");
Process.Start("/usr/bin/xfce4-terminal", $"--working-directory=\"{dir}\""); }
} else if (File.Exists("/usr/bin/xfce4-terminal"))
else {
{ Process.Start("/usr/bin/xfce4-terminal", $"--working-directory=\"{dir}\"");
App.RaiseException("", $"Only supports gnome-terminal/konsole/xfce4-terminal!"); }
return; else
} {
} App.RaiseException("", $"Only supports gnome-terminal/konsole/xfce4-terminal!");
return;
public void OpenWithDefaultEditor(string file) }
{ }
if (!File.Exists("/usr/bin/xdg-open"))
{ public void OpenWithDefaultEditor(string file)
App.RaiseException("", $"You should install xdg-open first!"); {
return; if (!File.Exists("/usr/bin/xdg-open"))
} {
App.RaiseException("", $"You should install xdg-open first!");
var proc = Process.Start("xdg-open", $"\"{file}\""); return;
proc.WaitForExit(); }
if (proc.ExitCode != 0) var proc = Process.Start("xdg-open", $"\"{file}\"");
{ proc.WaitForExit();
App.RaiseException("", $"Failed to open \"{file}\"");
} if (proc.ExitCode != 0)
{
proc.Close(); App.RaiseException("", $"Failed to open \"{file}\"");
} }
}
proc.Close();
}
}
} }