|
|
@ -38,6 +38,14 @@ struct SaveFileDialogOptions: Decodable {
|
|
|
|
var defaultPath: String?
|
|
|
|
var defaultPath: String?
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct FolderPickerOptions: Decodable {
|
|
|
|
|
|
|
|
var title: String?
|
|
|
|
|
|
|
|
var defaultPath: String?
|
|
|
|
|
|
|
|
var multiple: Bool?
|
|
|
|
|
|
|
|
var recursive: Bool?
|
|
|
|
|
|
|
|
var canCreateDirectories: Bool?
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class DialogPlugin: Plugin {
|
|
|
|
class DialogPlugin: Plugin {
|
|
|
|
|
|
|
|
|
|
|
|
var filePickerController: FilePickerController!
|
|
|
|
var filePickerController: FilePickerController!
|
|
|
@ -168,6 +176,47 @@ class DialogPlugin: Plugin {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@objc public func showFolderPicker(_ invoke: Invoke) throws {
|
|
|
|
|
|
|
|
let args = try invoke.parseArgs(FolderPickerOptions.self)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
onFilePickerResult = { (event: FilePickerEvent) -> Void in
|
|
|
|
|
|
|
|
switch event {
|
|
|
|
|
|
|
|
case .selected(let urls):
|
|
|
|
|
|
|
|
invoke.resolve(["directories": urls])
|
|
|
|
|
|
|
|
case .cancelled:
|
|
|
|
|
|
|
|
invoke.resolve(["directories": nil])
|
|
|
|
|
|
|
|
case .error(let error):
|
|
|
|
|
|
|
|
invoke.reject(error)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DispatchQueue.main.async {
|
|
|
|
|
|
|
|
let picker: UIDocumentPickerViewController
|
|
|
|
|
|
|
|
if #available(iOS 14.0, *) {
|
|
|
|
|
|
|
|
picker = UIDocumentPickerViewController(forOpeningContentTypes: [.folder])
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
picker = UIDocumentPickerViewController(documentTypes: [kUTTypeFolder as String], in: .open)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if let title = args.title {
|
|
|
|
|
|
|
|
picker.title = title
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if let defaultPath = args.defaultPath {
|
|
|
|
|
|
|
|
picker.directoryURL = URL(string: defaultPath)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
picker.delegate = self.filePickerController
|
|
|
|
|
|
|
|
picker.allowsMultipleSelection = args.multiple ?? false
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Note: canCreateDirectories is only supported on macOS
|
|
|
|
|
|
|
|
// recursive is handled at the filesystem access level, not in the picker
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
picker.modalPresentationStyle = .fullScreen
|
|
|
|
|
|
|
|
self.presentViewController(picker)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private func presentViewController(_ viewControllerToPresent: UIViewController) {
|
|
|
|
private func presentViewController(_ viewControllerToPresent: UIViewController) {
|
|
|
|
self.manager.viewController?.present(viewControllerToPresent, animated: true, completion: nil)
|
|
|
|
self.manager.viewController?.present(viewControllerToPresent, animated: true, completion: nil)
|
|
|
|
}
|
|
|
|
}
|
|
|
|