Skip to content

Commit fcd6039

Browse files
committed
fix: address CodeRabbit review comments
- Use consistent user-facing identifier in pluginNotLoaded error - Add explicit internal access to EmptyDialect - Replace DispatchQueue.main.async with MainActor.run in HostKeyVerifier - Log settings decode errors instead of silently swallowing with try?
1 parent a8fd4e2 commit fcd6039

File tree

4 files changed

+44
-63
lines changed

4 files changed

+44
-63
lines changed

TablePro/Core/Database/DatabaseDriver.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ enum DatabaseDriverFactory {
321321
// If background loading hasn't finished yet, throw a specific error
322322
// instead of blocking the main thread with synchronous plugin loading.
323323
if !PluginManager.shared.hasFinishedInitialLoad {
324-
throw PluginError.pluginNotLoaded(pluginId)
324+
throw PluginError.pluginNotLoaded(connection.type.rawValue)
325325
}
326326
if connection.type.isDownloadablePlugin {
327327
throw PluginError.pluginNotInstalled(connection.type.rawValue)

TablePro/Core/SSH/HostKeyVerifier.swift

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -101,18 +101,16 @@ internal enum HostKeyVerifier {
101101
Are you sure you want to continue connecting?
102102
""")
103103

104-
return await withCheckedContinuation { continuation in
105-
DispatchQueue.main.async {
106-
let alert = NSAlert()
107-
alert.messageText = title
108-
alert.informativeText = message
109-
alert.alertStyle = .informational
110-
alert.addButton(withTitle: String(localized: "Trust"))
111-
alert.addButton(withTitle: String(localized: "Cancel"))
112-
113-
let response = alert.runModal()
114-
continuation.resume(returning: response == .alertFirstButtonReturn)
115-
}
104+
return await MainActor.run {
105+
let alert = NSAlert()
106+
alert.messageText = title
107+
alert.informativeText = message
108+
alert.alertStyle = .informational
109+
alert.addButton(withTitle: String(localized: "Trust"))
110+
alert.addButton(withTitle: String(localized: "Cancel"))
111+
112+
let response = alert.runModal()
113+
return response == .alertFirstButtonReturn
116114
}
117115
}
118116

@@ -135,22 +133,20 @@ internal enum HostKeyVerifier {
135133
Current fingerprint: \(actual)
136134
""")
137135

138-
return await withCheckedContinuation { continuation in
139-
DispatchQueue.main.async {
140-
let alert = NSAlert()
141-
alert.messageText = title
142-
alert.informativeText = message
143-
alert.alertStyle = .critical
144-
alert.addButton(withTitle: String(localized: "Connect Anyway"))
145-
alert.addButton(withTitle: String(localized: "Disconnect"))
146-
147-
// Make "Disconnect" the default button (Return key) instead of "Connect Anyway"
148-
alert.buttons[1].keyEquivalent = "\r"
149-
alert.buttons[0].keyEquivalent = ""
150-
151-
let response = alert.runModal()
152-
continuation.resume(returning: response == .alertFirstButtonReturn)
153-
}
136+
return await MainActor.run {
137+
let alert = NSAlert()
138+
alert.messageText = title
139+
alert.informativeText = message
140+
alert.alertStyle = .critical
141+
alert.addButton(withTitle: String(localized: "Connect Anyway"))
142+
alert.addButton(withTitle: String(localized: "Disconnect"))
143+
144+
// Make "Disconnect" the default button (Return key) instead of "Connect Anyway"
145+
alert.buttons[1].keyEquivalent = "\r"
146+
alert.buttons[0].keyEquivalent = ""
147+
148+
let response = alert.runModal()
149+
return response == .alertFirstButtonReturn
154150
}
155151
}
156152
}

TablePro/Core/Services/Query/SQLDialectProvider.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ struct PluginDialectAdapter: SQLDialectProvider {
2828

2929
/// Fallback dialect with no keywords/functions. Internal visibility so SQLFormatterService
3030
/// can use it as a fallback when resolving dialects off the main thread.
31-
struct EmptyDialect: SQLDialectProvider {
31+
internal struct EmptyDialect: SQLDialectProvider {
3232
let identifierQuote = "\""
3333
let keywords: Set<String> = []
3434
let functions: Set<String> = []

TablePro/Core/Sync/SyncCoordinator.swift

Lines changed: 18 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -565,40 +565,25 @@ final class SyncCoordinator {
565565
let data = SyncRecordMapper.settingsData(from: record)
566566
else { return }
567567

568-
let decoder = JSONDecoder()
569-
switch category {
570-
case "general":
571-
if let settings = try? decoder.decode(GeneralSettings.self, from: data) {
572-
AppSettingsStorage.shared.saveGeneral(settings)
573-
}
574-
case "appearance":
575-
if let settings = try? decoder.decode(AppearanceSettings.self, from: data) {
576-
AppSettingsStorage.shared.saveAppearance(settings)
577-
}
578-
case "editor":
579-
if let settings = try? decoder.decode(EditorSettings.self, from: data) {
580-
AppSettingsStorage.shared.saveEditor(settings)
581-
}
582-
case "dataGrid":
583-
if let settings = try? decoder.decode(DataGridSettings.self, from: data) {
584-
AppSettingsStorage.shared.saveDataGrid(settings)
585-
}
586-
case "history":
587-
if let settings = try? decoder.decode(HistorySettings.self, from: data) {
588-
AppSettingsStorage.shared.saveHistory(settings)
589-
}
590-
case "tabs":
591-
if let settings = try? decoder.decode(TabSettings.self, from: data) {
592-
AppSettingsStorage.shared.saveTabs(settings)
593-
}
594-
case "keyboard":
595-
if let settings = try? decoder.decode(KeyboardSettings.self, from: data) {
596-
AppSettingsStorage.shared.saveKeyboard(settings)
597-
}
598-
case "ai":
599-
if let settings = try? decoder.decode(AISettings.self, from: data) {
600-
AppSettingsStorage.shared.saveAI(settings)
568+
func decode<T: Decodable>(_ type: T.Type, save: (T) -> Void) {
569+
do {
570+
let settings = try JSONDecoder().decode(type, from: data)
571+
save(settings)
572+
} catch {
573+
logger.debug("Failed to decode remote settings '\(category)': \(error.localizedDescription)")
601574
}
575+
}
576+
577+
let storage = AppSettingsStorage.shared
578+
switch category {
579+
case "general": decode(GeneralSettings.self, save: storage.saveGeneral)
580+
case "appearance": decode(AppearanceSettings.self, save: storage.saveAppearance)
581+
case "editor": decode(EditorSettings.self, save: storage.saveEditor)
582+
case "dataGrid": decode(DataGridSettings.self, save: storage.saveDataGrid)
583+
case "history": decode(HistorySettings.self, save: storage.saveHistory)
584+
case "tabs": decode(TabSettings.self, save: storage.saveTabs)
585+
case "keyboard": decode(KeyboardSettings.self, save: storage.saveKeyboard)
586+
case "ai": decode(AISettings.self, save: storage.saveAI)
602587
default:
603588
break
604589
}

0 commit comments

Comments
 (0)