|
1 | 1 | using System; |
| 2 | +using System.Diagnostics; |
2 | 3 | using System.Runtime.Versioning; |
3 | 4 | using Microsoft.Extensions.DependencyInjection; |
4 | 5 | using YMouseButtonControl.Core.Services.BackgroundTasks; |
@@ -51,8 +52,33 @@ private static void RegisterLinuxServices(IServiceCollection services) |
51 | 52 | services |
52 | 53 | .AddScoped<IStartupInstallerService, Linux.Services.StartupInstallerService>() |
53 | 54 | .AddScoped<IProcessMonitorService, Linux.Services.ProcessMonitorService>() |
54 | | - .AddScoped<ICurrentWindowService, Linux.Services.CurrentWindowService>() |
55 | 55 | .AddScoped<IBackgroundTasksRunner, Linux.Services.BackgroundTasksRunner>(); |
| 56 | + if (Environment.GetEnvironmentVariable("XDG_SESSION_TYPE") == "x11") |
| 57 | + { |
| 58 | + var startInfo = new ProcessStartInfo |
| 59 | + { |
| 60 | + FileName = "/bin/bash", |
| 61 | + Arguments = "-c \"xdotool\"", |
| 62 | + RedirectStandardOutput = true, |
| 63 | + RedirectStandardError = true, |
| 64 | + }; |
| 65 | + using var proc = new Process(); |
| 66 | + proc.StartInfo = startInfo; |
| 67 | + proc.Start(); |
| 68 | + proc.WaitForExit(); |
| 69 | + if (proc.ExitCode == 1) |
| 70 | + { |
| 71 | + services.AddScoped<ICurrentWindowService, Linux.Services.CurrentWindowServiceX11>(); |
| 72 | + } |
| 73 | + else |
| 74 | + { |
| 75 | + services.AddScoped<ICurrentWindowService, Linux.Services.CurrentWindowService>(); |
| 76 | + } |
| 77 | + } |
| 78 | + else |
| 79 | + { |
| 80 | + services.AddScoped<ICurrentWindowService, Linux.Services.CurrentWindowService>(); |
| 81 | + } |
56 | 82 | } |
57 | 83 |
|
58 | 84 | [SupportedOSPlatform("windows5.1.2600")] |
|
0 commit comments