Skip to content

Commit 869baec

Browse files
committed
fix: address code review findings from PR #473
1 parent 07aa957 commit 869baec

4 files changed

Lines changed: 22 additions & 16 deletions

File tree

TablePro/AppDelegate+FileOpen.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,8 @@ extension AppDelegate {
210210

211211
private func handleConnectionShareFile(_ url: URL) {
212212
openWelcomeWindow()
213-
// Delay to ensure WelcomeWindowView's .onReceive is registered after window appears
214-
DispatchQueue.main.async {
213+
// Delay to ensure WelcomeWindowView's .onReceive is registered after window renders
214+
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
215215
NotificationCenter.default.post(name: .connectionShareFileOpened, object: url)
216216
}
217217
}

TablePro/Core/Services/Export/ConnectionExportService.swift

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -155,16 +155,20 @@ enum ConnectionExportService {
155155
let aiPolicy: String? = connection.aiPolicy?.rawValue
156156

157157
// Filter secure fields from additionalFields
158-
var filteredFields = connection.additionalFields
159-
let secureFieldIds = PluginMetadataRegistry.shared
160-
.snapshot(forTypeId: connection.type.pluginTypeId)?
161-
.connection.additionalConnectionFields
162-
.filter(\.isSecure)
163-
.map(\.id) ?? []
164-
for fieldId in secureFieldIds {
165-
filteredFields.removeValue(forKey: fieldId)
158+
// If plugin metadata is unavailable, omit all fields to avoid leaking secrets
159+
let additionalFields: [String: String]?
160+
if let snapshot = PluginMetadataRegistry.shared.snapshot(forTypeId: connection.type.pluginTypeId) {
161+
var filteredFields = connection.additionalFields
162+
let secureFieldIds = snapshot.connection.additionalConnectionFields
163+
.filter(\.isSecure)
164+
.map(\.id)
165+
for fieldId in secureFieldIds {
166+
filteredFields.removeValue(forKey: fieldId)
167+
}
168+
additionalFields = filteredFields.isEmpty ? nil : filteredFields
169+
} else {
170+
additionalFields = nil
166171
}
167-
let additionalFields: [String: String]? = filteredFields.isEmpty ? nil : filteredFields
168172

169173
let exportable = ExportableConnection(
170174
name: connection.name,
@@ -222,10 +226,12 @@ enum ConnectionExportService {
222226
encoder.outputFormatting = [.prettyPrinted, .sortedKeys]
223227
encoder.dateEncodingStrategy = .iso8601
224228

225-
guard let data = try? encoder.encode(envelope) else {
229+
do {
230+
return try encoder.encode(envelope)
231+
} catch {
232+
logger.error("Encoding failed: \(error)")
226233
throw ConnectionExportError.encodingFailed
227234
}
228-
return data
229235
}
230236

231237
static func exportConnections(_ connections: [DatabaseConnection], to url: URL) throws {

TablePro/TableProApp.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,11 +239,11 @@ struct AppMenuCommands: Commands {
239239

240240
Divider()
241241

242-
Button("Export Connections...") {
242+
Button(String(localized: "Export Connections...")) {
243243
NotificationCenter.default.post(name: .exportConnections, object: nil)
244244
}
245245

246-
Button("Import Connections...") {
246+
Button(String(localized: "Import Connections...")) {
247247
NotificationCenter.default.post(name: .importConnections, object: nil)
248248
}
249249

TablePro/Views/Connection/WelcomeWindowView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ struct WelcomeWindowView: View {
518518
let envelope = ConnectionExportService.buildEnvelope(for: [connection])
519519
let data = try ConnectionExportService.encode(envelope)
520520
let tempURL = FileManager.default.temporaryDirectory
521-
.appendingPathComponent("\(connection.name).tablepro")
521+
.appendingPathComponent("\(connection.name)-\(connection.id.uuidString).tablepro")
522522
try data.write(to: tempURL, options: .atomic)
523523
completion(tempURL, true, nil)
524524
} catch {

0 commit comments

Comments
 (0)