diff --git a/dzgui/managers/config.py b/dzgui/managers/config.py index 5bdcc7f..d0ab9e8 100644 --- a/dzgui/managers/config.py +++ b/dzgui/managers/config.py @@ -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: diff --git a/dzgui/managers/connection.py b/dzgui/managers/connection.py index a8f5cb2..2521485 100644 --- a/dzgui/managers/connection.py +++ b/dzgui/managers/connection.py @@ -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)