Skip to content

Commit c974e79

Browse files
committed
Fix: add Cancel button to photo picker on macOS when Photos library is empty
When the Photos library is empty on macOS (Catalyst), PHPickerViewController renders no close/cancel button and ignores Esc/Cmd+Q, leaving the user unable to dismiss the picker without force-quitting the app (issue #507). Fix: after presenting the picker, inject a UIBarButtonItem(.cancel) into its navigationItem.leftBarButtonItem under #if targetEnvironment(macCatalyst). Tapping it dismisses the picker and calls the completion handler with nil, matching the existing behaviour for a cancelled pick. Fixes #507
1 parent 4dc000d commit c974e79

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

KeePassium/util/photo-picker/GalleryPhotoPicker.swift

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,29 @@ final class GalleryPhotoPicker: PhotoPicker {
2727
}
2828

2929
override internal func _pickImageInternal() {
30-
_presenter?.present(picker, animated: true, completion: nil)
30+
_presenter?.present(picker, animated: true) { [weak self] in
31+
#if targetEnvironment(macCatalyst)
32+
// On macOS, PHPickerViewController shows no close button when the Photos library is
33+
// empty, leaving the user with no way to dismiss it (issue #507).
34+
// Inject a Cancel button into the navigation bar as a reliable escape hatch.
35+
guard let self else { return }
36+
let cancelButton = UIBarButtonItem(
37+
barButtonSystemItem: .cancel,
38+
target: self,
39+
action: #selector(self.cancelPicker)
40+
)
41+
self.picker.navigationItem.leftBarButtonItem = cancelButton
42+
#endif
43+
}
44+
}
45+
46+
#if targetEnvironment(macCatalyst)
47+
@objc private func cancelPicker() {
48+
_presenter?.dismiss(animated: true) { [weak self] in
49+
self?._completion?(.success(nil))
50+
}
3151
}
52+
#endif
3253

3354
override class func isAllowed() -> Bool {
3455
#if INTUNE

0 commit comments

Comments
 (0)