mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-09-24 21:40:48 +02:00
fix(ios): decoding with default value is not supported (#1236)
This commit is contained in:
@@ -0,0 +1,7 @@
|
|||||||
|
---
|
||||||
|
"notification": patch
|
||||||
|
"barcode-scanner": patch
|
||||||
|
"dialog": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fixes command argument parsing on iOS.
|
||||||
@@ -8,7 +8,7 @@ import UIKit
|
|||||||
import WebKit
|
import WebKit
|
||||||
|
|
||||||
struct ScanOptions: Decodable {
|
struct ScanOptions: Decodable {
|
||||||
var formats: [SupportedFormat] = []
|
var formats: [SupportedFormat]?
|
||||||
let windowed: Bool?
|
let windowed: Bool?
|
||||||
let cameraDirection: String?
|
let cameraDirection: String?
|
||||||
}
|
}
|
||||||
@@ -241,7 +241,7 @@ class BarcodeScannerPlugin: Plugin, AVCaptureMetadataOutputObjectsDelegate {
|
|||||||
private func runScanner(_ invoke: Invoke, args: ScanOptions) {
|
private func runScanner(_ invoke: Invoke, args: ScanOptions) {
|
||||||
scanFormats = [AVMetadataObject.ObjectType]()
|
scanFormats = [AVMetadataObject.ObjectType]()
|
||||||
|
|
||||||
args.formats.forEach { format in
|
(args.formats ?? []).forEach { format in
|
||||||
scanFormats.append(format.value)
|
scanFormats.append(format.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,18 +19,18 @@ enum FilePickerEvent {
|
|||||||
struct MessageDialogOptions: Decodable {
|
struct MessageDialogOptions: Decodable {
|
||||||
let title: String?
|
let title: String?
|
||||||
let message: String
|
let message: String
|
||||||
var okButtonLabel = "OK"
|
let okButtonLabel: String?
|
||||||
var cancelButtonLabel = "Cancel"
|
let cancelButtonLabel: String?
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Filter: Decodable {
|
struct Filter: Decodable {
|
||||||
var extensions: [String] = []
|
var extensions: [String]?
|
||||||
}
|
}
|
||||||
|
|
||||||
struct FilePickerOptions: Decodable {
|
struct FilePickerOptions: Decodable {
|
||||||
var multiple = false
|
var multiple: Bool?
|
||||||
var readData = false
|
var readData: Bool?
|
||||||
var filters: [Filter] = []
|
var filters: [Filter]?
|
||||||
}
|
}
|
||||||
|
|
||||||
class DialogPlugin: Plugin {
|
class DialogPlugin: Plugin {
|
||||||
@@ -47,7 +47,7 @@ class DialogPlugin: Plugin {
|
|||||||
@objc public func showFilePicker(_ invoke: Invoke) throws {
|
@objc public func showFilePicker(_ invoke: Invoke) throws {
|
||||||
let args = try invoke.parseArgs(FilePickerOptions.self)
|
let args = try invoke.parseArgs(FilePickerOptions.self)
|
||||||
|
|
||||||
let parsedTypes = parseFiltersOption(args.filters)
|
let parsedTypes = parseFiltersOption(args.filters ?? [])
|
||||||
|
|
||||||
var isMedia = true
|
var isMedia = true
|
||||||
var uniqueMimeType: Bool? = nil
|
var uniqueMimeType: Bool? = nil
|
||||||
@@ -74,7 +74,7 @@ class DialogPlugin: Plugin {
|
|||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
if #available(iOS 14, *) {
|
if #available(iOS 14, *) {
|
||||||
var configuration = PHPickerConfiguration(photoLibrary: PHPhotoLibrary.shared())
|
var configuration = PHPickerConfiguration(photoLibrary: PHPhotoLibrary.shared())
|
||||||
configuration.selectionLimit = args.multiple ? 0 : 1
|
configuration.selectionLimit = (args.multiple ?? false) ? 0 : 1
|
||||||
|
|
||||||
if uniqueMimeType == true {
|
if uniqueMimeType == true {
|
||||||
if mimeKind == "image" {
|
if mimeKind == "image" {
|
||||||
@@ -106,7 +106,7 @@ class DialogPlugin: Plugin {
|
|||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
let picker = UIDocumentPickerViewController(documentTypes: documentTypes, in: .import)
|
let picker = UIDocumentPickerViewController(documentTypes: documentTypes, in: .import)
|
||||||
picker.delegate = self.filePickerController
|
picker.delegate = self.filePickerController
|
||||||
picker.allowsMultipleSelection = args.multiple
|
picker.allowsMultipleSelection = args.multiple ?? false
|
||||||
picker.modalPresentationStyle = .fullScreen
|
picker.modalPresentationStyle = .fullScreen
|
||||||
self.presentViewController(picker)
|
self.presentViewController(picker)
|
||||||
}
|
}
|
||||||
@@ -120,7 +120,7 @@ class DialogPlugin: Plugin {
|
|||||||
private func parseFiltersOption(_ filters: [Filter]) -> [String] {
|
private func parseFiltersOption(_ filters: [Filter]) -> [String] {
|
||||||
var parsedTypes: [String] = []
|
var parsedTypes: [String] = []
|
||||||
for filter in filters {
|
for filter in filters {
|
||||||
for ext in filter.extensions {
|
for ext in filter.extensions ?? [] {
|
||||||
guard
|
guard
|
||||||
let utType: String = UTTypeCreatePreferredIdentifierForTag(
|
let utType: String = UTTypeCreatePreferredIdentifierForTag(
|
||||||
kUTTagClassMIMEType, ext as CFString, nil)?.takeRetainedValue() as String?
|
kUTTagClassMIMEType, ext as CFString, nil)?.takeRetainedValue() as String?
|
||||||
@@ -197,24 +197,36 @@ class DialogPlugin: Plugin {
|
|||||||
DispatchQueue.main.async { [] in
|
DispatchQueue.main.async { [] in
|
||||||
let alert = UIAlertController(
|
let alert = UIAlertController(
|
||||||
title: args.title, message: args.message, preferredStyle: UIAlertController.Style.alert)
|
title: args.title, message: args.message, preferredStyle: UIAlertController.Style.alert)
|
||||||
alert.addAction(
|
|
||||||
UIAlertAction(
|
let cancelButtonLabel = args.cancelButtonLabel ?? ""
|
||||||
title: args.cancelButtonLabel, style: UIAlertAction.Style.default,
|
if !cancelButtonLabel.isEmpty {
|
||||||
handler: { (_) -> Void in
|
alert.addAction(
|
||||||
invoke.resolve([
|
UIAlertAction(
|
||||||
"value": false,
|
title: cancelButtonLabel, style: UIAlertAction.Style.default,
|
||||||
"cancelled": false,
|
handler: { (_) -> Void in
|
||||||
])
|
Logger.error("cancel")
|
||||||
}))
|
|
||||||
alert.addAction(
|
invoke.resolve([
|
||||||
UIAlertAction(
|
"value": false,
|
||||||
title: args.okButtonLabel, style: UIAlertAction.Style.default,
|
"cancelled": false,
|
||||||
handler: { (_) -> Void in
|
])
|
||||||
invoke.resolve([
|
}))
|
||||||
"value": true,
|
}
|
||||||
"cancelled": false,
|
|
||||||
])
|
let okButtonLabel = args.okButtonLabel ?? (cancelButtonLabel.isEmpty ? "OK" : "")
|
||||||
}))
|
if !okButtonLabel.isEmpty {
|
||||||
|
alert.addAction(
|
||||||
|
UIAlertAction(
|
||||||
|
title: okButtonLabel, style: UIAlertAction.Style.default,
|
||||||
|
handler: { (_) -> Void in
|
||||||
|
Logger.error("ok")
|
||||||
|
|
||||||
|
invoke.resolve([
|
||||||
|
"value": true,
|
||||||
|
"cancelled": false,
|
||||||
|
])
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
manager.viewController?.present(alert, animated: true, completion: nil)
|
manager.viewController?.present(alert, animated: true, completion: nil)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ func makeActions(_ actions: [Action]) -> [UNNotificationAction] {
|
|||||||
|
|
||||||
for action in actions {
|
for action in actions {
|
||||||
var newAction: UNNotificationAction
|
var newAction: UNNotificationAction
|
||||||
if action.input {
|
if action.input ?? false {
|
||||||
if action.inputButtonTitle != nil {
|
if action.inputButtonTitle != nil {
|
||||||
newAction = UNTextInputNotificationAction(
|
newAction = UNTextInputNotificationAction(
|
||||||
identifier: action.id,
|
identifier: action.id,
|
||||||
@@ -66,30 +66,30 @@ func makeActions(_ actions: [Action]) -> [UNNotificationAction] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func makeActionOptions(_ action: Action) -> UNNotificationActionOptions {
|
func makeActionOptions(_ action: Action) -> UNNotificationActionOptions {
|
||||||
if action.foreground {
|
if action.foreground ?? false {
|
||||||
return .foreground
|
return .foreground
|
||||||
}
|
}
|
||||||
if action.destructive {
|
if action.destructive ?? false {
|
||||||
return .destructive
|
return .destructive
|
||||||
}
|
}
|
||||||
if action.requiresAuthentication {
|
if action.requiresAuthentication ?? false {
|
||||||
return .authenticationRequired
|
return .authenticationRequired
|
||||||
}
|
}
|
||||||
return UNNotificationActionOptions(rawValue: 0)
|
return UNNotificationActionOptions(rawValue: 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeCategoryOptions(_ type: ActionType) -> UNNotificationCategoryOptions {
|
func makeCategoryOptions(_ type: ActionType) -> UNNotificationCategoryOptions {
|
||||||
if type.customDismissAction {
|
if type.customDismissAction ?? false {
|
||||||
return .customDismissAction
|
return .customDismissAction
|
||||||
}
|
}
|
||||||
if type.allowInCarPlay {
|
if type.allowInCarPlay ?? false {
|
||||||
return .allowInCarPlay
|
return .allowInCarPlay
|
||||||
}
|
}
|
||||||
|
|
||||||
if type.hiddenPreviewsShowTitle {
|
if type.hiddenPreviewsShowTitle ?? false {
|
||||||
return .hiddenPreviewsShowTitle
|
return .hiddenPreviewsShowTitle
|
||||||
}
|
}
|
||||||
if type.hiddenPreviewsShowSubtitle {
|
if type.hiddenPreviewsShowSubtitle ?? false {
|
||||||
return .hiddenPreviewsShowSubtitle
|
return .hiddenPreviewsShowSubtitle
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -64,9 +64,9 @@ struct NotificationAttachment: Codable {
|
|||||||
|
|
||||||
struct Notification: Decodable {
|
struct Notification: Decodable {
|
||||||
let id: Int
|
let id: Int
|
||||||
var title: String = ""
|
var title: String
|
||||||
var body: String = ""
|
var body: String
|
||||||
var extra: [String: String] = [:]
|
var extra: [String: String]?
|
||||||
let schedule: NotificationSchedule?
|
let schedule: NotificationSchedule?
|
||||||
let attachments: [NotificationAttachment]?
|
let attachments: [NotificationAttachment]?
|
||||||
let sound: String?
|
let sound: String?
|
||||||
@@ -126,10 +126,10 @@ struct CancelArgs: Decodable {
|
|||||||
struct Action: Decodable {
|
struct Action: Decodable {
|
||||||
let id: String
|
let id: String
|
||||||
let title: String
|
let title: String
|
||||||
var requiresAuthentication: Bool = false
|
var requiresAuthentication: Bool?
|
||||||
var foreground: Bool = false
|
var foreground: Bool?
|
||||||
var destructive: Bool = false
|
var destructive: Bool?
|
||||||
var input: Bool = false
|
var input: Bool?
|
||||||
let inputButtonTitle: String?
|
let inputButtonTitle: String?
|
||||||
let inputPlaceholder: String?
|
let inputPlaceholder: String?
|
||||||
}
|
}
|
||||||
@@ -138,10 +138,10 @@ struct ActionType: Decodable {
|
|||||||
let id: String
|
let id: String
|
||||||
let actions: [Action]
|
let actions: [Action]
|
||||||
let hiddenPreviewsBodyPlaceholder: String?
|
let hiddenPreviewsBodyPlaceholder: String?
|
||||||
var customDismissAction = false
|
var customDismissAction: Bool?
|
||||||
var allowInCarPlay = false
|
var allowInCarPlay: Bool?
|
||||||
var hiddenPreviewsShowTitle = false
|
var hiddenPreviewsShowTitle: Bool?
|
||||||
var hiddenPreviewsShowSubtitle = false
|
var hiddenPreviewsShowSubtitle: Bool?
|
||||||
let hiddenBodyPlaceholder: String?
|
let hiddenBodyPlaceholder: String?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user