Repository navigation
Fix hidden Settings CPU during Codex output #4661
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
21c4333
8bd1ba7
9d6f660
6a337a7
73f1892
18d8f96
9ec3e57
f184ec6
24741af
4e8cdc0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| import AppKit | ||
| import SwiftUI | ||
| import Observation | ||
| import Darwin | ||
| import Bonsplit | ||
| import UniformTypeIdentifiers | ||
|
|
@@ -634,11 +635,8 @@ struct cmuxApp: App { | |
| } | ||
|
|
||
| Window(String(localized: "settings.title", defaultValue: "Settings"), id: SettingsWindowPresenter.windowID) { | ||
| SettingsRootView() | ||
| SettingsWindowRootView() | ||
| .cmuxAppearanceColorScheme(appearanceMode) | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
| .background(WindowAccessor { window in | ||
| SettingsWindowPresenter.configure(window: window) | ||
| }) | ||
| } | ||
| .defaultSize(width: 980, height: 680) | ||
| .windowResizability(.contentMinSize) | ||
|
|
@@ -5312,8 +5310,7 @@ struct SettingsView: View { | |
| @State private var didRequestBrowserImportDetection = false | ||
| @State private var isDetectingImportBrowsers = false | ||
| @State private var browserImportDetectionGeneration = 0 | ||
| @State private var browserInsecureHTTPAllowlistDraft = BrowserInsecureHTTPSettings.defaultAllowlistText | ||
| @State private var socketPasswordDraft = "" | ||
| @Bindable var draftState: SettingsDraftState | ||
| @State private var socketPasswordStatusMessage: String? | ||
| @State private var socketPasswordStatusIsError = false | ||
| @State private var notificationCustomSoundStatusMessage: String? | ||
|
|
@@ -5785,7 +5782,7 @@ struct SettingsView: View { | |
| } | ||
|
|
||
| private var browserInsecureHTTPAllowlistHasUnsavedChanges: Bool { | ||
| browserInsecureHTTPAllowlistDraft != browserInsecureHTTPAllowlist | ||
| draftState.browserInsecureHTTPAllowlistDraft != browserInsecureHTTPAllowlist | ||
| } | ||
|
|
||
| private var hasCustomNotificationSoundFilePath: Bool { | ||
|
|
@@ -6066,7 +6063,7 @@ struct SettingsView: View { | |
| } | ||
|
|
||
| private func saveSocketPassword() { | ||
| let trimmed = socketPasswordDraft.trimmingCharacters(in: .whitespacesAndNewlines) | ||
| let trimmed = draftState.socketPasswordDraft.trimmingCharacters(in: .whitespacesAndNewlines) | ||
| guard !trimmed.isEmpty else { | ||
| socketPasswordStatusMessage = String(localized: "settings.automation.socketPassword.enterFirst", defaultValue: "Enter a password first.") | ||
| socketPasswordStatusIsError = true | ||
|
|
@@ -6075,7 +6072,7 @@ struct SettingsView: View { | |
|
|
||
| do { | ||
| try SocketControlPasswordStore.savePassword(trimmed) | ||
| socketPasswordDraft = "" | ||
| draftState.socketPasswordDraft = "" | ||
| socketPasswordStatusMessage = String(localized: "settings.automation.socketPassword.saved", defaultValue: "Password saved.") | ||
| socketPasswordStatusIsError = false | ||
| } catch { | ||
|
|
@@ -6087,7 +6084,7 @@ struct SettingsView: View { | |
| private func clearSocketPassword() { | ||
| do { | ||
| try SocketControlPasswordStore.clearPassword() | ||
| socketPasswordDraft = "" | ||
| draftState.socketPasswordDraft = "" | ||
| socketPasswordStatusMessage = String(localized: "settings.automation.socketPassword.cleared", defaultValue: "Password cleared.") | ||
| socketPasswordStatusIsError = false | ||
| } catch { | ||
|
|
@@ -6938,15 +6935,15 @@ struct SettingsView: View { | |
| : String(localized: "settings.automation.socketPassword.subtitleUnset", defaultValue: "No password set. External clients will be blocked until one is configured.") | ||
| ) { | ||
| HStack(spacing: 8) { | ||
| SecureField(String(localized: "settings.automation.socketPassword.placeholder", defaultValue: "Password"), text: $socketPasswordDraft) | ||
| SecureField(String(localized: "settings.automation.socketPassword.placeholder", defaultValue: "Password"), text: $draftState.socketPasswordDraft) | ||
| .textFieldStyle(.roundedBorder) | ||
| .frame(width: 170) | ||
| Button(hasSocketPasswordConfigured ? String(localized: "settings.automation.socketPassword.change", defaultValue: "Change") : String(localized: "settings.automation.socketPassword.set", defaultValue: "Set")) { | ||
| saveSocketPassword() | ||
| } | ||
| .buttonStyle(.bordered) | ||
| .controlSize(.small) | ||
| .disabled(socketPasswordDraft.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty) | ||
| .disabled(draftState.socketPasswordDraft.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty) | ||
| if hasSocketPasswordConfigured { | ||
| Button(String(localized: "settings.automation.socketPassword.clear", defaultValue: "Clear")) { | ||
| clearSocketPassword() | ||
|
|
@@ -7275,7 +7272,7 @@ struct SettingsView: View { | |
| .font(.caption) | ||
| .foregroundStyle(.secondary) | ||
|
|
||
| TextEditor(text: $browserInsecureHTTPAllowlistDraft) | ||
| TextEditor(text: $draftState.browserInsecureHTTPAllowlistDraft) | ||
| .font(.system(size: 12, weight: .regular, design: .monospaced)) | ||
| .frame(minHeight: 86) | ||
| .padding(6) | ||
|
|
@@ -7737,7 +7734,7 @@ struct SettingsView: View { | |
| browserImportHintVariantRaw = BrowserImportHintSettings.variant(for: browserImportHintVariantRaw).rawValue | ||
| didLoadBrowserHistoryForSettings = BrowserHistoryStore.shared.isLoaded | ||
| browserHistoryEntryCount = didLoadBrowserHistoryForSettings ? BrowserHistoryStore.shared.entries.count : 0 | ||
| browserInsecureHTTPAllowlistDraft = browserInsecureHTTPAllowlist | ||
|
cursor[bot] marked this conversation as resolved.
Resolved
|
||
| draftState.browserInsecureHTTPAllowlistDraft = browserInsecureHTTPAllowlist | ||
|
cursor[bot] marked this conversation as resolved.
Resolved
|
||
| reloadWorkspaceTabColorSettings() | ||
| refreshNotificationCustomSoundStatus() | ||
| let target = SettingsWindowPresenter.consumePendingContentNavigationTarget() | ||
|
|
@@ -7760,8 +7757,8 @@ struct SettingsView: View { | |
| } | ||
| .onChange(of: browserInsecureHTTPAllowlist) { oldValue, newValue in | ||
| // Keep draft in sync with external changes unless the user has local unsaved edits. | ||
| if browserInsecureHTTPAllowlistDraft == oldValue { | ||
| browserInsecureHTTPAllowlistDraft = newValue | ||
| if draftState.browserInsecureHTTPAllowlistDraft == oldValue { | ||
| draftState.browserInsecureHTTPAllowlistDraft = newValue | ||
| } | ||
| } | ||
| .onReceive(BrowserHistoryStore.shared.$entries) { entries in | ||
|
|
@@ -7888,7 +7885,7 @@ struct SettingsView: View { | |
| browserHostWhitelist = BrowserLinkOpenSettings.defaultBrowserHostWhitelist | ||
| browserExternalOpenPatterns = BrowserLinkOpenSettings.defaultBrowserExternalOpenPatterns | ||
| browserInsecureHTTPAllowlist = BrowserInsecureHTTPSettings.defaultAllowlistText | ||
| browserInsecureHTTPAllowlistDraft = BrowserInsecureHTTPSettings.defaultAllowlistText | ||
| draftState.browserInsecureHTTPAllowlistDraft = BrowserInsecureHTTPSettings.defaultAllowlistText | ||
| notificationSound = NotificationSoundSettings.defaultValue | ||
| notificationSoundCustomFilePath = NotificationSoundSettings.defaultCustomFilePath | ||
| notificationCustomSoundStatusMessage = nil | ||
|
|
@@ -7962,7 +7959,7 @@ struct SettingsView: View { | |
| sidebarMatchTerminalBackground = false | ||
| showOpenAccessConfirmation = false | ||
| pendingOpenAccessMode = nil | ||
| socketPasswordDraft = "" | ||
| draftState.socketPasswordDraft = "" | ||
| socketPasswordStatusMessage = nil | ||
| socketPasswordStatusIsError = false | ||
| refreshDetectedImportBrowsers() | ||
|
|
@@ -8017,7 +8014,7 @@ struct SettingsView: View { | |
| } | ||
|
|
||
| private func saveBrowserInsecureHTTPAllowlist() { | ||
| browserInsecureHTTPAllowlist = browserInsecureHTTPAllowlistDraft | ||
| browserInsecureHTTPAllowlist = draftState.browserInsecureHTTPAllowlistDraft | ||
| } | ||
|
|
||
| private func refreshDetectedImportBrowsers() { | ||
|
|
@@ -8739,7 +8736,65 @@ private struct GlobalHotkeySection: View { | |
| } | ||
| } | ||
|
|
||
| private struct SettingsWindowRootView: View { | ||
| @State private var draftState = SettingsDraftState() | ||
| @State private var window: NSWindow? | ||
| @State private var shouldRenderSettingsContent = true | ||
|
|
||
| var body: some View { | ||
| Group { | ||
| if shouldRenderSettingsContent { | ||
| SettingsRootView(draftState: draftState) | ||
| } else { | ||
| Color.clear | ||
| .frame( | ||
| minWidth: SettingsWindowPresenter.minimumSize.width, | ||
| minHeight: SettingsWindowPresenter.minimumSize.height | ||
| ) | ||
| } | ||
|
cursor[bot] marked this conversation as resolved.
Resolved
|
||
| } | ||
| .background(WindowAccessor { window in | ||
| self.window = window | ||
| SettingsWindowPresenter.configure(window: window) | ||
| setContentVisibility(!window.isMiniaturized) | ||
| }) | ||
| .onReceive(NotificationCenter.default.publisher(for: NSWindow.didMiniaturizeNotification)) { notification in | ||
| guard notification.object as? NSWindow === window else { return } | ||
| setContentVisibility(false) | ||
| } | ||
| .onReceive(NotificationCenter.default.publisher(for: NSWindow.didDeminiaturizeNotification)) { notification in | ||
| guard notification.object as? NSWindow === window else { return } | ||
| setContentVisibility(true) | ||
| } | ||
| .onReceive(NotificationCenter.default.publisher(for: NSWindow.didBecomeKeyNotification)) { notification in | ||
| guard notification.object as? NSWindow === window else { return } | ||
| setContentVisibility(true) | ||
| } | ||
| .onReceive(NotificationCenter.default.publisher(for: NSWindow.didBecomeMainNotification)) { notification in | ||
| guard notification.object as? NSWindow === window else { return } | ||
| setContentVisibility(true) | ||
| } | ||
| .onReceive(NotificationCenter.default.publisher(for: NSWindow.willCloseNotification)) { notification in | ||
| guard notification.object as? NSWindow === window else { return } | ||
| setContentVisibility(false) | ||
| } | ||
| } | ||
|
|
||
| private func setContentVisibility(_ isVisible: Bool) { | ||
| guard shouldRenderSettingsContent != isVisible else { return } | ||
| shouldRenderSettingsContent = isVisible | ||
| } | ||
| } | ||
|
Comment on lines
+8820
to
+8876
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Because Rule Used: Flag SwiftUI changes that can cause stale state, b... (source) |
||
|
|
||
| @MainActor | ||
| @Observable | ||
| final class SettingsDraftState { | ||
| var browserInsecureHTTPAllowlistDraft = BrowserInsecureHTTPSettings.defaultAllowlistText | ||
| var socketPasswordDraft = "" | ||
| } | ||
|
|
||
| private struct SettingsRootView: View { | ||
| @Bindable var draftState: SettingsDraftState | ||
| @SceneStorage("selectedSettingsSection") private var selectedSectionRaw = SettingsNavigationTarget.account.rawValue | ||
| @SceneStorage("selectedSettingsSidebarEntry") private var selectedSidebarEntryID = SettingsSearchIndex.defaultSelectionID | ||
| @State private var columnVisibility: NavigationSplitViewVisibility = .all | ||
|
|
@@ -8786,7 +8841,7 @@ private struct SettingsRootView: View { | |
| ) | ||
| .navigationSplitViewColumnWidth(210) | ||
| } detail: { | ||
| SettingsView() | ||
| SettingsView(draftState: draftState) | ||
| } | ||
| .navigationSplitViewStyle(.balanced) | ||
| .frame(minWidth: SettingsWindowPresenter.minimumSize.width, minHeight: SettingsWindowPresenter.minimumSize.height) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
focusHandleris a mutable static closure that lives in the production portion ofSettingsWindowPresenter(outside#if DEBUG), making arbitrary focus behaviour injectable at runtime even though the mutation API (setFocusHandlerForTests) is guarded. Per the project's architectural-rethink rule, introducing a new singleton side channel — even one whose default is alwaysperformFocus— leaves the production invariant implicit rather than enforced. Consider moving the property and its default assignment inside#if DEBUGas well, and callingperformFocusdirectly in the productionfocus(_:)body.Rule Used: Flag Swift fixes that patch symptoms while leaving... (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!