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