@@ -20,6 +20,8 @@ struct ConnectionImportSheet: View {
2020 @State private var encryptedData : Data ?
2121 @State private var passphrase = " "
2222 @State private var passphraseError : String ?
23+ @State private var isDecrypting = false
24+ @State private var wasEncryptedImport = false
2325
2426 var body : some View {
2527 VStack ( spacing: 0 ) {
@@ -246,7 +248,7 @@ struct ConnectionImportSheet: View {
246248 Button ( String ( localized: " Decrypt " ) ) { decryptFile ( ) }
247249 . buttonStyle ( . borderedProminent)
248250 . keyboardShortcut ( . defaultAction)
249- . disabled ( passphrase. isEmpty)
251+ . disabled ( passphrase. isEmpty || isDecrypting )
250252 }
251253 . padding ( 12 )
252254 }
@@ -311,8 +313,9 @@ struct ConnectionImportSheet: View {
311313 }
312314
313315 private func decryptFile( ) {
314- guard let data = encryptedData else { return }
316+ guard let data = encryptedData, !isDecrypting else { return }
315317 let currentPassphrase = passphrase
318+ isDecrypting = true
316319
317320 Task . detached ( priority: . userInitiated) {
318321 do {
@@ -321,13 +324,16 @@ struct ConnectionImportSheet: View {
321324 await MainActor . run {
322325 passphraseError = nil
323326 encryptedData = nil
327+ wasEncryptedImport = true
324328 preview = result
325329 selectReadyItems ( result)
330+ isDecrypting = false
326331 }
327332 } catch {
328333 await MainActor . run {
329334 passphraseError = error. localizedDescription
330335 passphrase = " "
336+ isDecrypting = false
331337 }
332338 }
333339 }
@@ -361,8 +367,8 @@ struct ConnectionImportSheet: View {
361367
362368 let result = ConnectionExportService . performImport ( preview, resolutions: resolutions)
363369
364- // Restore credentials if this was an encrypted import
365- if let envelope = preview. envelope. credentials, !envelope . isEmpty {
370+ // Only restore credentials from verified encrypted imports (not plaintext files)
371+ if wasEncryptedImport , preview. envelope. credentials != nil {
366372 ConnectionExportService . restoreCredentials (
367373 from: preview. envelope,
368374 connectionIdMap: result. connectionIdMap
0 commit comments