From 72ca5b1ab3f4e05925a4c78a5bf6defa0dfbdce8 Mon Sep 17 00:00:00 2001 From: xTrayambak Date: Fri, 20 Sep 2024 16:27:18 +0530 Subject: [PATCH] (fix) watcher: don't spam flatpak command; fixes #11 This causes the system to OOM since we constantly force PolicyKit to perform allocations by running `flatpak ps`, for some bizzare reason. --- src/commands/run.nim | 12 +++++++++++- src/flatpak.nim | 4 ++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/commands/run.nim b/src/commands/run.nim index 554e3e7..3a197f2 100644 --- a/src/commands/run.nim +++ b/src/commands/run.nim @@ -200,10 +200,20 @@ proc eventWatcher*( startedPlayingAt = 0.0 startingTime = 0.0 hasntStarted = true + + soberIsRunning = false + ticksUntilSoberRunCheck = 0 - while hasntStarted or flatpakRunning(SOBER_APP_ID): + while hasntStarted or soberIsRunning: let logFile = readFile(getSoberLogPath()).splitLines() + if ticksUntilSoberRunCheck < 1: + debug "lucem: checking if sober is still running" + soberIsRunning = soberRunning() + ticksUntilSoberRunCheck = 5000 + + dec ticksUntilSoberRunCheck + if logFile.len - 1 < line: continue diff --git a/src/flatpak.nim b/src/flatpak.nim index 827f276..cee764d 100644 --- a/src/flatpak.nim +++ b/src/flatpak.nim @@ -21,8 +21,8 @@ proc flatpakInstall*(id: string, user: bool = true): bool {.inline, discardable. info "flatpak: successfully installed \"" & id & "\"!" true -proc flatpakRunning*(id: string): bool {.inline.} = - execCmdEx("flatpak ps --columns=application").output.contains(id) +proc soberRunning*: bool {.inline.} = + execCmdEx("pidof sober").output.len > 2 proc flatpakRun*( id: string, path: string = "/dev/stdout", launcher: string = ""