mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2025-08-12 06:26:36 +00:00
Add code that can add a feed to the first active account
This commit is contained in:
@@ -7,16 +7,47 @@
|
||||
//
|
||||
|
||||
import Intents
|
||||
import Account
|
||||
|
||||
public class AddFeedIntentHandler: NSObject, AddFeedIntentHandling {
|
||||
|
||||
override init() {
|
||||
super.init()
|
||||
DispatchQueue.main.sync {
|
||||
AccountManager.shared = AccountManager()
|
||||
}
|
||||
}
|
||||
|
||||
public func resolveUrl(for intent: AddFeedIntent, with completion: @escaping (AddFeedUrlResolutionResult) -> Void) {
|
||||
guard let url = intent.url else {
|
||||
completion(.unsupported(forReason: .required))
|
||||
return
|
||||
}
|
||||
completion(.success(with: url))
|
||||
}
|
||||
|
||||
public func handle(intent: AddFeedIntent, completion: @escaping (AddFeedIntentResponse) -> Void) {
|
||||
guard let url = intent.url else {
|
||||
completion(AddFeedIntentResponse(code: .failure, userActivity: nil))
|
||||
return
|
||||
}
|
||||
|
||||
DispatchQueue.main.async {
|
||||
guard let account = AccountManager.shared.activeAccounts.first else {
|
||||
completion(AddFeedIntentResponse(code: .failure, userActivity: nil))
|
||||
return
|
||||
}
|
||||
|
||||
account.createFeed(url: url.absoluteString, name: nil, container: account) { result in
|
||||
switch result {
|
||||
case .success:
|
||||
completion(AddFeedIntentResponse(code: .success, userActivity: nil))
|
||||
case .failure:
|
||||
completion(AddFeedIntentResponse(code: .failure, userActivity: nil))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public func resolveUrl(for intent: AddFeedIntent, with completion: @escaping (INURLResolutionResult) -> Void) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -25,6 +25,8 @@
|
||||
<string>Add a feed</string>
|
||||
<key>INIntentDescriptionID</key>
|
||||
<string>IuAbef</string>
|
||||
<key>INIntentInput</key>
|
||||
<string>url</string>
|
||||
<key>INIntentKeyParameter</key>
|
||||
<string>url</string>
|
||||
<key>INIntentLastParameterTag</key>
|
||||
@@ -89,6 +91,19 @@
|
||||
<integer>2</integer>
|
||||
<key>INIntentParameterType</key>
|
||||
<string>URL</string>
|
||||
<key>INIntentParameterUnsupportedReasons</key>
|
||||
<array>
|
||||
<dict>
|
||||
<key>INIntentParameterUnsupportedReasonCode</key>
|
||||
<string>required</string>
|
||||
<key>INIntentParameterUnsupportedReasonCustom</key>
|
||||
<true/>
|
||||
<key>INIntentParameterUnsupportedReasonFormatString</key>
|
||||
<string>You must supply a URL.</string>
|
||||
<key>INIntentParameterUnsupportedReasonFormatStringID</key>
|
||||
<string>4xjRes</string>
|
||||
</dict>
|
||||
</array>
|
||||
</dict>
|
||||
</array>
|
||||
<key>INIntentResponse</key>
|
||||
|
||||
Reference in New Issue
Block a user