fix: restore default cmd+tab shortcut when alt-tab crashes

This commit is contained in:
lwouis
2024-06-21 11:52:36 +02:00
parent 4371eb7c39
commit 2c47b4e585
+15 -4
View File
@@ -1,11 +1,22 @@
import AppKit
import Darwin
// if the app is quit/force-quit from Activity Monitor, it will receive SIGTERM and applicationWillTerminate won't be called
// we intercept SIGTERM so we can reset the native command-tab shortcut
signal(SIGTERM) { _ in
// symbolic hotkeys state persist after the app is quit; we restore this shortcut before quitting
// - if the app is quit/force-quit from Activity Monitor, it will receive SIGTERM and applicationWillTerminate won't be called
// - if the app crashes in swift code (e.g. unexpected nil object), SIGTRAP is sent
// we intercept these signals, and reset the native command-tab shortcut
[SIGTERM, SIGTRAP].forEach {
signal($0) { s in
setNativeCommandTabEnabled(true)
debugPrint("Exiting after receiving signal", s)
exit(0)
}
}
// - if the app crashes in objective-c code, an NSException may be sent
// we intercept the exception, and reset the native command-tab shortcut
NSSetUncaughtExceptionHandler { (exception) in
setNativeCommandTabEnabled(true)
debugPrint("Exiting after receiving uncaught NSException", exception)
exit(0)
}