mirror of
https://github.com/aclist/dztui.git
synced 2026-10-30 14:42:54 +01:00
chore: simplify process checking logic
This commit is contained in:
1 parent
7c62aed6b0
commit
77c641327f
2 files changed
+41
-24
No files matched your search
+39
-20
@@ -3,29 +3,40 @@ import subprocess
|
|||||||
import shutil
|
import shutil
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from dzgui.const.constants import DAYZ_BINARY, STEAM_CMD
|
from dzgui.const.constants import (
|
||||||
|
DAYZ_BINARY,
|
||||||
|
STEAM_CMD,
|
||||||
|
FLATPAK_APPID,
|
||||||
|
FLATPAK_RUN_CMD,
|
||||||
|
FLATPAK_SANDBOX,
|
||||||
|
)
|
||||||
from dzgui.views.dialogs.early_alert import EarlyAlertDialog
|
from dzgui.views.dialogs.early_alert import EarlyAlertDialog
|
||||||
from dzgui.util.strings import init
|
from dzgui.util.strings import init
|
||||||
|
|
||||||
# TODO: move to util.proc
|
# TODO: move to util.proc
|
||||||
|
def is_dayz_running() -> bool:
|
||||||
|
return is_running(DAYZ_BINARY)
|
||||||
|
|
||||||
|
|
||||||
# TODO: simplify
|
def is_steam_running(cmd: str) -> bool:
|
||||||
def is_dayz_running(dialog: bool = False) -> bool | None:
|
if cmd == STEAM_CMD:
|
||||||
if dialog is False:
|
if has_cmd(STEAM_CMD) is False:
|
||||||
return is_running(DAYZ_BINARY)
|
return False
|
||||||
if is_running(DAYZ_BINARY) is True:
|
|
||||||
EarlyAlertDialog(init.is_dayz_running)
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
|
|
||||||
def is_steam_running(dialog: bool = False) -> bool | None:
|
|
||||||
# TODO: check proc name of flatpak steam
|
|
||||||
if dialog is False:
|
|
||||||
return is_running(STEAM_CMD)
|
return is_running(STEAM_CMD)
|
||||||
if is_running(STEAM_CMD) is False:
|
elif cmd == FLATPAK_RUN_CMD or FLATPAK_SANDBOX:
|
||||||
EarlyAlertDialog(init.is_steam_running)
|
return is_flatpak_steam_running()
|
||||||
sys.exit(1)
|
else:
|
||||||
|
raise TypeError("Not a valid Steam client selection")
|
||||||
|
|
||||||
|
|
||||||
|
def is_flatpak_steam_running() -> bool:
|
||||||
|
if has_cmd(FLATPAK_CMD) is False:
|
||||||
|
return False
|
||||||
|
proc = subprocess.check_output([FLATPAK_CMD, "ps"], capture_output=True, text=True)
|
||||||
|
lines = proc.stdout.splitlines()
|
||||||
|
if FLATPAK_APPID in lines:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def is_running(proc: str) -> bool:
|
def is_running(proc: str) -> bool:
|
||||||
@@ -43,8 +54,10 @@ def has_cmd(cmd: str) -> bool:
|
|||||||
|
|
||||||
def foreground(cmd: str, pid: int) -> None:
|
def foreground(cmd: str, pid: int) -> None:
|
||||||
if cmd == "wmctrl":
|
if cmd == "wmctrl":
|
||||||
proc = subprocess.run(["wmctrl", "-ilp"], capture_output=True, text=True)
|
proc = subprocess.check_output(
|
||||||
lines = proc.stdout.splitlines()
|
["wmctrl", "-ilp"], capture_output=True, text=True
|
||||||
|
)
|
||||||
|
lines = proc.splitlines()
|
||||||
for line in lines:
|
for line in lines:
|
||||||
els = line.split(" ")
|
els = line.split(" ")
|
||||||
if str(pid) in els:
|
if str(pid) in els:
|
||||||
@@ -52,5 +65,11 @@ def foreground(cmd: str, pid: int) -> None:
|
|||||||
break
|
break
|
||||||
subprocess.run(["wmctrl", "-ia", wid])
|
subprocess.run(["wmctrl", "-ia", wid])
|
||||||
elif cmd == "xdotool":
|
elif cmd == "xdotool":
|
||||||
args = [cmd, "search", "--onlyvisible", "--name", "DZGUI", "windowactivate"]
|
args = [cmd, "search", "--pid", str(pid)]
|
||||||
subprocess.Popen([*args])
|
proc = subprocess.check_output([*args], stderr=subprocess.DEVNULL)
|
||||||
|
lines = proc.splitlines()
|
||||||
|
## NOTE: some forked subprocesses may fail, so skip over them
|
||||||
|
for line in lines:
|
||||||
|
subprocess.run(
|
||||||
|
["xdotool", "windowactivate", line], stderr=subprocess.DEVNULL
|
||||||
|
)
|
||||||
+2
-4
@@ -122,6 +122,8 @@ def main() -> None:
|
|||||||
if allow is True:
|
if allow is True:
|
||||||
check_updates(version)
|
check_updates(version)
|
||||||
|
|
||||||
|
# TODO: config wizard: check has_steam_client() prior to VDF exploration
|
||||||
|
|
||||||
if _is_steam_deck is False:
|
if _is_steam_deck is False:
|
||||||
# TODO: sudo escalation dialog
|
# TODO: sudo escalation dialog
|
||||||
count = get_map_count()
|
count = get_map_count()
|
||||||
@@ -129,10 +131,6 @@ def main() -> None:
|
|||||||
if has_steam_client() is False:
|
if has_steam_client() is False:
|
||||||
EarlyAlertDialog(init.requires_steam)
|
EarlyAlertDialog(init.requires_steam)
|
||||||
|
|
||||||
is_dayz_installed(XDG.config)
|
|
||||||
is_dayz_running(dialog=True)
|
|
||||||
is_steam_running(dialog=True)
|
|
||||||
|
|
||||||
# NOTE: clear versions file of unlinked mods
|
# NOTE: clear versions file of unlinked mods
|
||||||
rebuild_symlinks(XDG.config)
|
rebuild_symlinks(XDG.config)
|
||||||
remove_stale_signatures(XDG.config, XDG.version)
|
remove_stale_signatures(XDG.config, XDG.version)
|
||||||
|
|||||||
Reference in new issue
Block a user