feat: linux support
This commit is contained in:
parent
04ebe3f606
commit
d996ca0efb
3 changed files with 80 additions and 1 deletions
55
SlidePresenter/Linux.cs
Normal file
55
SlidePresenter/Linux.cs
Normal file
|
@ -0,0 +1,55 @@
|
|||
#if OS_LINUX
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace ControllerSlidePresenter;
|
||||
|
||||
public static class Linux {
|
||||
public static bool CanRun() {
|
||||
if (getuid() != 0) {
|
||||
Console.WriteLine("On Linux you need tu run as 'sudo'");
|
||||
return false;
|
||||
}
|
||||
if (!IsXdoToolInstalled())
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static bool IsXdoToolInstalled() {
|
||||
string result = RunShellCommand("which xdotool");
|
||||
if (!string.IsNullOrEmpty(result))
|
||||
return true;
|
||||
|
||||
Console.WriteLine("xdotool is not installed.");
|
||||
return false;
|
||||
}
|
||||
|
||||
private static string RunShellCommand(string command) {
|
||||
try {
|
||||
ProcessStartInfo procStartInfo = new("bash", "-c \"" + command + "\"") {
|
||||
RedirectStandardOutput = true,
|
||||
UseShellExecute = false,
|
||||
CreateNoWindow = true,
|
||||
};
|
||||
|
||||
using Process process = new();
|
||||
process.StartInfo = procStartInfo;
|
||||
process.Start();
|
||||
|
||||
string result = process.StandardOutput.ReadToEnd();
|
||||
process.WaitForExit();
|
||||
|
||||
return result.Trim();
|
||||
}
|
||||
catch (Exception ex) {
|
||||
Console.WriteLine("Error: " + ex.Message);
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[DllImport("libc")]
|
||||
private static extern uint getuid();
|
||||
}
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue