|
37 | 37 | using ArchiSteamFarm.Localization; |
38 | 38 | using ArchiSteamFarm.Storage; |
39 | 39 | using ArchiSteamFarm.Web; |
| 40 | +using Login.DBus; |
| 41 | +using Tmds.DBus.Protocol; |
40 | 42 |
|
41 | 43 | namespace ArchiSteamFarm.Core; |
42 | 44 |
|
@@ -69,13 +71,18 @@ internal static string Version { |
69 | 71 | } |
70 | 72 | } |
71 | 73 |
|
| 74 | + private static SafeHandle? InhibitLock; |
72 | 75 | private static Mutex? SingleInstance; |
73 | 76 |
|
74 | | - internal static void CoreInit(bool minimized, bool systemRequired) { |
| 77 | + internal static async Task CoreInit(bool minimized, bool systemRequired) { |
75 | 78 | if (minimized) { |
76 | 79 | MinimizeConsoleWindow(); |
77 | 80 | } |
78 | 81 |
|
| 82 | + if (OperatingSystem.IsLinux()) { |
| 83 | + await LinuxKeepSystemActive().ConfigureAwait(false); |
| 84 | + } |
| 85 | + |
79 | 86 | if (OperatingSystem.IsWindows()) { |
80 | 87 | if (systemRequired) { |
81 | 88 | WindowsKeepSystemActive(); |
@@ -181,6 +188,12 @@ internal static void UnregisterProcess() { |
181 | 188 | // Instead, we'll dispose the mutex which should automatically release it by the CLR |
182 | 189 | SingleInstance.Dispose(); |
183 | 190 | SingleInstance = null; |
| 191 | + |
| 192 | + // Release the inhibit lock as well, if needed |
| 193 | + if (InhibitLock != null) { |
| 194 | + InhibitLock.Dispose(); |
| 195 | + InhibitLock = null; |
| 196 | + } |
184 | 197 | } |
185 | 198 |
|
186 | 199 | internal static bool VerifyEnvironment() { |
@@ -316,6 +329,31 @@ private static void WindowsDisableQuickEditMode() { |
316 | 329 | } |
317 | 330 | } |
318 | 331 |
|
| 332 | + [SupportedOSPlatform("Linux")] |
| 333 | + private static async Task LinuxKeepSystemActive() { |
| 334 | + if (!OperatingSystem.IsLinux()) { |
| 335 | + throw new PlatformNotSupportedException(); |
| 336 | + } |
| 337 | + |
| 338 | + string? systemAddress = Address.System; |
| 339 | + |
| 340 | + if (string.IsNullOrEmpty(systemAddress)) { |
| 341 | + ASF.ArchiLogger.LogGenericError(Strings.FormatWarningFailedWithError(nameof(systemAddress))); |
| 342 | + |
| 343 | + return; |
| 344 | + } |
| 345 | + |
| 346 | + using Connection connection = new(systemAddress); |
| 347 | + |
| 348 | + await connection.ConnectAsync().ConfigureAwait(false); |
| 349 | + |
| 350 | + LoginService loginService = new(connection, "org.freedesktop.login1"); |
| 351 | + |
| 352 | + Manager manager = loginService.CreateManager("/org/freedesktop/login1"); |
| 353 | + |
| 354 | + InhibitLock = await manager.InhibitAsync("idle", SharedInfo.PublicIdentifier, "--system-required", "block"); |
| 355 | + } |
| 356 | + |
319 | 357 | [SupportedOSPlatform("Windows")] |
320 | 358 | private static void WindowsKeepSystemActive() { |
321 | 359 | if (!OperatingSystem.IsWindows()) { |
|
0 commit comments