perf: do login item and plist updates later to accelerate launch

This commit is contained in:
lwouis committed 2026-01-03 18:09:19 +01:00
1 parent a62949f0dc
commit 2f72c5d6ae
2 files changed
+6 -3

No files matched your search

+2
View File
@@ -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()
@@ -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 {