Skip to content

Commit d2b10c1

Browse files
committed
Initial POC
1 parent d4691ce commit d2b10c1

File tree

5 files changed

+1920
-2
lines changed

5 files changed

+1920
-2
lines changed

ArchiSteamFarm/ArchiSteamFarm.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
<PackageReference Include="SteamKit2" />
2525
<PackageReference Include="System.Composition" />
2626
<PackageReference Include="System.Security.Cryptography.ProtectedData" />
27+
<PackageReference Include="Tmds.DBus.Protocol" />
2728
</ItemGroup>
2829

2930
<ItemGroup>

ArchiSteamFarm/Core/OS.cs

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
using ArchiSteamFarm.Localization;
3838
using ArchiSteamFarm.Storage;
3939
using ArchiSteamFarm.Web;
40+
using Login.DBus;
41+
using Tmds.DBus.Protocol;
4042

4143
namespace ArchiSteamFarm.Core;
4244

@@ -69,13 +71,18 @@ internal static string Version {
6971
}
7072
}
7173

74+
private static SafeHandle? InhibitLock;
7275
private static Mutex? SingleInstance;
7376

74-
internal static void CoreInit(bool minimized, bool systemRequired) {
77+
internal static async Task CoreInit(bool minimized, bool systemRequired) {
7578
if (minimized) {
7679
MinimizeConsoleWindow();
7780
}
7881

82+
if (OperatingSystem.IsLinux()) {
83+
await LinuxKeepSystemActive().ConfigureAwait(false);
84+
}
85+
7986
if (OperatingSystem.IsWindows()) {
8087
if (systemRequired) {
8188
WindowsKeepSystemActive();
@@ -181,6 +188,12 @@ internal static void UnregisterProcess() {
181188
// Instead, we'll dispose the mutex which should automatically release it by the CLR
182189
SingleInstance.Dispose();
183190
SingleInstance = null;
191+
192+
// Release the inhibit lock as well, if needed
193+
if (InhibitLock != null) {
194+
InhibitLock.Dispose();
195+
InhibitLock = null;
196+
}
184197
}
185198

186199
internal static bool VerifyEnvironment() {
@@ -316,6 +329,31 @@ private static void WindowsDisableQuickEditMode() {
316329
}
317330
}
318331

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+
319357
[SupportedOSPlatform("Windows")]
320358
private static void WindowsKeepSystemActive() {
321359
if (!OperatingSystem.IsWindows()) {

0 commit comments

Comments
 (0)