linux - check locations for bash and wmctrl rather than assuming location
This commit is contained in:
@@ -16,6 +16,9 @@ namespace EveOPreview.Services.Implementation
|
||||
|
||||
#region Private fields
|
||||
private readonly bool _enableWineCompatabilityMode;
|
||||
private string _bashLocation;
|
||||
private string _wmctrlLocation;
|
||||
private const string EXCEPTION_DUMP_FILE_NAME = "EVE-O-Preview.log";
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -23,6 +26,8 @@ namespace EveOPreview.Services.Implementation
|
||||
{
|
||||
#if LINUX
|
||||
this._enableWineCompatabilityMode = configuration.EnableWineCompatibilityMode;
|
||||
this._bashLocation = FindLinuxBinLocation("bash");
|
||||
this._wmctrlLocation = FindLinuxBinLocation("wmctrl");
|
||||
#endif
|
||||
// Composition is always enabled for Windows 8+
|
||||
this.IsCompositionEnabled =
|
||||
@@ -31,6 +36,39 @@ namespace EveOPreview.Services.Implementation
|
||||
|| DwmNativeMethods.DwmIsCompositionEnabled(); // In case of Win 7 an API call is requiredWin 7
|
||||
_animationParam.cbSize = (System.UInt32)Marshal.SizeOf(typeof(ANIMATIONINFO));
|
||||
}
|
||||
#if LINUX
|
||||
private string FindLinuxBinLocation(string command)
|
||||
{
|
||||
// Check common paths for bash
|
||||
string[] paths = { "/run/host/usr/bin", "/bin", "/usr/bin" };
|
||||
foreach (var path in paths)
|
||||
{
|
||||
string locationToCheck = $"{path}/{command}";
|
||||
if (System.IO.File.Exists(locationToCheck))
|
||||
{
|
||||
string binLocation = System.IO.Path.GetDirectoryName(locationToCheck);
|
||||
string binLocationUnixStyle = binLocation.Replace("\\", "/");
|
||||
|
||||
return binLocationUnixStyle;
|
||||
}
|
||||
}
|
||||
|
||||
WriteToLog($"[{DateTime.Now}] Error: {command} not found in expected locations.");
|
||||
return null;
|
||||
}
|
||||
#endif
|
||||
|
||||
private void WriteToLog(string message)
|
||||
{
|
||||
try
|
||||
{
|
||||
System.IO.File.AppendAllText(EXCEPTION_DUMP_FILE_NAME, message + Environment.NewLine);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Failed to write to log file: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
private int? _currentAnimationSetting = null;
|
||||
private ANIMATIONINFO _animationParam = new ANIMATIONINFO();
|
||||
@@ -95,17 +133,37 @@ namespace EveOPreview.Services.Implementation
|
||||
return;
|
||||
}
|
||||
|
||||
string? cmd = null;
|
||||
string cmd = "";
|
||||
try
|
||||
{
|
||||
// If we are in a flatpak, then use flatpak-spawn to run wmctrl outside the sandbox
|
||||
if (Environment.GetEnvironmentVariable("container") == "flatpak")
|
||||
{
|
||||
cmd = "-c \"flatpak-spawn --host wmctrl -a \"\"" + windowName + "\"\"\"";
|
||||
cmd = $"-c \"flatpak-spawn --host {this._wmctrlLocation}/wmctrl -a \"\"" + windowName + "\"\"\"";
|
||||
}
|
||||
else
|
||||
{
|
||||
cmd = "-c \"wmctrl -a \"\"" + windowName + "\"\"\"";
|
||||
cmd = $"-c \"{this._wmctrlLocation}/wmctrl -a \"\"" + windowName + "\"\"\"";
|
||||
}
|
||||
|
||||
// Configure and start the process
|
||||
var processStartInfo = new System.Diagnostics.ProcessStartInfo
|
||||
{
|
||||
FileName = $"{this._bashLocation}/bash",
|
||||
Arguments = cmd,
|
||||
UseShellExecute = false,
|
||||
CreateNoWindow = false
|
||||
};
|
||||
|
||||
using (var process = System.Diagnostics.Process.Start(processStartInfo))
|
||||
{
|
||||
process.WaitForExit();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
WriteToLog($"[{DateTime.Now}] executing wmctrl - Exception: {ex.Message}");
|
||||
}
|
||||
System.Diagnostics.Process.Start("bash", cmd);
|
||||
}
|
||||
|
||||
public void ActivateWindow(IntPtr handle, string windowName)
|
||||
|
Reference in New Issue
Block a user