feat: block connection if client is absent or not running

This commit is contained in:
aclist committed 2026-05-09 20:00:31 +09:00
1 parent 77c641327f
commit 3a22ad630a
5 files changed
+49 -33

No files matched your search

+27 -7
View File
@@ -47,6 +47,12 @@ if TYPE_CHECKING:
logger = logging.getLogger(APP_NAME) logger = logging.getLogger(APP_NAME)
@dataclass(slots=True, frozen=True)
class SteamProcess:
name: str
is_running: bool
@dataclass(slots=True, frozen=True) @dataclass(slots=True, frozen=True)
class Prerequisites: class Prerequisites:
name: str name: str
@@ -59,9 +65,10 @@ class Prerequisites:
available_space: float available_space: float
passworded: bool passworded: bool
dayz_running: bool dayz_running: bool
steam_running: bool steam_proc: SteamProcess
mods: list[str] mods: list[str]
foreground_cmd: str | None foreground_cmd: str | None
game_mode: bool
class ConnectionManager: class ConnectionManager:
@@ -118,7 +125,8 @@ class ConnectionManager:
local_version = "0.0.0" local_version = "0.0.0"
binary_missing = True binary_missing = True
remote_mods: list[str, str, str] = [] prefs = self.controller.get_prefs()
remote_mods: list[list[str]] = []
if res.is_modded(): if res.is_modded():
try: try:
remote_mods = self._query_modlist(record) remote_mods = self._query_modlist(record)
@@ -129,9 +137,14 @@ class ConnectionManager:
return return
hashes = get_remote_signatures(self.remote_mod_ids) hashes = get_remote_signatures(self.remote_mod_ids)
version_file = self.controller.get_prefs().paths.version version_file = prefs.paths.version
self.missing_mods = get_needs_update(version_file, hashes) self.missing_mods = get_needs_update(version_file, hashes)
# TODO: walk through missing mods and update remote_mods store
for mod in remote_mods:
if any(mod[1] in tuple for tuple in self.missing_mods):
mod[2] = "Needs updating"
if local_version is not None: if local_version is not None:
pefile_path = PeFile.get_pefile_path(steam_path, info.game_id) pefile_path = PeFile.get_pefile_path(steam_path, info.game_id)
total, used, free = shutil.disk_usage(pefile_path) total, used, free = shutil.disk_usage(pefile_path)
@@ -141,9 +154,15 @@ class ConnectionManager:
free_mib = format_mib(required_size) free_mib = format_mib(required_size)
dayz_running = is_dayz_running() dayz_running = is_dayz_running()
steam_running = is_steam_running()
self.foreground_cmd = self.controller.get_prefs().foreground_cmd client_name = self.controller.get_steam_client_name()
client = self.controller.query_config(Preferences.CLIENT)
running = is_steam_running(client)
steam_proc = SteamProcess(client_name, running)
# /home/USER/.var/app/com.valvesoftware.Steam
self.foreground_cmd = prefs.foreground_cmd
game_mode = prefs.is_game_mode
prereqs = Prerequisites( prereqs = Prerequisites(
name=info.server_name, name=info.server_name,
@@ -156,9 +175,10 @@ class ConnectionManager:
available_space=free_mib, available_space=free_mib,
passworded=info.password_protected, passworded=info.password_protected,
dayz_running=dayz_running, dayz_running=dayz_running,
steam_running=steam_running, steam_proc=steam_proc,
mods=remote_mods, mods=remote_mods,
foreground_cmd=self.foreground_cmd, # TODO: change to bool foreground_cmd=self.foreground_cmd, # TODO: change to bool
game_mode=game_mode,
) )
func = StoredFunc(self.controller.open_connection_assistant, prereqs) func = StoredFunc(self.controller.open_connection_assistant, prereqs)
@@ -261,7 +281,7 @@ class ConnectionManager:
rebuild_symlinks(self.controller.get_prefs().paths.config) rebuild_symlinks(self.controller.get_prefs().paths.config)
# TODO: update version file # TODO: update version file
# TODO: update tree checkmarks # TODO: update tree checkmarks when finished
func = StoredFunc( func = StoredFunc(
self.controller.update_status, "All mods updated.", mark_finished=True self.controller.update_status, "All mods updated.", mark_finished=True
) )
+1 -1
View File
@@ -1,4 +1,4 @@
mod = "Mod" mod = "Mod"
mod_id = "ID" mod_id = "ID"
installed = "Installed" up_to_date = "Up to date"
modlist = "Modlist" modlist = "Modlist"
+6
View File
@@ -49,6 +49,7 @@ class Options(Gtk.Box):
) )
self.controller = controller self.controller = controller
self.controller.register_widget("options", self)
emitter = controller.get_emitter() emitter = controller.get_emitter()
emitter.connect("api_change_failed", self._on_api_change_failed) emitter.connect("api_change_failed", self._on_api_change_failed)
@@ -207,6 +208,11 @@ class Options(Gtk.Box):
self.scrollable.add(grid) self.scrollable.add(grid)
self.add(self.scrollable) self.add(self.scrollable)
def get_client_name(self) -> str:
model = self.client_combo.get_model()
ind = self.client_combo.get_active()
return model[ind][0]
def block_text_entry(self) -> None: def block_text_entry(self) -> None:
for entry in self.steam_entry, self.bm_entry: for entry in self.steam_entry, self.bm_entry:
entry.set_position(-1) entry.set_position(-1)
+14 -24
View File
@@ -145,20 +145,6 @@ class PreConnectionAssistant(Gtk.ScrolledWindow):
) )
self.progress_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=15) self.progress_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=15)
self.progress_box.add(self.mod_count) self.progress_box.add(self.mod_count)
# self.cancel = Gtk.Button(
# label=preconnect.cancel,
# halign=Gtk.Align.START,
# hexpand=True,
# margin_bottom=5,
# margin_top=5,
# )
# self.progress_box.add(self.cancel)
# self.cancel.connect("clicked", self._on_cancel_clicked)
# self.cancel.set_visible(False)
# TODO: live count of remaining downloads
# "Steam is downloading: {mod_name}"
# mention whether manual or auto mod is active
self.scrolled = Gtk.ScrolledWindow() self.scrolled = Gtk.ScrolledWindow()
self.scrolled.add(self.tree) self.scrolled.add(self.tree)
@@ -175,7 +161,6 @@ class PreConnectionAssistant(Gtk.ScrolledWindow):
self.tree_frame = HeadingFrame(self.tree_box, preconnect.mods) self.tree_frame = HeadingFrame(self.tree_box, preconnect.mods)
# TODO: abstract into components # TODO: abstract into components
# TODO: strings # TODO: strings
self.warning_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) self.warning_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
self.warning_tree = MaskedTree(WARNING) self.warning_tree = MaskedTree(WARNING)
@@ -226,9 +211,6 @@ class PreConnectionAssistant(Gtk.ScrolledWindow):
if event.keyval == Gdk.KEY_Escape: if event.keyval == Gdk.KEY_Escape:
self.back.emit("clicked") self.back.emit("clicked")
# def _on_cancel_clicked(self, button: Gtk.Button) -> None:
# print("user canceled")
def _on_ok_clicked(self, button: Gtk.Button) -> None: def _on_ok_clicked(self, button: Gtk.Button) -> None:
# TODO: cancel mod downloads # TODO: cancel mod downloads
# sets some kind of global event listener # sets some kind of global event listener
@@ -248,6 +230,9 @@ class PreConnectionAssistant(Gtk.ScrolledWindow):
warnings: list[str] = [] warnings: list[str] = []
errors: list[str] = [] errors: list[str] = []
# TODO: check availability of currently selected steam cmd
"""Errors"""
if prereqs.binary_missing: if prereqs.binary_missing:
errors.append( errors.append(
f"Remote server is running the build '{prereqs.build}', but it is not installed." f"Remote server is running the build '{prereqs.build}', but it is not installed."
@@ -262,6 +247,17 @@ class PreConnectionAssistant(Gtk.ScrolledWindow):
errors.append( errors.append(
f"Need to update {required_pretty} MiB of mods, but installation path only has {available_pretty} MiB." f"Need to update {required_pretty} MiB of mods, but installation path only has {available_pretty} MiB."
) )
if len(prereqs.mods) > 0 and prereqs.game_mode:
errors.append("Use Desktop Mode to download mods on Steam Deck")
print(prereqs.steam_proc)
if prereqs.steam_proc.is_running is False:
client = prereqs.steam_proc.name
errors.append(
f"'{client}' is set as the default Steam client, but it either not installed or not running."
)
"""Warnings"""
if prereqs.passworded: if prereqs.passworded:
warnings.append( warnings.append(
"Protected: you will be prompted for a password when connecting to this server." "Protected: you will be prompted for a password when connecting to this server."
@@ -270,10 +266,6 @@ class PreConnectionAssistant(Gtk.ScrolledWindow):
warnings.append( warnings.append(
"It looks like DayZ is already running in the background. Exit DayZ before connecting." "It looks like DayZ is already running in the background. Exit DayZ before connecting."
) )
if prereqs.steam_running is False:
warnings.append(
"It looks like Steam is not running. Launch Steam before connecting."
)
self.add_warnings(warnings) self.add_warnings(warnings)
self.add_errors(errors) self.add_errors(errors)
@@ -319,8 +311,6 @@ class PreConnectionAssistant(Gtk.ScrolledWindow):
def update_mod(self, text: str, mark_finished: bool = False) -> None: def update_mod(self, text: str, mark_finished: bool = False) -> None:
self.mod_count.set_label(text) self.mod_count.set_label(text)
# if mark_finished:
# self.cancel.set_visible(False)
def add_errors(self, errors: list[str]) -> None: def add_errors(self, errors: list[str]) -> None:
self.error_tree.extend(errors) self.error_tree.extend(errors)
+1 -1
View File
@@ -32,7 +32,7 @@ class ServerModTreeView(ContextMixin, TreeView): # type: ignore
columns = [ columns = [
server_mods.mod, server_mods.mod,
server_mods.mod_id, server_mods.mod_id,
server_mods.installed, server_mods.up_to_date,
] ]
for i, column_title in enumerate(columns): for i, column_title in enumerate(columns):
renderer = Gtk.CellRendererText(ellipsize=Pango.EllipsizeMode.END) renderer = Gtk.CellRendererText(ellipsize=Pango.EllipsizeMode.END)