Skip to content

Commit

Permalink
(fix) watcher: don't spam flatpak command; fixes #11
Browse files Browse the repository at this point in the history
This causes the system to OOM since we constantly force PolicyKit to
perform allocations by running `flatpak ps`, for some bizzare reason.
  • Loading branch information
xTrayambak committed Sep 20, 2024
1 parent 20af9c2 commit 72ca5b1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
12 changes: 11 additions & 1 deletion src/commands/run.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions src/flatpak.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
Expand Down

0 comments on commit 72ca5b1

Please sign in to comment.