Skip to content

Commit 8191b29

Browse files
author
Iakov Senatov
committed
fix: encrypted archive alert offers Open with App via NSWorkspace
- Encrypted: "Open with App" / "Cancel" — opens archive in system app - Other errors: plain "OK" alert with error description
1 parent 7cd0a83 commit 8191b29

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

GUI/Sources/States/AppState/AppState.swift

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ extension AppState {
409409
log.info("[AppState] Successfully entered archive: \(archiveURL.lastPathComponent)")
410410
} catch {
411411
log.error("[AppState] Failed to enter archive: \(error.localizedDescription)")
412-
await showArchiveErrorAlert(archiveName: archiveURL.lastPathComponent, error: error)
412+
await showArchiveErrorAlert(archiveName: archiveURL.lastPathComponent, archiveURL: archiveURL, error: error)
413413
}
414414
}
415415

@@ -459,20 +459,26 @@ extension AppState {
459459

460460
/// Shows NSAlert when archive open fails (encrypted, corrupted, etc.)
461461
@MainActor
462-
private func showArchiveErrorAlert(archiveName: String, error: Error) async {
462+
private func showArchiveErrorAlert(archiveName: String, archiveURL: URL, error: Error) async {
463463
let desc = error.localizedDescription
464464
let isEncrypted = desc.lowercased().contains("password") || desc.lowercased().contains("encrypted")
465465
let alert = NSAlert()
466466
alert.alertStyle = .critical
467467
if isEncrypted {
468468
alert.messageText = "Encrypted Archive"
469-
alert.informativeText = "\"\(archiveName)\" is password-protected.\n\nPassword-protected archives cannot be opened yet."
469+
alert.informativeText = "\"\(archiveName)\" is password-protected and cannot be browsed inline.\n\nOpen with a system application instead?"
470+
alert.addButton(withTitle: "Open with App")
471+
alert.addButton(withTitle: "Cancel")
472+
let response = alert.runModal()
473+
if response == .alertFirstButtonReturn {
474+
NSWorkspace.shared.open(archiveURL)
475+
}
470476
} else {
471477
alert.messageText = "Cannot Open Archive"
472478
alert.informativeText = "\"\(archiveName)\" could not be opened.\n\n\(desc)"
479+
alert.addButton(withTitle: "OK")
480+
alert.runModal()
473481
}
474-
alert.addButton(withTitle: "OK")
475-
alert.runModal()
476482
}
477483

478484
/// Shows NSAlert asking user whether to repack the modified archive.

0 commit comments

Comments
 (0)