From fc5420db2787b1c98d74b95d826cbbf91fa24812 Mon Sep 17 00:00:00 2001 From: Arksine Date: Tue, 25 May 2021 20:05:15 -0400 Subject: [PATCH] file_manager: filter out websocket notifcations in the gcodes root Only push notifications for files with valid gcode extensions. Signed-off-by: Eric Callahan --- moonraker/components/file_manager.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/moonraker/components/file_manager.py b/moonraker/components/file_manager.py index 064a559..cfa52db 100644 --- a/moonraker/components/file_manager.py +++ b/moonraker/components/file_manager.py @@ -1295,7 +1295,7 @@ class INotifyHandler: logging.debug(f"Syncing notification: {full_path}") IOLoop.current().spawn_callback( self._delay_notification, result, sync_lock.sync(full_path)) - else: + elif self._check_need_notify(file_info): self.server.send_event("file_manager:filelist_changed", result) async def _delay_notification(self, @@ -1303,7 +1303,15 @@ class INotifyHandler: sync_fut: Coroutine ) -> None: await sync_fut - self.server.send_event("file_manager:filelist_changed", result) + if self._check_need_notify(result['item']): + self.server.send_event("file_manager:filelist_changed", result) + + def _check_need_notify(self, file_info: Dict[str, Any]) -> bool: + if file_info['root'] == "gcodes": + ext = os.path.splitext(file_info['path'])[-1] + if ext and ext not in VALID_GCODE_EXTS: + return False + return True def close(self) -> None: IOLoop.current().remove_handler(self.inotify.fileno())