fix: break after 10th record

This commit is contained in:
aclist 2026-05-28 05:47:59 +09:00
parent 2c9b36ba84
commit 1ea30270ce
2 changed files with 34 additions and 24 deletions

View File

@ -55,12 +55,22 @@ class ConfigManager:
def update_history_file(self, fqip: str) -> None:
with open(self.prefs.paths.history, "r") as f:
lines = [line.rstrip() for line in f.readlines()]
lines.append(fqip)
lines = set(lines)
dq = deque(lines, maxlen=10)
ips = [line.rstrip() for line in f.readlines()]
seen = set()
ips.append(fqip)
# NOTE: Preserve linear order of records while deduplicating
unique = deque(maxlen=10)
for i in range(len(ips) - 1, -1, -1):
if ips[i] not in seen:
seen.add(ips[i])
unique.appendleft(ips[i])
# NOTE: appendleft will push 11th item off right edge
if len(unique) == 10:
break
with open(self.prefs.paths.history, "w") as f:
for record in dq:
for record in unique:
f.write(f"{record}\n")
def remove_saved_server(self, record: str) -> None:

View File

@ -265,26 +265,26 @@ class ConnectionManager:
addr = f"{self.record.ip}:{self.record.gameport}"
playername = self.controller.query_config(Preferences.NAME)
client = self.controller.query_config(Preferences.CLIENT)
if menu_only:
rc = load_to_menu(client, addr, self.appid, playername, self.remote_mod_ids)
else:
rc = connect(client, addr, self.appid, playername, self.remote_mod_ids)
if rc != 0:
# TODO: log/pop the error
func = StoredFunc(self.controller.update_status)
self.thread_man.set_cleanup_func(func)
return
#if menu_only:
# rc = load_to_menu(client, addr, self.appid, playername, self.remote_mod_ids)
#else:
# rc = connect(client, addr, self.appid, playername, self.remote_mod_ids)
#if rc != 0:
# # TODO: log/pop the error
# func = StoredFunc(self.controller.update_status)
# self.thread_man.set_cleanup_func(func)
# return
self.thread_man.show_cancel(False)
self.thread_man.update_dialog(waiting_for_launch)
while True:
# TODO: check cancel event
if self.controller.get_exit_event().is_set():
# TODO: some facility to also close spawned steam process
return
if is_dayz_running():
break
time.sleep(1)
#self.thread_man.show_cancel(False)
#self.thread_man.update_dialog(waiting_for_launch)
#while True:
# # TODO: check cancel event
# if self.controller.get_exit_event().is_set():
# # TODO: some facility to also close spawned steam process
# return
# if is_dayz_running():
# break
# time.sleep(1)
func = StoredFunc(self._add_to_history_and_return)
self.thread_man.set_cleanup_func(func)