diff --git a/TrackingBackend/app/config.py b/TrackingBackend/app/config.py index cbcba65..d523d0c 100644 --- a/TrackingBackend/app/config.py +++ b/TrackingBackend/app/config.py @@ -245,8 +245,8 @@ def trackers_position_validator(cls, value: list[TrackerConfig]) -> list[Tracker class ConfigManager(EyeTrackConfig, FileSystemEventHandler): - # TODO: Should the callback return the manager or the config? - def __init__(self, callback: Callable[[ConfigManager, EyeTrackConfig], None] | None = None, *args, **kwargs): + # callback function will a copy of the old config, the manager will have the new config + def __init__(self, callback: Callable[[EyeTrackConfig], None] | None = None, *args, **kwargs): super().__init__(*args, **kwargs) self.__callback = callback self.__logger = get_logger() @@ -266,7 +266,8 @@ def start(self) -> ConfigManager: ) self.__observer.start() - self.load() + # fire callbacks incase the config was modified while the server was offline + self.on_modified(FileModifiedEvent(CONFIG_FILE)) # this also loads the config return self def stop(self) -> None: @@ -317,7 +318,7 @@ def on_modified(self, event: FileModifiedEvent) -> None: if self.load().model_dump() != old_config: self.__logger.info("Config update detected, calling callbacks") if self.__callback is not None: - self.__callback(self, EyeTrackConfig(**old_config)) + self.__callback(EyeTrackConfig(**old_config)) # endregion diff --git a/TrackingBackend/app/etvr.py b/TrackingBackend/app/etvr.py index 165908a..ffe4f45 100644 --- a/TrackingBackend/app/etvr.py +++ b/TrackingBackend/app/etvr.py @@ -39,11 +39,11 @@ def setup_trackers(self) -> None: for tracker in self.trackers: tracker.stop() + self.trackers = [] for tracker_config in self.config.trackers: if tracker_config.enabled: - # no need to create a new tracker if we already have one with the same uuid - if tracker_config.uuid not in [tracker.uuid for tracker in self.trackers]: - self.trackers.append(Tracker(self.config, tracker_config.uuid, self.manager, self.router)) + self.trackers.append(Tracker(self.config, tracker_config.uuid, self.manager, self.router)) + else: logger.error("Cannot setup trackers while ETVR is running!") diff --git a/TrackingBackend/app/utils/process.py b/TrackingBackend/app/utils/process.py index 882e11f..2950668 100644 --- a/TrackingBackend/app/utils/process.py +++ b/TrackingBackend/app/utils/process.py @@ -96,18 +96,17 @@ def set_affinity(self) -> None: self.logger.info(f"affinity={cpu_list} for process `{self.name}`") psutil.Process().cpu_affinity(cpu_list) - def on_config_modified(self, config: ConfigManager, old_config: EyeTrackConfig) -> None: - if config != old_config: - self.logger.debug(f"Config updated for process `{self.name}`") - self.debug = self.base_config.debug - self.on_config_update(self.base_config) - self.window._debug = self.base_config.debug - for tracker in self.base_config.trackers: - if tracker.uuid == self.uuid: - old_tracker = old_config.get_tracker_by_uuid(self.uuid) - if tracker != old_tracker: - self.logger.info(f"Tracker config updated for process `{self.name}`") - self.on_tracker_config_update(tracker) + def on_config_modified(self, old_config: EyeTrackConfig) -> None: + self.logger.debug(f"Config updated for process `{self.name}`") + self.debug = self.base_config.debug + self.on_config_update(self.base_config) + self.window._debug = self.base_config.debug + for tracker_config in self.base_config.trackers: + if tracker_config.uuid == self.uuid: + old_tracker = old_config.get_tracker_by_uuid(self.uuid) + if tracker_config != old_tracker: + self.logger.info(f"Tracker config updated for process `{self.name}`") + self.on_tracker_config_update(tracker_config) # endregion @@ -119,6 +118,7 @@ def start(self) -> None: return try: + self.base_config.load() self.__shutdown_event.clear() self.logger.info(f"Starting Process `{self.name}`") self.__process = Process(target=self._run, name=f"{self.name}")