Skip to content

Commit 7116d06

Browse files
committed
fix #27
problem was when calling via ui, not function level when called from ui it would unsubscribe from statechanged before the state was set to completed
1 parent 1561e9b commit 7116d06

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

SomethingNeedDoing/Managers/MacroScheduler.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -329,22 +329,15 @@ public async void StopMacro(string macroId)
329329
if (_macroStates.TryGetValue(macroId, out var state))
330330
{
331331
state.CancellationSource.Cancel();
332-
state.Macro.StateChanged -= OnMacroStateChanged;
333332
state.Macro.State = MacroState.Completed;
334333

334+
// rest of the cleanup will be handled by OnMacroStateChanged
335335
UnregisterFunctionTriggers(state.Macro);
336336
await SetPluginStates(state.Macro, true);
337337

338-
// Execute cleanup functions
339-
_cleanupManager.ExecuteCleanup(macroId, "Stopped");
340-
341338
if (C.PropagateControlsToChildren)
342339
foreach (var child in _macroHierarchy.GetChildMacros(macroId).ToList())
343340
StopMacro(child.Id);
344-
345-
if (_macroStates.TryRemove(macroId, out var removedState))
346-
removedState.Dispose();
347-
_enginesByMacroId.TryRemove(macroId, out _);
348341
}
349342
}
350343

@@ -505,8 +498,15 @@ private void OnMacroStateChanged(object? sender, MacroStateChangedEventArgs e)
505498
tempMacro.StateChanged -= OnMacroStateChanged;
506499
}
507500

508-
StopMacro(e.MacroId); // handle local cancellations/state
509-
CleanupMacro(e.MacroId); // cleanup triggers/state
501+
if (_macroStates.TryRemove(e.MacroId, out var state))
502+
{
503+
UnregisterFunctionTriggers(state.Macro);
504+
state.CancellationSource.Cancel();
505+
state.CancellationSource.Dispose();
506+
state.Macro.StateChanged -= OnMacroStateChanged;
507+
}
508+
509+
_enginesByMacroId.TryRemove(e.MacroId, out _);
510510
}
511511
}
512512

0 commit comments

Comments
 (0)