Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions Sources/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCent
private var browserAddressBarBlurObserver: NSObjectProtocol?
private var browserWebViewFirstResponderObserver: NSObjectProtocol?
let updateLog = UpdateLogStore()
let focusLog = FocusLogStore()
private lazy var updateController = UpdateController(log: updateLog)
private lazy var titlebarAccessoryController = UpdateTitlebarAccessoryController(updateLog: updateLog)
private let windowDecorationsController = WindowDecorationsController()
Expand Down Expand Up @@ -1123,7 +1124,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCent
let mainWindowNumber = NSApp.mainWindow?.windowNumber ?? -1
let ws = workspaceId.map { String($0.uuidString.prefix(8)) } ?? "nil"
let wd = workingDirectory.map { String($0.prefix(120)) } ?? "-"
FocusLogStore.shared.append(
focusLog.append(
"cmdn.route phase=\(phase) src=\(source) reason=\(reason) eventWin=\(eventWindowNumber) eventNum=\(eventNumber) keyCode=\(eventKeyCode) chars=\(eventChars) keyWin=\(keyWindowNumber) mainWin=\(mainWindowNumber) activeTM=\(pointerString(tabManager)) chosen={\(summarizeContextForWorkspaceRouting(chosenContext))} ws=\(ws) wd=\(wd) contexts=[\(summarizeAllContextsForWorkspaceRouting())]"
)
}
Expand Down Expand Up @@ -7817,7 +7818,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCent
private func synchronizeShortcutRoutingContext(event: NSEvent) -> Bool {
guard let context = preferredMainWindowContextForShortcutRouting(event: event) else {
#if DEBUG
FocusLogStore.shared.append(
focusLog.append(
"shortcut.route reason=no_context_no_fallback eventWin=\(event.windowNumber) keyCode=\(event.keyCode)"
)
#endif
Expand All @@ -7841,7 +7842,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCent
}

#if DEBUG
FocusLogStore.shared.append(
focusLog.append(
"shortcut.route reason=sync activeTM=\(pointerString(tabManager)) chosen={\(summarizeContextForWorkspaceRouting(context))}"
)
#endif
Expand Down Expand Up @@ -8590,12 +8591,12 @@ final class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCent
pasteboard.setString(payload, forType: .string)
}
@objc func copyFocusLogs(_ sender: Any?) {
let logText = FocusLogStore.shared.snapshot()
let logText = focusLog.snapshot()
let payload: String
if logText.isEmpty {
payload = "No focus logs captured.\nLog file: \(FocusLogStore.shared.logPath())"
payload = "No focus logs captured.\nLog file: \(focusLog.logPath())"
} else {
payload = logText + "\nLog file: \(FocusLogStore.shared.logPath())"
payload = logText + "\nLog file: \(focusLog.logPath())"
}
let pasteboard = NSPasteboard.general
pasteboard.clearContents()
Expand Down
2 changes: 1 addition & 1 deletion Sources/GhosttyTerminalView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7488,7 +7488,7 @@ class GhosttyNSView: NSView, NSUserInterfaceValidations {

fileprivate static func focusLog(_ message: String) {
guard focusDebugEnabled else { return }
FocusLogStore.shared.append(message)
AppDelegate.shared?.focusLog.append(message)
NSLog("[FOCUSDBG] %@", message)
}

Expand Down
9 changes: 5 additions & 4 deletions Sources/Update/UpdateLogStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,17 @@ final class UpdateLogStore: UpdateLogging, @unchecked Sendable {
}
}

final class FocusLogStore {
static let shared = FocusLogStore()

// @unchecked Sendable: all mutable state (`entries`) is confined to the serial `queue`; the other
// stored properties are immutable. Owned and injected by `AppDelegate` (see `AppDelegate.focusLog`)
// rather than self-vending a global, so its lifecycle has a single composition root.
final class FocusLogStore: @unchecked Sendable {
private let queue = DispatchQueue(label: "cmux.focus.log")
private var entries: [String] = []
private let maxEntries = 400
private let logURL: URL
private let formatter: ISO8601DateFormatter

private init() {
init() {
formatter = ISO8601DateFormatter()
formatter.formatOptions = [.withInternetDateTime, .withFractionalSeconds]
let logsDir = FileManager.default.urls(for: .libraryDirectory, in: .userDomainMask).first
Expand Down
4 changes: 2 additions & 2 deletions Sources/Workspace.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16043,7 +16043,7 @@ final class Workspace: Identifiable, ObservableObject {
let pane = bonsplitController.focusedPaneId?.id.uuidString.prefix(5) ?? "nil"
let triggerLabel = trigger == .terminalFirstResponder ? "firstResponder" : "standard"
cmuxDebugLog("focus.panel panel=\(panelId.uuidString.prefix(5)) pane=\(pane) trigger=\(triggerLabel)")
FocusLogStore.shared.append(
AppDelegate.shared?.focusLog.append(
"Workspace.focusPanel panelId=\(panelId.uuidString) focusedPane=\(pane) trigger=\(triggerLabel)"
)
#endif
Expand Down Expand Up @@ -18661,7 +18661,7 @@ extension Workspace: BonsplitDelegate {
// When a pane is focused, focus its selected tab's panel
guard let tab = controller.selectedTab(inPane: pane) else { return }
#if DEBUG
FocusLogStore.shared.append(
AppDelegate.shared?.focusLog.append(
"Workspace.didFocusPane paneId=\(pane.id.uuidString) tabId=\(tab.id) focusedPane=\(controller.focusedPaneId?.id.uuidString ?? "nil")"
)
#endif
Expand Down
Loading