fix: crashed if an invalid login item existed (closes #202)
This commit is contained in:
1 parent
19b742a073
commit
48d5d6305e
2 files changed
+5
-3
No files matched your search
@@ -10,7 +10,6 @@ class App: NSApplication, NSApplicationDelegate {
|
||||
static let version = Bundle.main.object(forInfoDictionaryKey: "CFBundleVersion") as! String
|
||||
static let licence = Bundle.main.object(forInfoDictionaryKey: "NSHumanReadableCopyright") as! String
|
||||
static let repository = "https://github.com/lwouis/alt-tab-macos"
|
||||
static let url = URL(fileURLWithPath: Bundle.main.bundlePath) as CFURL
|
||||
static var app: App!
|
||||
static let shortcutMonitor = LocalShortcutMonitor()
|
||||
var statusItem: NSStatusItem?
|
||||
|
||||
@@ -106,13 +106,16 @@ class GeneralTab {
|
||||
@objc static func startAtLoginCallback(_ sender: NSControl) {
|
||||
let loginItems = LSSharedFileListCreate(nil, kLSSharedFileListSessionLoginItems.takeRetainedValue(), nil).takeRetainedValue()
|
||||
let loginItemsSnapshot = LSSharedFileListCopySnapshot(loginItems, nil).takeRetainedValue() as! [LSSharedFileListItem]
|
||||
let itemName = Bundle.main.bundleURL.lastPathComponent as CFString
|
||||
let itemUrl = URL(fileURLWithPath: Bundle.main.bundlePath) as CFURL
|
||||
loginItemsSnapshot.forEach {
|
||||
if LSSharedFileListItemCopyResolvedURL($0, 0, nil).takeRetainedValue() == App.url {
|
||||
if (LSSharedFileListItemCopyDisplayName($0)?.takeRetainedValue() == itemName) ||
|
||||
(LSSharedFileListItemCopyResolvedURL($0, 0, nil)?.takeRetainedValue() == itemUrl) {
|
||||
LSSharedFileListItemRemove(loginItems, $0)
|
||||
}
|
||||
}
|
||||
if (sender as! NSButton).state == .on {
|
||||
LSSharedFileListInsertItemURL(loginItems, kLSSharedFileListItemBeforeFirst.takeRetainedValue(), nil, nil, App.url, nil, nil)
|
||||
LSSharedFileListInsertItemURL(loginItems, kLSSharedFileListItemBeforeFirst.takeRetainedValue(), nil, nil, itemUrl, nil, nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user