feat: connection dialog (WIP)

This commit is contained in:
aclist 2026-05-04 06:01:19 +09:00
parent 29082ea1c1
commit e319c01d58
4 changed files with 63 additions and 28 deletions

View File

@ -156,7 +156,6 @@ def find_stale_mods(config: Path) -> list[int]:
record = fqip_to_record(rec)
try:
mods = get_rules(record)
print(mods)
except Exception:
return []
return [mod.workshop_id for mod in mods]

View File

@ -433,13 +433,14 @@ def validate_ip(addr: str) -> Record:
def get_rules(record: Record) -> list["DayzMod"]:
ip = record.ip
qport = record.qport
try:
mods = dayzquery.dayz_rules((ip, qport)).mods
return [mod for mod in mods]
except Exception as e:
logger.critical(e)
#try:
mods = dayzquery.dayz_rules((ip, qport)).mods
return [mod for mod in mods]
#except Exception as e:
# logger.critical(e)
# raise e
# TODO: supposed to skip failing servers for highlight action
return []
#return []
def query_by_id(addr: str, key: str) -> dict[Any] | None:

View File

@ -27,19 +27,19 @@ class ConnectionManager:
@call_on_thread(dialog.querying)
def connect_by_id(self, addr: str, key: str) -> None:
res = Servers.query_by_id(addr, key)
self.prepare_connection(res)
self._prepare_connection(res)
@call_on_thread(dialog.querying)
def connect_by_ip(self, addr: str) -> None:
res = Servers.query_by_ip(addr)
self.prepare_connection(res)
self._prepare_connection(res)
@call_on_thread(dialog.querying)
def connect_by_record(self, record: Servers.Record) -> None:
res = Servers.query_by_record(record)
self.prepare_connection(res)
self._prepare_connection(res)
def prepare_connection(self, res: dict[Any] | None) -> None:
def _prepare_connection(self, res: dict[Any] | None) -> None:
if res is None:
self.thread_man.set_cleanup_func(
StoredFunc(self._server_timeout), destroy_first=True
@ -49,11 +49,12 @@ class ConnectionManager:
record = Servers.response_to_record(res)
try:
# TODO: proper error handling (currently returns empty list)
mods = self.query_modlist(record)
mods = self._query_modlist(record)
except Exception:
self.thread_man.set_cleanup_func(
StoredFunc(self._server_timeout), destroy_first=True
)
return
func = StoredFunc(self.controller.open_connection_assistant, res, mods)
self.thread_man.set_cleanup_func(func, destroy_first=True)
@ -69,7 +70,7 @@ class ConnectionManager:
StoredFunc(self._present_details_dialog, details), destroy_first=True
)
def query_modlist(self, record: Servers.Record) -> None:
def _query_modlist(self, record: Servers.Record) -> None:
mods = Servers.get_rules(record)
steam_path = self.controller.query_config(Preferences.DEFAULT)
local = get_local_mod_ids(steam_path)
@ -94,7 +95,7 @@ class ConnectionManager:
@call_on_thread(dialog.querying)
def query_modlist_and_present(self, record: Servers.Record) -> None:
try:
mods = self.query_modlist(record)
mods = self._query_modlist(record)
except Exception:
self.thread_man.set_cleanup_func(
StoredFunc(self._server_timeout), destroy_first=True

View File

@ -43,36 +43,61 @@ class PreConnectionAssistant(Gtk.Box):
self.controller.register_widget("preconnect", self)
# TODO: strings
self.back = Gtk.Button(label="Back")
# TODO: dynamic button text if no mods needed
self.ok = Gtk.Button(label="Download mods and connect")
self.button_box.add(self.back)
self.button_box.add(self.ok)
self.back = Gtk.Button(label="Back", halign=Gtk.Align.START)
self.cancel = Gtk.Button(
label="Cancel", halign=Gtk.Align.END, sensitive=False, hexpand=True
)
self.ok = Gtk.Button(label="Update mods and connect", halign=Gtk.Align.END)
self.button_box = Gtk.Box(
orientation=Gtk.Orientation.HORIZONTAL,
valign=Gtk.Align.END,
vexpand=True,
spacing=5,
)
for button in self.back, self.cancel, self.ok:
self.button_box.add(button)
self.back.connect("clicked", self._on_back_clicked)
self.ok.connect("clicked", self._on_ok_clicked)
self.warnings = []
# TODO: populate with strings and icons
# set visibility if warnings > 1
frame = HeadingFrame(Gtk.Label(label="ITEM ONE"), "Warnings")
self.title = Gtk.Label(label="")
self.tree = ServerModTreeView(self.controller)
self.mod_count = Gtk.Label(label="", halign=Gtk.Align.START, margin_start=5)
# 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.add(self.tree)
self.scrolled.set_size_request(600, 400)
self.tree_frame = HeadingFrame(self.scrolled, "Mods")
self.tree_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
self.tree_box.add(self.scrolled)
self.tree_box.add(self.mod_count)
# TODO: should form a part of tree_frame above
self.mod_count = Gtk.Label(label="")
self.tree_frame = HeadingFrame(self.tree_box, "Mods")
self.title = Gtk.Label(label="")
self.warnings = []
# TODO: populate with strings and icons
# set visibility if warnings > 1
# warning category enums with matching strings
"""
blocking warning types:
- build mismatch
- version mismatch
- not enough drive space
passing warning types:
- dayz is running
- steam is not running
- server has password
"""
frame = HeadingFrame(Gtk.Label(label="ITEM ONE"), "Warnings")
self.add(self.title)
self.add(self.tree_frame)
self.add(self.mod_count)
self.add(frame)
self.add(self.button_box)
@ -90,13 +115,16 @@ class PreConnectionAssistant(Gtk.Box):
total = len(mods)
self.title.set_text(f"Connecting to {res["name"]}")
if total < 1:
self.tree.set_visible(False)
self.tree_frame.set_visible(False)
self.mod_count.set_visible(False)
return
else:
self.tree.set_visible(True)
self.mod_count.set_visible(True)
self.mod_count.set_text(f"Total mods: {str(total)}")
# TODO: check which mods need updating
# TODO: fourth column: needs update
# steam_path = self.controller.get_config_man().lookup(Preferences.DEFAULT)
# dayz_version = PeFile.get_pretty_version(steam_path, APPID_DAYZ)
# dayz_exp_version = PeFile.get_pretty_version(steam_path, APPID_DAYZ_EXP)
@ -107,6 +135,12 @@ class PreConnectionAssistant(Gtk.Box):
def connect(self) -> None:
# TODO: add to history file and list store
"""
spawn dialog in thread
watch for subprocess
return to prior page when finished
"""
self.back.emit("clicked")
pass
# TODO: icon for mod signature issue