From 76e4aaf49a579e12928af43c2a8300e60c19fd61 Mon Sep 17 00:00:00 2001 From: lwouis Date: Mon, 29 Dec 2025 15:44:48 +0100 Subject: [PATCH] perf: do login item and plist updates later to accelerate launch --- src/ui/App.swift | 2 ++ src/ui/preferences-window/tabs/GeneralTab.swift | 7 ++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/ui/App.swift b/src/ui/App.swift index 16ae98cd..2038ac9d 100644 --- a/src/ui/App.swift +++ b/src/ui/App.swift @@ -313,6 +313,8 @@ extension App: NSApplicationDelegate { MouseEvents.observe() TrackpadEvents.observe() CliEvents.observe() + // login item and plist updates can be done a bit later, to accelerate launch + DispatchQueue.main.asyncAfter(deadline: .now() + 2) { GeneralTab.startAtLoginCallback() } Logger.info("AltTab finished launching") #if DEBUG // self.showPreferencesWindow() diff --git a/src/ui/preferences-window/tabs/GeneralTab.swift b/src/ui/preferences-window/tabs/GeneralTab.swift index e51a2938..be484f36 100644 --- a/src/ui/preferences-window/tabs/GeneralTab.swift +++ b/src/ui/preferences-window/tabs/GeneralTab.swift @@ -20,6 +20,7 @@ class GeneralTab { ] static var menubarIconDropdown: NSPopUpButton? private static var menubarIsVisibleObserver: NSKeyValueObservation? + private static var startAtLoginToggle: NSControl? static func initTab() -> NSView { let startAtLogin = TableGroupView.Row(leftTitle: NSLocalizedString("Start at login", comment: ""), @@ -44,7 +45,7 @@ class GeneralTab { cell.bezelStyle = .regularSquare cell.arrowPosition = .arrowAtBottom cell.imagePosition = .imageOverlaps - startAtLoginCallback(startAtLogin.rightViews[0] as! NSControl) + startAtLoginToggle = startAtLogin.rightViews[0] as? NSControl Menubar.menubarIconCallback(nil) enableDraggingOffMenubarIcon(menuIconShownToggle) let table = TableGroupView(width: PreferencesWindow.width) @@ -83,8 +84,8 @@ class GeneralTab { } /// add/remove plist file in ~/Library/LaunchAgents/ depending on the checkbox state - static func startAtLoginCallback(_ sender: NSControl) { - let sender = sender as! Switch + static func startAtLoginCallback(_: NSControl? = nil) { + let sender = startAtLoginToggle as! Switch // if the user has added AltTab manually as a LoginItem, we remove it, and add AltTab as a LaunchAgent // LaunchAgent are the recommended method for open-at-login in recent versions of macos if (GeneralTab.self as AvoidDeprecationWarnings.Type).removeLoginItemIfPresent() && sender.state == .off {