Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 8 additions & 4 deletions Sources/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1346,7 +1346,8 @@ struct ContentView: View {
forTabId: workspace.id,
surfaceId: panelId
),
isManuallyUnread: workspace.manualUnreadPanelIds.contains(panelId),
hasPanelUnreadIndicator: workspace.manualUnreadPanelIds.contains(panelId) ||
workspace.restoredUnreadPanelIds.contains(panelId),
isWorkspaceManuallyUnread: isWorkspaceManuallyUnread,
isWorkspaceManualUnreadRepresentative: workspaceManualUnreadPanelId == panelId
)
Expand Down Expand Up @@ -6058,7 +6059,9 @@ struct ContentView: View {
snapshot.setBool(CommandPaletteContextKeys.panelHasCustomName, workspace.panelCustomTitles[panelId] != nil)
snapshot.setBool(CommandPaletteContextKeys.panelShouldPin, !workspace.isPanelPinned(panelId))
snapshot.setBool(CommandPaletteContextKeys.panelCanMoveToNewWorkspace, workspace.panels.count > 1)
let hasUnread = workspace.manualUnreadPanelIds.contains(panelId) || notificationStore.hasUnreadNotification(forTabId: workspace.id, surfaceId: panelId)
let hasUnread = workspace.manualUnreadPanelIds.contains(panelId) ||
workspace.restoredUnreadPanelIds.contains(panelId) ||
notificationStore.hasUnreadNotification(forTabId: workspace.id, surfaceId: panelId)
snapshot.setBool(CommandPaletteContextKeys.panelHasUnread, hasUnread)

if panelIsTerminal {
Expand Down Expand Up @@ -7387,8 +7390,9 @@ struct ContentView: View {
NSSound.beep()
return
}
let hasUnread = panelContext.workspace.manualUnreadPanelIds.contains(panelContext.panelId)
|| notificationStore.hasUnreadNotification(forTabId: panelContext.workspace.id, surfaceId: panelContext.panelId)
let hasUnread = panelContext.workspace.manualUnreadPanelIds.contains(panelContext.panelId) ||
panelContext.workspace.restoredUnreadPanelIds.contains(panelContext.panelId) ||
notificationStore.hasUnreadNotification(forTabId: panelContext.workspace.id, surfaceId: panelContext.panelId)
if hasUnread {
panelContext.workspace.markPanelRead(panelContext.panelId)
} else {
Expand Down
3 changes: 3 additions & 0 deletions Sources/SessionPersistence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ struct SessionPanelSnapshot: Codable, Sendable {
var directory: String?
var isPinned: Bool
var isManuallyUnread: Bool
var hasUnreadIndicator: Bool? = nil
var gitBranch: SessionGitBranchSnapshot?
var listeningPorts: [Int]
var ttyName: String?
Expand Down Expand Up @@ -343,6 +344,8 @@ struct SessionWorkspaceSnapshot: Codable, Sendable {
var customDescription: String?
var customColor: String?
var isPinned: Bool
var isManuallyUnread: Bool? = nil
var hasUnreadIndicator: Bool? = nil
var terminalScrollBarHidden: Bool?
var currentDirectory: String
var focusedPanelId: UUID?
Expand Down
34 changes: 28 additions & 6 deletions Sources/TabManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5139,30 +5139,41 @@ class TabManager: ObservableObject {
guard let notificationStore = AppDelegate.shared?.notificationStore else { return false }
let workspace = tabs.first(where: { $0.id == tabId })
let hasManualPanelUnread = surfaceId.map { workspace?.manualUnreadPanelIds.contains($0) ?? false } ?? false
let hasRestoredPanelUnread = surfaceId.map { workspace?.hasRestoredUnreadIndicator(panelId: $0) ?? false } ?? false
let hasManualWorkspaceUnread = notificationStore.hasManualUnread(forTabId: tabId)
let canDismissManualUnread = context == .terminalInteraction && (hasManualPanelUnread || hasManualWorkspaceUnread)
let hasRestoredWorkspaceUnread = notificationStore.hasRestoredUnreadIndicator(forTabId: tabId)
let canDismissUnreadIndicator = context == .terminalInteraction &&
(hasManualPanelUnread || hasRestoredPanelUnread || hasManualWorkspaceUnread || hasRestoredWorkspaceUnread)
let hasUnreadNotification = notificationStore.hasUnreadNotification(forTabId: tabId, surfaceId: surfaceId)
let hasFocusedIndicator = notificationStore.hasVisibleNotificationIndicator(forTabId: tabId, surfaceId: surfaceId)
guard hasUnreadNotification || hasFocusedIndicator || canDismissManualUnread else { return false }
guard hasUnreadNotification || hasFocusedIndicator || canDismissUnreadIndicator else { return false }
if hasUnreadNotification {
notificationStore.markRead(forTabId: tabId, surfaceId: surfaceId)
}
var didDismissManualUnread = false
var didDismissUnreadIndicator = false
if context == .terminalInteraction {
if let panelId = surfaceId, hasManualPanelUnread {
workspace?.clearManualUnread(panelId: panelId)
didDismissManualUnread = true
didDismissUnreadIndicator = true
}
if let panelId = surfaceId, hasRestoredPanelUnread {
workspace?.clearRestoredUnreadIndicator(panelId: panelId)
didDismissUnreadIndicator = true
}
if hasManualWorkspaceUnread {
didDismissManualUnread = notificationStore.clearManualUnread(forTabId: tabId) || didDismissManualUnread
didDismissUnreadIndicator = notificationStore.clearManualUnread(forTabId: tabId) || didDismissUnreadIndicator
}
if hasRestoredWorkspaceUnread {
didDismissUnreadIndicator = notificationStore.clearRestoredUnreadIndicator(forTabId: tabId) ||
didDismissUnreadIndicator
}
}
notificationStore.clearFocusedReadIndicator(forTabId: tabId, surfaceId: surfaceId)
if let panelId = surfaceId,
let workspace {
if hasUnreadNotification || hasFocusedIndicator {
workspace.triggerNotificationDismissFlash(panelId: panelId)
} else if didDismissManualUnread {
} else if didDismissUnreadIndicator {
workspace.triggerManualUnreadDismissFlash(panelId: panelId)
}
}
Expand Down Expand Up @@ -7306,6 +7317,7 @@ extension TabManager {
var hasher = Hasher()
hasher.combine(selectedTabId)
hasher.combine(tabs.count)
let notificationStore = AppDelegate.shared?.notificationStore

for workspace in tabs.prefix(SessionPersistencePolicy.maxWorkspacesPerWindow) {
hasher.combine(workspace.id)
Expand All @@ -7325,11 +7337,21 @@ extension TabManager {
hasher.combine(workspace.panelPullRequests.count)
hasher.combine(workspace.panelGitBranches.count)
hasher.combine(workspace.surfaceListeningPorts.count)
hasher.combine(notificationStore?.hasManualUnread(forTabId: workspace.id) ?? false)
hasher.combine(notificationStore?.workspaceIsUnread(forTabId: workspace.id) ?? false)

let panelIds = workspace.panels.keys.sorted { $0.uuidString < $1.uuidString }
hasher.combine(panelIds.count)
for panelId in panelIds {
hasher.combine(panelId)
hasher.combine(workspace.manualUnreadPanelIds.contains(panelId))
hasher.combine(workspace.restoredUnreadPanelIds.contains(panelId))
hasher.combine(
notificationStore?.hasVisibleNotificationIndicator(
forTabId: workspace.id,
surfaceId: panelId
) ?? false
)
Self.hashRestorableAgentSnapshot(
restorableAgentIndex.snapshot(
workspaceId: workspace.id,
Expand Down
60 changes: 56 additions & 4 deletions Sources/TerminalNotificationStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,7 @@ final class TerminalNotificationStore: ObservableObject {
// Workspace-level manual unread drives sidebar workspace badges; pane-level
// manual unread remains owned by Workspace.manualUnreadPanelIds.
@Published private(set) var manualUnreadWorkspaceIds: Set<UUID> = []
@Published private(set) var restoredUnreadWorkspaceIds: Set<UUID> = []
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
@Published private(set) var focusedReadIndicatorByTabId: [UUID: UUID] = [:]
@Published private(set) var authorizationState: NotificationAuthorizationState = .unknown
private var suppressNotificationDiffPublishing = false
Expand Down Expand Up @@ -915,19 +916,54 @@ final class TerminalNotificationStore: ObservableObject {
manualUnreadWorkspaceIds = []
}

@discardableResult
private func setWorkspaceRestoredUnread(_ isUnread: Bool, forTabId tabId: UUID) -> Bool {
var nextIds = restoredUnreadWorkspaceIds
let didChange: Bool
if isUnread {
didChange = nextIds.insert(tabId).inserted
} else {
didChange = nextIds.remove(tabId) != nil
}
guard didChange else { return false }
restoredUnreadWorkspaceIds = nextIds
return true
}

private func clearWorkspaceRestoredUnread() {
guard !restoredUnreadWorkspaceIds.isEmpty else { return }
restoredUnreadWorkspaceIds = []
}

func hasManualUnread(forTabId tabId: UUID) -> Bool {
manualUnreadWorkspaceIds.contains(tabId)
}

func hasRestoredUnreadIndicator(forTabId tabId: UUID) -> Bool {
restoredUnreadWorkspaceIds.contains(tabId)
}

@discardableResult
func restoreUnreadIndicator(forTabId tabId: UUID) -> Bool {
setWorkspaceRestoredUnread(true, forTabId: tabId)
}

@discardableResult
func clearRestoredUnreadIndicator(forTabId tabId: UUID) -> Bool {
setWorkspaceRestoredUnread(false, forTabId: tabId)
}

@discardableResult
func clearManualUnread(forTabId tabId: UUID) -> Bool {
setWorkspaceManualUnread(false, forTabId: tabId)
}

// Per-workspace badges treat manualUnreadWorkspaceIds as "has unread
// Per-workspace badges treat manual/restored workspace IDs as "has unread
// activity"; summing these counts can exceed indexes.unreadCount.
func unreadCount(forTabId tabId: UUID) -> Int {
(indexes.unreadCountByTabId[tabId] ?? 0) + (manualUnreadWorkspaceIds.contains(tabId) ? 1 : 0)
let hasWorkspaceUnreadIndicator = manualUnreadWorkspaceIds.contains(tabId) ||
restoredUnreadWorkspaceIds.contains(tabId)
return (indexes.unreadCountByTabId[tabId] ?? 0) + (hasWorkspaceUnreadIndicator ? 1 : 0)
}

func workspaceIsUnread(forTabId tabId: UUID) -> Bool {
Expand Down Expand Up @@ -1344,6 +1380,7 @@ final class TerminalNotificationStore: ObservableObject {
}
}
setWorkspaceManualUnread(false, forTabId: tabId)
setWorkspaceRestoredUnread(false, forTabId: tabId)
if !idsToClear.isEmpty {
notifications = updated
center.removeDeliveredNotificationsOffMain(withIdentifiers: idsToClear)
Expand All @@ -1361,6 +1398,9 @@ final class TerminalNotificationStore: ObservableObject {
idsToClear.append(updated[index].id.uuidString)
}
}
if surfaceId == nil {
setWorkspaceRestoredUnread(false, forTabId: tabId)
}
if !idsToClear.isEmpty {
notifications = updated
center.removeDeliveredNotificationsOffMain(withIdentifiers: idsToClear)
Expand All @@ -1370,6 +1410,7 @@ final class TerminalNotificationStore: ObservableObject {

func markUnread(forTabId tabId: UUID) {
setWorkspaceManualUnread(true, forTabId: tabId)
setWorkspaceRestoredUnread(false, forTabId: tabId)
}

@discardableResult
Expand Down Expand Up @@ -1430,6 +1471,7 @@ final class TerminalNotificationStore: ObservableObject {
}
}
clearWorkspaceManualUnread()
clearWorkspaceRestoredUnread()
if !idsToClear.isEmpty {
notifications = updated
center.removeDeliveredNotificationsOffMain(withIdentifiers: idsToClear)
Expand All @@ -1454,10 +1496,14 @@ final class TerminalNotificationStore: ObservableObject {

func clearAll(discardQueuedNotifications: Bool = true) {
if discardQueuedNotifications { TerminalMutationBus.shared.discardPendingNotifications() }
guard !notifications.isEmpty || !focusedReadIndicatorByTabId.isEmpty || !manualUnreadWorkspaceIds.isEmpty else { return }
guard !notifications.isEmpty ||
!focusedReadIndicatorByTabId.isEmpty ||
!manualUnreadWorkspaceIds.isEmpty ||
!restoredUnreadWorkspaceIds.isEmpty else { return }
let ids = notifications.map { $0.id.uuidString }
replaceNotificationsForClear([])
clearWorkspaceManualUnread()
clearWorkspaceRestoredUnread()
focusedReadIndicatorByTabId.removeAll()
CmuxEventBus.shared.publishNotificationCleared(ids: ids, workspaceId: nil, surfaceId: nil)
center.removeDeliveredNotificationsOffMain(withIdentifiers: ids)
Expand All @@ -1471,6 +1517,7 @@ final class TerminalNotificationStore: ObservableObject {
) {
if discardQueuedNotifications { TerminalMutationBus.shared.discardPendingNotifications(forTabId: tabId, surfaceId: surfaceId) }
let hadFocusedReadIndicator = focusedReadIndicatorByTabId[tabId].map { $0 == surfaceId } ?? false
let hadRestoredWorkspaceUnread = surfaceId == nil && restoredUnreadWorkspaceIds.contains(tabId)
var updated: [TerminalNotification] = []
updated.reserveCapacity(notifications.count)
var idsToClear: [String] = []
Expand All @@ -1481,10 +1528,13 @@ final class TerminalNotificationStore: ObservableObject {
updated.append(notification)
}
}
guard !idsToClear.isEmpty || hadFocusedReadIndicator else { return }
guard !idsToClear.isEmpty || hadFocusedReadIndicator || hadRestoredWorkspaceUnread else { return }
if !idsToClear.isEmpty {
replaceNotificationsForClear(updated)
}
if surfaceId == nil {
setWorkspaceRestoredUnread(false, forTabId: tabId)
}
clearFocusedReadIndicator(forTabId: tabId, surfaceId: surfaceId)
if !idsToClear.isEmpty {
CmuxEventBus.shared.publishNotificationCleared(ids: idsToClear, workspaceId: tabId, surfaceId: surfaceId)
Expand Down Expand Up @@ -1541,6 +1591,7 @@ final class TerminalNotificationStore: ObservableObject {
}
}
setWorkspaceManualUnread(false, forTabId: tabId)
setWorkspaceRestoredUnread(false, forTabId: tabId)
guard !idsToClear.isEmpty || hadFocusedReadIndicator else { return }
if !idsToClear.isEmpty {
replaceNotificationsForClear(updated)
Expand Down Expand Up @@ -1923,6 +1974,7 @@ final class TerminalNotificationStore: ObservableObject {
TerminalMutationBus.shared.discardPendingNotifications()
self.notifications = notifications
clearWorkspaceManualUnread()
clearWorkspaceRestoredUnread()
focusedReadIndicatorByTabId.removeAll()
}
#endif
Expand Down
2 changes: 2 additions & 0 deletions Sources/Workspace+DetachedSurfaceTransfer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ extension Workspace {
let cachedTitle: String?
let customTitle: String?
let manuallyUnread: Bool
let restoredUnread: Bool
let restorableAgent: SessionRestorableAgentSnapshot?
let restorableAgentResumeState: RestoredAgentResumeState?
let agentRuntime: DetachedAgentRuntimeState?
Expand All @@ -47,6 +48,7 @@ extension Workspace {
cachedTitle: cachedTitle,
customTitle: customTitle,
manuallyUnread: manuallyUnread,
restoredUnread: restoredUnread,
restorableAgent: restorableAgent,
restorableAgentResumeState: restorableAgentResumeState,
agentRuntime: agentRuntime,
Expand Down
Loading
Loading