mirror of
https://github.com/aclist/dztui.git
synced 2026-08-25 17:32:36 +02:00
feat: lazy load ping
This commit is contained in:
parent
933c3b19b0
commit
39abbf3a02
@ -35,6 +35,7 @@
|
||||
- Sidebar buttos do not steal focus
|
||||
- Copy IP copies IP:queryport only instead of IP:gameport:queryport, mimics syntax needed by add by ip method
|
||||
- Load new model into view without flushing
|
||||
- Cull servers with abnormal queue values (integer overflow: 2147483647)
|
||||
|
||||
## Fixed
|
||||
- Longstanding issue with left clicks not registering as tree selection changes after spamming keyboard input
|
||||
|
||||
@ -140,6 +140,8 @@ def parse_json(json: list) -> list:
|
||||
try:
|
||||
r = row["gametype"].split("lqs")
|
||||
queue = r[1].split(",")[0]
|
||||
if int(queue) > 255:
|
||||
continue
|
||||
except IndexError:
|
||||
queue = 0
|
||||
|
||||
@ -225,13 +227,6 @@ class Res:
|
||||
json: Union[str, None]
|
||||
|
||||
|
||||
@dataclass(slots=True, frozen=True)
|
||||
class Ping:
|
||||
addr: str
|
||||
iteration: int
|
||||
ping: int
|
||||
|
||||
|
||||
@dataclass(slots=True, frozen=True)
|
||||
class Details:
|
||||
data: Union[list, None]
|
||||
@ -279,7 +274,6 @@ def get_details(record: Record) -> Details:
|
||||
|
||||
try:
|
||||
info = a2s.info((ip, qport))
|
||||
name = info.server_name
|
||||
except TimeoutError:
|
||||
return Details(None, default_str, False)
|
||||
try:
|
||||
@ -368,31 +362,15 @@ def get_details(record: Record) -> Details:
|
||||
return Details(rows, description, True)
|
||||
|
||||
|
||||
def ping(iteration: int, addr: list, qport: int, ping: int) -> Ping:
|
||||
# addr = row[7]
|
||||
# qport = row[8]
|
||||
|
||||
res = None
|
||||
|
||||
if ping != 9999:
|
||||
return Ping(addr, iteration, ping)
|
||||
|
||||
try:
|
||||
ip = addr.split(":")[0]
|
||||
except IndexError:
|
||||
ping = 9999
|
||||
|
||||
def ping(ip: str, qport: int) -> int:
|
||||
try:
|
||||
res = query_direct(ip, qport, 0.5)
|
||||
if res is None:
|
||||
return 9999
|
||||
else:
|
||||
return res["ping"]
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
if res is None:
|
||||
ping = 9999
|
||||
else:
|
||||
ping = res["ping"]
|
||||
|
||||
return Ping(addr, iteration, ping)
|
||||
return 9999
|
||||
|
||||
|
||||
def query_api(key: str, appid: int, param: str) -> Res:
|
||||
|
||||
@ -35,6 +35,7 @@
|
||||
- Sidebar buttos do not steal focus
|
||||
- Copy IP copies IP:queryport only instead of IP:gameport:queryport, mimics syntax needed by add by ip method
|
||||
- Load new model into view without flushing
|
||||
- Cull servers with abnormal queue values (integer overflow: 2147483647)
|
||||
|
||||
## Fixed
|
||||
- Longstanding issue with left clicks not registering as tree selection changes after spamming keyboard input
|
||||
|
||||
@ -118,6 +118,10 @@ class ServerModelManager:
|
||||
j = res.json
|
||||
servers += j["response"]["servers"]
|
||||
|
||||
import json
|
||||
|
||||
with open("test.txt", "w") as f:
|
||||
json.dump(servers, f)
|
||||
parsed = Servers.parse_json(servers)
|
||||
self._push_data(parsed)
|
||||
|
||||
|
||||
@ -58,6 +58,8 @@ class ServerTreeView(ContextMixin, TreeView):
|
||||
self.handler_id: int
|
||||
self.queue = Queue()
|
||||
|
||||
self.seen_cache = []
|
||||
|
||||
prefs = self.controller.get_prefs()
|
||||
columns = prefs.paths.columns
|
||||
try:
|
||||
@ -93,10 +95,10 @@ class ServerTreeView(ContextMixin, TreeView):
|
||||
else:
|
||||
w = width_map[column_title]
|
||||
column.set_fixed_width(w)
|
||||
# if column_title == "Ping":
|
||||
# self.fancy_col = column
|
||||
# self.fancy_rend = renderer
|
||||
# column.set_cell_data_func(renderer, self._get_ping)
|
||||
if column_title == "Ping":
|
||||
# self.fancy_col = column
|
||||
# self.fancy_rend = renderer
|
||||
column.set_cell_data_func(renderer, self._get_ping)
|
||||
# if column_title == "Name":
|
||||
# column.set_fixed_width(800)
|
||||
# if column_title == "Map":
|
||||
@ -351,39 +353,42 @@ class ServerTreeView(ContextMixin, TreeView):
|
||||
def set_loaded(self, status: bool) -> None:
|
||||
self.loaded = status
|
||||
|
||||
# @deprecated("currently unused")
|
||||
# def _get_ping(
|
||||
# self,
|
||||
# column: Gtk.TreeViewColumn,
|
||||
# cell: Gtk.CellRendererText,
|
||||
# model: Gtk.TreeModel,
|
||||
# it: Gtk.TreeIter,
|
||||
# data: Any,
|
||||
# ):
|
||||
# def ping_server(model, _iter, ip: str, qport: int, ping: int):
|
||||
# res = Ping(0, ip, qport, ping)
|
||||
# ping = res.ping
|
||||
# GLib.idle_add(lambda: model.set(_iter, ping_column, ping))
|
||||
def _get_ping(
|
||||
self,
|
||||
column: Gtk.TreeViewColumn,
|
||||
cell: Gtk.CellRendererText,
|
||||
model: Gtk.TreeModel,
|
||||
_iter: Gtk.TreeIter,
|
||||
data: Any,
|
||||
):
|
||||
def ping_server(model, _iter: Gtk.TreeIter, ip: str, qport: int, ping: int):
|
||||
from dzgui.api.servers import ping
|
||||
|
||||
# addr_column = 7
|
||||
# qport_column = 8
|
||||
# ping_column = 9
|
||||
_ping = ping(ip, qport, ping)
|
||||
GLib.idle_add(lambda: model.set(_iter, ping_column, _ping))
|
||||
|
||||
# addr = model.get_value(it, addr_column).split(":")[0]
|
||||
# qport = model.get_value(it, qport_column)
|
||||
# ping = model.get_value(it, ping_column)
|
||||
# ip = f"{addr}:{qport}"
|
||||
addr_column = 7
|
||||
qport_column = 8
|
||||
ping_column = 9
|
||||
|
||||
# if ip in self.seen_cache:
|
||||
# return
|
||||
# self.seen_cache.append(ip)
|
||||
addr = model.get_value(_iter, addr_column).split(":")
|
||||
ip = addr[0]
|
||||
gameport = addr[1]
|
||||
qport = model.get_value(_iter, qport_column)
|
||||
# ping = model.get_value(_iter, ping_column)
|
||||
record = f"{addr}:{gameport}:{qport}"
|
||||
|
||||
# thread = threading.Thread(
|
||||
# daemon=True,
|
||||
# target=ping_server,
|
||||
# args=(model, it, addr, qport, ping),
|
||||
# )
|
||||
# thread.start()
|
||||
if record in self.seen_cache:
|
||||
return
|
||||
self.seen_cache.append(record)
|
||||
|
||||
# TODO: use thread manager
|
||||
thread = threading.Thread(
|
||||
daemon=True,
|
||||
target=ping_server,
|
||||
args=(model, _iter, ip, qport),
|
||||
)
|
||||
thread.start()
|
||||
|
||||
@deprecated("Currently unused")
|
||||
def _lazy_load(
|
||||
|
||||
Loading…
Reference in New Issue
Block a user