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
|
#region Private fields
|
||||||
private readonly bool _enableWineCompatabilityMode;
|
private readonly bool _enableWineCompatabilityMode;
|
||||||
|
private string _bashLocation;
|
||||||
|
private string _wmctrlLocation;
|
||||||
|
private const string EXCEPTION_DUMP_FILE_NAME = "EVE-O-Preview.log";
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
@@ -23,6 +26,8 @@ namespace EveOPreview.Services.Implementation
|
|||||||
{
|
{
|
||||||
#if LINUX
|
#if LINUX
|
||||||
this._enableWineCompatabilityMode = configuration.EnableWineCompatibilityMode;
|
this._enableWineCompatabilityMode = configuration.EnableWineCompatibilityMode;
|
||||||
|
this._bashLocation = FindLinuxBinLocation("bash");
|
||||||
|
this._wmctrlLocation = FindLinuxBinLocation("wmctrl");
|
||||||
#endif
|
#endif
|
||||||
// Composition is always enabled for Windows 8+
|
// Composition is always enabled for Windows 8+
|
||||||
this.IsCompositionEnabled =
|
this.IsCompositionEnabled =
|
||||||
@@ -31,6 +36,39 @@ namespace EveOPreview.Services.Implementation
|
|||||||
|| DwmNativeMethods.DwmIsCompositionEnabled(); // In case of Win 7 an API call is requiredWin 7
|
|| DwmNativeMethods.DwmIsCompositionEnabled(); // In case of Win 7 an API call is requiredWin 7
|
||||||
_animationParam.cbSize = (System.UInt32)Marshal.SizeOf(typeof(ANIMATIONINFO));
|
_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 int? _currentAnimationSetting = null;
|
||||||
private ANIMATIONINFO _animationParam = new ANIMATIONINFO();
|
private ANIMATIONINFO _animationParam = new ANIMATIONINFO();
|
||||||
@@ -95,17 +133,37 @@ namespace EveOPreview.Services.Implementation
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
string? cmd = null;
|
string cmd = "";
|
||||||
// If we are in a flatpak, then use flatpak-spawn to run wmctrl outside the sandbox
|
try
|
||||||
if (Environment.GetEnvironmentVariable("container") == "flatpak")
|
{
|
||||||
{
|
// If we are in a flatpak, then use flatpak-spawn to run wmctrl outside the sandbox
|
||||||
cmd = "-c \"flatpak-spawn --host wmctrl -a \"\"" + windowName + "\"\"\"";
|
if (Environment.GetEnvironmentVariable("container") == "flatpak")
|
||||||
}
|
{
|
||||||
else
|
cmd = $"-c \"flatpak-spawn --host {this._wmctrlLocation}/wmctrl -a \"\"" + windowName + "\"\"\"";
|
||||||
{
|
}
|
||||||
cmd = "-c \"wmctrl -a \"\"" + windowName + "\"\"\"";
|
else
|
||||||
}
|
{
|
||||||
System.Diagnostics.Process.Start("bash", cmd);
|
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}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ActivateWindow(IntPtr handle, string windowName)
|
public void ActivateWindow(IntPtr handle, string windowName)
|
||||||
|
Reference in New Issue
Block a user