Skip to content

Commit 76a07af

Browse files
committed
fix: remove lifecycle keepalive window
1 parent c8822a8 commit 76a07af

9 files changed

Lines changed: 89 additions & 205 deletions

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- Usage & Spend: add a Projects panel to the settings pane and let the Models and Projects lists expand beyond the top eight rows (#2985). Thanks @Yuxin-Qiao!
88

99
### Fixed
10+
- Settings: remove the invisible lifecycle keepalive window; the rebuilt Settings window no longer needs it, eliminating its Mission Control/WindowServer footprint entirely (#2955).
1011
- Mission Control: stop the lifecycle keepalive window from participating as a floating all-Spaces window on macOS 27 (#2955). Thanks @phuchong89 for the diagnostics!
1112
- Cost history chart: localize the Projects, Conversations, session, and standard/fast mode labels that previously stayed English for all 23 app languages (#2983). Thanks @Yuxin-Qiao!
1213
- Grok: show SuperGrok Heavy from the CLI settings `subscription_tier_display` instead of labeling every OIDC login as SuperGrok (#2991). Thanks @olddonkey!

‎Sources/CodexBar/CodexbarApp.swift‎

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,6 @@ struct CodexBarApp: App {
105105

106106
@SceneBuilder
107107
var body: some Scene {
108-
// Hidden 1×1 window to keep SwiftUI's lifecycle alive so `Settings` scene
109-
// shows the native toolbar tabs even though the UI is AppKit-based.
110-
WindowGroup("CodexBarLifecycleKeepalive") {
111-
HiddenWindowView()
112-
}
113-
.defaultSize(width: 20, height: 20)
114-
.windowStyle(.hiddenTitleBar)
115-
116108
Settings {
117109
PreferencesView(
118110
settings: self.settings,
@@ -130,22 +122,6 @@ struct CodexBarApp: App {
130122
.windowResizability(.contentMinSize)
131123
}
132124

133-
private func openSettings(pane: SettingsPane) {
134-
self.preferencesSelection.pane = pane
135-
DockIconController.shared.promote()
136-
NSApp.activate(ignoringOtherApps: true)
137-
let outcome = SettingsWindowOpener.live().open(preferred: .appKit)
138-
let logger = CodexBarLog.logger(LogCategories.app)
139-
switch outcome {
140-
case .preferred:
141-
break
142-
case .fallback:
143-
logger.warning("Settings AppKit action was not handled; used notification fallback")
144-
case .failed:
145-
logger.error("Failed to open Settings; AppKit action and notification fallback unavailable")
146-
}
147-
}
148-
149125
private static func applyLanguagePreference(from settings: SettingsStore) {
150126
AppLanguagePreferenceMigration.clearLegacyOverrideIfOwned(storedAppLanguage: settings.appLanguage)
151127
resetCodexBarLocalizationCache()

‎Sources/CodexBar/DockIconController.swift‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,12 @@ struct DockIconWindowDescriptor: Equatable, Sendable {
2727

2828
var isRealWindow: Bool {
2929
guard self.isVisible, !self.isMiniaturized, self.canBecomeKey else { return false }
30-
guard !self.isKeepaliveWindow, !self.isStatusBarWindow else { return false }
30+
guard !self.isTinyWindow, !self.isStatusBarWindow else { return false }
3131
return true
3232
}
3333

34-
private var isKeepaliveWindow: Bool {
35-
if self.identifier == "CodexBarLifecycleKeepalive" || self.title == "CodexBarLifecycleKeepalive" {
36-
return true
37-
}
38-
return self.width <= 20 && self.height <= 20
34+
private var isTinyWindow: Bool {
35+
self.width <= 20 && self.height <= 20
3936
}
4037

4138
private var isStatusBarWindow: Bool {

‎Sources/CodexBar/HiddenWindowView.swift‎

Lines changed: 0 additions & 122 deletions
This file was deleted.

‎Sources/CodexBar/Notifications+CodexBar.swift‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import CodexBarCore
22
import Foundation
33

44
extension Notification.Name {
5-
static let codexbarOpenSettings = Notification.Name("codexbarOpenSettings")
65
static let codexbarDebugBlinkNow = Notification.Name("codexbarDebugBlinkNow")
76
#if DEBUG
87
static let codexbarDebugSimulateMemoryPressure =
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import AppKit
2+
3+
@MainActor
4+
struct SettingsWindowOpener {
5+
enum Outcome: Equatable {
6+
case settingsSelector
7+
case preferencesSelector
8+
case failed
9+
}
10+
11+
private let prepare: @MainActor () -> Void
12+
private let sendAction: @MainActor (Selector) -> Bool
13+
14+
init(
15+
prepare: @escaping @MainActor () -> Void = {},
16+
sendAction: @escaping @MainActor (Selector) -> Bool)
17+
{
18+
self.prepare = prepare
19+
self.sendAction = sendAction
20+
}
21+
22+
static func live() -> Self {
23+
Self(
24+
prepare: {
25+
DockIconController.shared.prepareToOpenSettings()
26+
},
27+
sendAction: { selector in
28+
NSApp.sendAction(selector, to: nil, from: nil)
29+
})
30+
}
31+
32+
func open() -> Outcome {
33+
self.prepare()
34+
if self.sendAction(Selector(("showSettingsWindow:"))) {
35+
return .settingsSelector
36+
}
37+
if self.sendAction(Selector(("showPreferencesWindow:"))) {
38+
return .preferencesSelector
39+
}
40+
return .failed
41+
}
42+
}

‎Sources/CodexBar/StatusItemController+Actions.swift‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -617,14 +617,14 @@ extension StatusItemController: StatusItemMenuPersistentActionDelegate {
617617
self.preferencesSelection.pane = pane
618618
}
619619
NSApp.activate(ignoringOtherApps: true)
620-
let outcome = SettingsWindowOpener.live().open(preferred: .notification)
620+
let outcome = SettingsWindowOpener.live().open()
621621
switch outcome {
622-
case .preferred:
622+
case .settingsSelector:
623623
break
624-
case .fallback:
625-
self.menuLogger.warning("Settings notification relay unavailable; used AppKit fallback")
624+
case .preferencesSelector:
625+
self.menuLogger.warning("Modern Settings action was not handled; used legacy Preferences action")
626626
case .failed:
627-
self.menuLogger.error("Failed to open Settings; notification relay and AppKit fallback unavailable")
627+
self.menuLogger.error("Failed to open Settings; AppKit actions were not handled")
628628
}
629629
}
630630
}

‎Tests/CodexBarTests/DockIconPolicyDecisionTests.swift‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,7 @@ struct DockIconPolicyDecisionTests {
3939
}
4040

4141
@Test
42-
func `ignored windows allow accessory activation policy`() {
43-
let keepalive = self.window(
44-
identifier: "CodexBarLifecycleKeepalive",
45-
title: "CodexBarLifecycleKeepalive",
46-
width: 1,
47-
height: 1,
48-
canBecomeKey: false)
42+
func `status bar and non-key windows allow accessory activation policy`() {
4943
let statusBar = self.window(
5044
classNames: ["NSStatusBarWindow"],
5145
width: 300,
@@ -55,7 +49,7 @@ struct DockIconPolicyDecisionTests {
5549
canBecomeKey: false)
5650

5751
#expect(!DockIconPolicyDecision.shouldUseRegularActivationPolicy(
58-
windows: [keepalive, statusBar, borderlessPanel]))
52+
windows: [statusBar, borderlessPanel]))
5953
}
6054

6155
@Test

‎Tests/CodexBarTests/SettingsWindowOpeningTests.swift‎

Lines changed: 36 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5,52 +5,49 @@ import Testing
55
@MainActor
66
struct SettingsWindowOpeningTests {
77
@Test
8-
func `keepalive shell stays invisible and inert to Mission Control`() {
9-
let keepaliveShell = NSWindow(
10-
contentRect: NSRect(x: 0, y: 0, width: 500, height: 500),
11-
styleMask: [.titled],
12-
backing: .buffered,
13-
defer: false)
14-
let configuratorView = KeepaliveWindowConfiguratorView(windowProvider: { _ in keepaliveShell })
15-
configuratorView.viewDidMoveToWindow()
16-
17-
#expect(keepaliveShell.identifier?.rawValue == "CodexBarLifecycleKeepalive")
18-
#expect(keepaliveShell.styleMask == [.borderless])
19-
#expect(keepaliveShell.level == .normal)
20-
#expect(keepaliveShell.collectionBehavior == [.auxiliary, .ignoresCycle, .transient])
21-
#expect(!keepaliveShell.collectionBehavior.contains(.canJoinAllSpaces))
22-
#expect(keepaliveShell.isExcludedFromWindowsMenu)
23-
#expect(!keepaliveShell.isOpaque)
24-
#expect(keepaliveShell.alphaValue == 0)
25-
#expect(!keepaliveShell.hasShadow)
26-
#expect(keepaliveShell.ignoresMouseEvents)
27-
#expect(!keepaliveShell.canHide)
28-
#expect(keepaliveShell.frame.size == NSSize(width: 1, height: 1))
29-
#expect(keepaliveShell.frame.origin == NSPoint(x: -5000, y: -5000))
30-
}
31-
32-
@Test
33-
func `missing keepalive relay invokes settings fallback`() {
34-
let settingsWindow = NSWindow(
35-
contentRect: NSRect(x: 0, y: 0, width: 640, height: 480),
36-
styleMask: [.titled],
37-
backing: .buffered,
38-
defer: false)
39-
40-
var presentedWindow: NSWindow?
8+
func `modern Settings action opens first`() {
9+
var selectors: [String] = []
4110
var prepareCount = 0
4211
let opener = SettingsWindowOpener(
4312
prepare: { prepareCount += 1 },
44-
notification: { false },
45-
appKit: {
46-
presentedWindow = settingsWindow
13+
sendAction: { selector in
14+
selectors.append(NSStringFromSelector(selector))
4715
return true
4816
})
4917

50-
let outcome = opener.open(preferred: .notification)
18+
let outcome = opener.open()
5119

52-
#expect(outcome == .fallback)
20+
#expect(outcome == .settingsSelector)
5321
#expect(prepareCount == 1)
54-
#expect(presentedWindow === settingsWindow)
22+
#expect(selectors == ["showSettingsWindow:"])
23+
}
24+
25+
@Test
26+
func `legacy Preferences action is the fallback`() {
27+
var selectors: [String] = []
28+
let opener = SettingsWindowOpener(sendAction: { selector in
29+
let name = NSStringFromSelector(selector)
30+
selectors.append(name)
31+
return name == "showPreferencesWindow:"
32+
})
33+
34+
let outcome = opener.open()
35+
36+
#expect(outcome == .preferencesSelector)
37+
#expect(selectors == ["showSettingsWindow:", "showPreferencesWindow:"])
38+
}
39+
40+
@Test
41+
func `unhandled Settings actions report failure`() {
42+
var selectors: [String] = []
43+
let opener = SettingsWindowOpener(sendAction: { selector in
44+
selectors.append(NSStringFromSelector(selector))
45+
return false
46+
})
47+
48+
let outcome = opener.open()
49+
50+
#expect(outcome == .failed)
51+
#expect(selectors == ["showSettingsWindow:", "showPreferencesWindow:"])
5552
}
5653
}

0 commit comments

Comments
 (0)