iOS quick response (w.i.p)

This commit is contained in:
2024-12-21 21:06:14 +08:00
parent e458943f56
commit be98fe133d
11 changed files with 154 additions and 35 deletions

View File

@ -0,0 +1,39 @@
//
// AppIntent.swift
// Runner
//
// Created by LittleSheep on 2024/12/21.
//
import AppIntents
import Flutter
import Foundation
import home_widget
@available(iOS 17, *)
public struct AppBackgroundIntent: AppIntent {
static public var title: LocalizedStringResource = "Solar Network Background Intent"
@Parameter(title: "Widget URI")
var url: URL?
@Parameter(title: "AppGroup")
var appGroup: String?
public init() {}
public init(url: URL?, appGroup: String?) {
self.url = url
self.appGroup = appGroup
}
public func perform() async throws -> some IntentResult {
await HomeWidgetBackgroundWorker.run(url: url, appGroup: appGroup!)
return .result()
}
}
@available(iOS 17, *)
@available(iOSApplicationExtension, unavailable)
extension AppBackgroundIntent: ForegroundContinuableIntent {}

View File

@ -6,13 +6,34 @@
//
import Foundation
import home_widget
class NotifyDelegate: UIResponder, UNUserNotificationCenterDelegate {
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
if let textResponse = response as? UNTextInputNotificationResponse {
let userText = textResponse.userText
print("User replied: \(userText)")
// Handle the reply text
let content = response.notification.request.content
guard let metadata = content.userInfo["metadata"] as? [AnyHashable: Any] else {
return
}
let channelId = metadata["channel_id"] as? Int
let eventId = metadata["event_id"] as? Int
if #available(iOS 17, *) {
Task {
await HomeWidgetBackgroundWorker.run(
url: URL(string: "solink:///chat/reply")?.appending(queryItems: [
URLQueryItem(name: "channel_id", value: String(channelId ?? 0)),
URLQueryItem(name: "event_id", value: String(eventId ?? 0)),
URLQueryItem(name: "text", value: textResponse.userText)
]),
appGroup: "group.solsynth.solian"
)
}
} else {
// Fallback on earlier versions
}
}
completionHandler()