mirror of
https://github.com/home-assistant/iOS.git
synced 2026-04-17 08:05:44 -05:00
<!-- Thank you for submitting a Pull Request and helping to improve Home Assistant. Please complete the following sections to help the processing and review of your changes. Please do not delete anything from this template. --> ## Summary <!-- Provide a brief summary of the changes you have made and most importantly what they aim to achieve --> This PR removes the `options` parameters which use the default value. ## Screenshots <!-- If this is a user-facing change not in the frontend, please include screenshots in light and dark mode. --> <img width="1014" alt="Screenshot 2024-03-03 at 21 17 55" src="https://github.com/home-assistant/iOS/assets/35694712/85324caf-c36d-4366-a9f8-9c349192a361"> <img width="1049" alt="Screenshot 2024-03-03 at 21 17 17" src="https://github.com/home-assistant/iOS/assets/35694712/cebddbe6-8ea4-415e-b12a-0e35f86bf5a3"> <img width="1022" alt="Screenshot 2024-03-03 at 21 16 53" src="https://github.com/home-assistant/iOS/assets/35694712/ccccb902-9791-42f6-8868-5900093c40ae"> <img width="991" alt="Screenshot 2024-03-03 at 21 16 28" src="https://github.com/home-assistant/iOS/assets/35694712/f2f33685-a55c-47ed-a555-8cc0fc1561ce"> <img width="1329" alt="Screenshot 2024-03-03 at 21 16 00" src="https://github.com/home-assistant/iOS/assets/35694712/2dc156da-29d6-44e4-a064-4fbdb79139bd"> <img width="1130" alt="Screenshot 2024-03-03 at 21 14 53" src="https://github.com/home-assistant/iOS/assets/35694712/628dd2ff-5bba-4ee7-912b-cdbdf73f18b2">
40 lines
1.2 KiB
Swift
40 lines
1.2 KiB
Swift
import CoreServices
|
|
import Foundation
|
|
import PromiseKit
|
|
|
|
public struct ItemProviderRequest<Type> {
|
|
let utType: String
|
|
init(_ utType: CFString) {
|
|
self.utType = utType as String
|
|
}
|
|
|
|
public static var url: ItemProviderRequest<URL> { .init(kUTTypeURL) }
|
|
public static var text: ItemProviderRequest<String> { .init(kUTTypeText) }
|
|
}
|
|
|
|
public extension NSItemProvider {
|
|
func item<T>(for request: ItemProviderRequest<T>) -> Promise<T> {
|
|
Promise { seal in
|
|
loadItem(forTypeIdentifier: request.utType, completionHandler: { value, error in
|
|
seal.resolve(value as? T, error)
|
|
})
|
|
}
|
|
}
|
|
}
|
|
|
|
public extension NSExtensionContext {
|
|
func inputItemAttachments<T>(for request: ItemProviderRequest<T>) -> Guarantee<[T]> {
|
|
let extensionItems = inputItems.compactMap { $0 as? NSExtensionItem }
|
|
let attachments = extensionItems
|
|
.flatMap { $0.attachments ?? [] }
|
|
.map { $0.item(for: request) }
|
|
|
|
return when(resolved: attachments).compactMapValues {
|
|
switch $0 {
|
|
case let .fulfilled(value): return value
|
|
case .rejected: return nil
|
|
}
|
|
}
|
|
}
|
|
}
|