Skip to content

Commit 585ab90

Browse files
authored
Merge pull request #281 from datlechin/refactor/remove-dead-notifications
refactor: remove 11 dead notifications and their observers
2 parents f442622 + 931bec7 commit 585ab90

12 files changed

Lines changed: 4 additions & 139 deletions

TablePro/ContentView.swift

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -69,25 +69,6 @@ struct ContentView: View {
6969
.onReceive(NotificationCenter.default.publisher(for: .newConnection)) { _ in
7070
openWindow(id: "connection-form", value: nil as UUID?)
7171
}
72-
.onReceive(NotificationCenter.default.publisher(for: .deselectConnection)) { _ in
73-
let sessionId = payload?.connectionId ?? DatabaseManager.shared.currentSessionId
74-
if let sessionId {
75-
Task { @MainActor in
76-
let window = NSApp.keyWindow
77-
let confirmed = await AlertHelper.confirmDestructive(
78-
title: String(localized: "Disconnect"),
79-
message: String(localized: "Are you sure you want to disconnect from this database?"),
80-
confirmButton: String(localized: "Disconnect"),
81-
cancelButton: String(localized: "Cancel"),
82-
window: window
83-
)
84-
85-
if confirmed {
86-
await DatabaseManager.shared.disconnectSession(sessionId)
87-
}
88-
}
89-
}
90-
}
9172
// Right sidebar toggle is handled by MainContentView (has the binding)
9273
// Left sidebar toggle uses native NSSplitViewController.toggleSidebar via responder chain
9374
.onChange(of: DatabaseManager.shared.currentSessionId, initial: true) { _, newSessionId in

TablePro/Core/Plugins/PluginManager.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,6 @@ final class PluginManager {
402402
}
403403

404404
Self.logger.info("Plugin '\(pluginId)' \(enabled ? "enabled" : "disabled")")
405-
NotificationCenter.default.post(name: .pluginStateDidChange, object: nil, userInfo: ["pluginId": pluginId])
406405
}
407406

408407
// MARK: - Install / Uninstall

TablePro/Core/Services/Infrastructure/AppNotifications.swift

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ import Foundation
1212
extension Notification.Name {
1313
// MARK: - Query Editor
1414

15-
static let formatQueryRequested = Notification.Name("formatQueryRequested")
16-
static let sendAIPrompt = Notification.Name("sendAIPrompt")
1715
static let aiFixError = Notification.Name("aiFixError")
1816
static let aiExplainSelection = Notification.Name("aiExplainSelection")
1917
static let aiOptimizeSelection = Notification.Name("aiOptimizeSelection")
@@ -28,14 +26,9 @@ extension Notification.Name {
2826

2927
static let connectionUpdated = Notification.Name("connectionUpdated")
3028
static let databaseDidConnect = Notification.Name("databaseDidConnect")
31-
static let connectionHealthStateChanged = Notification.Name("connectionHealthStateChanged")
3229

3330
// MARK: - SSH
3431

3532
static let sshTunnelDied = Notification.Name("sshTunnelDied")
3633
static let lastWindowDidClose = Notification.Name("lastWindowDidClose")
37-
38-
// MARK: - Plugins
39-
40-
static let pluginStateDidChange = Notification.Name("pluginStateDidChange")
4134
}

TablePro/Core/Services/Licensing/LicenseManager.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ final class LicenseManager {
143143
license = newLicense
144144
evaluateStatus()
145145

146-
NotificationCenter.default.post(name: .licenseStatusDidChange, object: nil)
147146
Self.logger.info("License activated for \(payloadData.email)")
148147
} catch let error as LicenseError {
149148
lastError = error
@@ -187,7 +186,6 @@ final class LicenseManager {
187186
revalidationTask?.cancel()
188187
revalidationTask = nil
189188

190-
NotificationCenter.default.post(name: .licenseStatusDidChange, object: nil)
191189
Self.logger.info("License deactivated")
192190
}
193191

@@ -232,8 +230,6 @@ final class LicenseManager {
232230
}
233231
// Otherwise keep using cached license (still within grace period)
234232
}
235-
236-
NotificationCenter.default.post(name: .licenseStatusDidChange, object: nil)
237233
}
238234

239235
// MARK: - Status Evaluation

TablePro/TableProApp.swift

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -449,13 +449,10 @@ struct TableProApp: App {
449449
extension Notification.Name {
450450
// Connection lifecycle
451451
static let newConnection = Notification.Name("newConnection")
452-
static let deselectConnection = Notification.Name("deselectConnection")
453452
static let openConnectionSwitcher = Notification.Name("openConnectionSwitcher")
454-
static let reconnectDatabase = Notification.Name("reconnectDatabase")
455453

456454
// Multi-listener broadcasts (Sidebar + Coordinator + StructureView)
457455
static let refreshData = Notification.Name("refreshData")
458-
static let refreshAll = Notification.Name("refreshAll")
459456

460457
// Data operations (still posted by DataGrid / context menus / StructureView subscribers)
461458
static let deleteSelectedRows = Notification.Name("deleteSelectedRows")
@@ -486,11 +483,6 @@ extension Notification.Name {
486483
static let showTableStructure = Notification.Name("showTableStructure")
487484
static let editViewDefinition = Notification.Name("editViewDefinition")
488485

489-
// Filter notifications
490-
static let applyAllFilters = Notification.Name("applyAllFilters")
491-
static let duplicateFilter = Notification.Name("duplicateFilter")
492-
static let removeFilter = Notification.Name("removeFilter")
493-
494486
// File opening notifications
495487
static let openSQLFiles = Notification.Name("openSQLFiles")
496488

@@ -502,9 +494,6 @@ extension Notification.Name {
502494
// Database URL handling notifications
503495
static let switchSchemaFromURL = Notification.Name("switchSchemaFromURL")
504496
static let applyURLFilter = Notification.Name("applyURLFilter")
505-
506-
// License notifications
507-
static let licenseStatusDidChange = Notification.Name("licenseStatusDidChange")
508497
}
509498

510499
// MARK: - Check for Updates

TablePro/ViewModels/SidebarViewModel.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,9 @@ final class SidebarViewModel {
152152
guard !hasSetupNotifications else { return }
153153
hasSetupNotifications = true
154154

155-
Publishers.Merge3(
155+
Publishers.Merge(
156156
NotificationCenter.default.publisher(for: .databaseDidConnect),
157-
NotificationCenter.default.publisher(for: .refreshData),
158-
NotificationCenter.default.publisher(for: .refreshAll)
157+
NotificationCenter.default.publisher(for: .refreshData)
159158
)
160159
.receive(on: DispatchQueue.main)
161160
.sink { [weak self] _ in

TablePro/Views/AIChat/AIChatPanelView.swift

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,6 @@ struct AIChatPanelView: View {
6969
.task(id: tables) {
7070
await fetchSchemaContext()
7171
}
72-
.onReceive(NotificationCenter.default.publisher(for: .sendAIPrompt)) { notification in
73-
guard let userInfo = notification.userInfo,
74-
let prompt = userInfo["prompt"] as? String,
75-
let featureRaw = userInfo["feature"] as? String,
76-
let feature = AIFeature(rawValue: featureRaw) else { return }
77-
updateContext()
78-
viewModel.sendWithContext(prompt: prompt, feature: feature)
79-
}
8072
.onReceive(NotificationCenter.default.publisher(for: .aiFixError)) { notification in
8173
guard let userInfo = notification.userInfo,
8274
let query = userInfo["query"] as? String,

TablePro/Views/Editor/QueryEditorView.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@ struct QueryEditorView: View {
5050
.clipped()
5151
}
5252
.background(Color(nsColor: .textBackgroundColor))
53-
.onReceive(NotificationCenter.default.publisher(for: .formatQueryRequested)) { _ in
54-
formatQuery()
55-
}
5653
.onReceive(NotificationCenter.default.publisher(for: .editorSettingsDidChange)) { _ in
5754
isVimEnabled = AppSettingsManager.shared.editor.vimModeEnabled
5855
}

TablePro/Views/Main/Extensions/MainContentCoordinator+Alerts.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ extension MainContentCoordinator {
9595
/// Generate appropriate message for discard action type
9696
private func discardMessage(for action: DiscardAction) -> String {
9797
switch action {
98-
case .refresh, .refreshAll:
98+
case .refresh:
9999
return String(localized: "Refreshing will discard all unsaved changes.")
100100
}
101101
}

TablePro/Views/Main/Extensions/MainContentCoordinator+Refresh.swift

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,35 +11,6 @@ import Foundation
1111
extension MainContentCoordinator {
1212
// MARK: - Refresh Handling
1313

14-
func handleRefreshAll(
15-
hasPendingTableOps: Bool,
16-
onDiscard: @escaping () -> Void
17-
) {
18-
// If showing structure view, let it handle refresh notifications
19-
if let tabIndex = tabManager.selectedTabIndex,
20-
tabManager.tabs[tabIndex].showStructure {
21-
return
22-
}
23-
24-
let hasEditedCells = changeManager.hasChanges
25-
26-
if hasEditedCells || hasPendingTableOps {
27-
Task { @MainActor in
28-
let window = NSApp.keyWindow
29-
let confirmed = await confirmDiscardChanges(action: .refreshAll, window: window)
30-
if confirmed {
31-
onDiscard()
32-
changeManager.clearChanges()
33-
NotificationCenter.default.post(name: .databaseDidConnect, object: nil)
34-
runQuery()
35-
}
36-
}
37-
} else {
38-
NotificationCenter.default.post(name: .databaseDidConnect, object: nil)
39-
runQuery()
40-
}
41-
}
42-
4314
func handleRefresh(
4415
hasPendingTableOps: Bool,
4516
onDiscard: @escaping () -> Void

0 commit comments

Comments
 (0)