fix: avoid crashing in some cases

This commit is contained in:
allsochen
2024-10-12 15:23:36 +08:00
committed by lwouis
parent b4e97ead04
commit d46d90395c
3 changed files with 21 additions and 10 deletions
+9
View File
@@ -1,6 +1,13 @@
import AppKit
import Darwin
func printStackTrace() {
let stackSymbols = Thread.callStackSymbols
for symbol in stackSymbols {
print(symbol)
}
}
// - 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
@@ -8,6 +15,7 @@ import Darwin
signal($0) { s in
setNativeCommandTabEnabled(true)
debugPrint("Exiting after receiving signal", s)
printStackTrace()
exit(0)
}
}
@@ -17,6 +25,7 @@ import Darwin
NSSetUncaughtExceptionHandler { (exception) in
setNativeCommandTabEnabled(true)
debugPrint("Exiting after receiving uncaught NSException", exception)
printStackTrace()
exit(0)
}
+6 -6
View File
@@ -183,18 +183,16 @@ class App: AppCenterApplication, NSApplicationDelegate {
permissionsWindow.show()
}
@objc func showFeedbackPanel() {
showSecondaryWindow(feedbackWindow)
}
@objc func supportProject() {
NSWorkspace.shared.open(URL(string: App.website + "/support")!)
}
@objc func showFeedbackPanel() {
showSecondaryWindow(feedbackWindow)
}
@objc func showPreferencesWindow() {
showSecondaryWindow(preferencesWindow)
// Use the center function to continue to center, the `repositionPanel` function cannot center, it may be a system bug
preferencesWindow.center()
}
func showSecondaryWindow(_ window: NSWindow?) {
@@ -202,6 +200,8 @@ class App: AppCenterApplication, NSApplicationDelegate {
NSScreen.preferred().repositionPanel(window)
App.shared.activate(ignoringOtherApps: true)
window.makeKeyAndOrderFront(nil)
// Use the center function to continue to center, the `repositionPanel` function cannot center, it may be a system bug
window.center()
}
}
@@ -260,12 +260,14 @@ class LabelAndControl: NSObject {
button.setWidth(segmentWidth, forSegment: i)
}
if #available(macOS 11.0, *) {
if let preference = preference as? SfSymbolMacroPreference {
button.setImage(NSImage(systemSymbolName: preference.symbolName, accessibilityDescription: nil)!, forSegment: i)
if let preference = preference as? SfSymbolMacroPreference,
let symbolImage = NSImage(systemSymbolName: preference.symbolName, accessibilityDescription: nil) {
button.setImage(symbolImage, forSegment: i)
}
}
if defaults.int(rawName) == i {
button.selectedSegment = i
let selectedSegment = defaults.int(rawName)
if selectedSegment >= 0 && selectedSegment < macroPreferences.count {
button.selectedSegment = selectedSegment
}
_ = setupControl(button, rawName, String(i), extraAction: extraAction)
}