From 2492a588b76f0692ea2d7632332823094c55b313 Mon Sep 17 00:00:00 2001 From: Thorsten Sommer Date: Sun, 27 Apr 2025 15:33:33 +0200 Subject: [PATCH] Improve hot reload logic with enhanced logging and semaphore management --- .../PluginSystem/PluginFactory.HotReload.cs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/app/MindWork AI Studio/Tools/PluginSystem/PluginFactory.HotReload.cs b/app/MindWork AI Studio/Tools/PluginSystem/PluginFactory.HotReload.cs index 91641af6..4eb3b0c3 100644 --- a/app/MindWork AI Studio/Tools/PluginSystem/PluginFactory.HotReload.cs +++ b/app/MindWork AI Studio/Tools/PluginSystem/PluginFactory.HotReload.cs @@ -22,15 +22,23 @@ public static partial class PluginFactory HOT_RELOAD_WATCHER.Filter = "*.lua"; HOT_RELOAD_WATCHER.Changed += async (_, args) => { + var changeType = args.ChangeType.ToString().ToLowerInvariant(); if (!await HOT_RELOAD_SEMAPHORE.WaitAsync(0)) { - LOG.LogInformation($"File changed ({args.ChangeType}): {args.FullPath}. Already processing another change."); + LOG.LogInformation($"File changed ({changeType}): {args.FullPath}. Already processing another change."); return; } - - LOG.LogInformation($"File changed ({args.ChangeType}): {args.FullPath}. Reloading plugins..."); - await LoadAll(); - await messageBus.SendMessage(null, Event.PLUGINS_RELOADED); + + try + { + LOG.LogInformation($"File changed ({changeType}): {args.FullPath}. Reloading plugins..."); + await LoadAll(); + await messageBus.SendMessage(null, Event.PLUGINS_RELOADED); + } + finally + { + HOT_RELOAD_SEMAPHORE.Release(); + } }; HOT_RELOAD_WATCHER.EnableRaisingEvents = true;