Skip to content

Commit d8091bb

Browse files
fix: crash when skipping messages in deployed version
1 parent b0f408b commit d8091bb

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/TwitchStreamingTools/Services/GlobalKeyPressService.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class GlobalKeyPressService : IGlobalKeyPressService {
1919
/// <summary>
2020
/// The logger.
2121
/// </summary>
22-
private static readonly ILog LOGGER = LogManager.GetLogger(typeof(GlobalKeyPressService));
22+
private static readonly ILog LOG = LogManager.GetLogger(typeof(GlobalKeyPressService));
2323

2424
/// <summary>
2525
/// The pointer to the hook we added.
@@ -124,7 +124,16 @@ private int KeystrokeCallback(int nCode, IntPtr wParam, IntPtr lParam) {
124124
Key = key
125125
};
126126
LogKey(keybind);
127-
s_onKeystroke?.Invoke(keybind);
127+
128+
var callbacks = s_onKeystroke;
129+
foreach (var callback in callbacks?.GetInvocationList() ?? []) {
130+
try {
131+
callback.DynamicInvoke(keybind);
132+
}
133+
catch (Exception ex) {
134+
LOG.Error("Callback failed", ex);
135+
}
136+
}
128137
}
129138
else if (whatHappened == KeyboardMessage.KEY_UP) {
130139
if (modifiers.Contains(key)) {
@@ -140,6 +149,6 @@ private int KeystrokeCallback(int nCode, IntPtr wParam, IntPtr lParam) {
140149
/// </summary>
141150
/// <param name="keybind">The key pressed.</param>
142151
private void LogKey(Keybind keybind) {
143-
LOGGER.Debug($"Key pressed: {keybind}");
152+
LOG.Debug($"Key pressed: {keybind}");
144153
}
145154
}

0 commit comments

Comments
 (0)