function adapt
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
import UIKit
|
||||
import WidgetKit
|
||||
|
||||
let widgetGroupId = "group.top.zhushenwudi.llmp"
|
||||
let widgetGroupId = "group.com.zhushenwudi.lovelivemusicplayer"
|
||||
|
||||
@main
|
||||
class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||
private var widgetReloadWorkItem: DispatchWorkItem?
|
||||
|
||||
func application(
|
||||
_ application: UIApplication,
|
||||
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil
|
||||
@@ -28,15 +31,19 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||
options: UIScene.ConnectionOptions
|
||||
) -> UISceneConfiguration {
|
||||
if connectingSceneSession.role == UISceneSession.Role.carTemplateApplication {
|
||||
return UISceneConfiguration(
|
||||
let config = UISceneConfiguration(
|
||||
name: "CarPlay Configuration",
|
||||
sessionRole: connectingSceneSession.role
|
||||
)
|
||||
config.delegateClass = CarPlaySceneDelegate.self
|
||||
return config
|
||||
}
|
||||
return UISceneConfiguration(
|
||||
let config = UISceneConfiguration(
|
||||
name: "Default Configuration",
|
||||
sessionRole: connectingSceneSession.role
|
||||
)
|
||||
config.delegateClass = SceneDelegate.self
|
||||
return config
|
||||
}
|
||||
|
||||
private func registerHostNotifications() {
|
||||
@@ -48,18 +55,62 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||
HostBridge.shared.presentShare(from: notification.userInfo)
|
||||
}
|
||||
NotificationCenter.default.addObserver(
|
||||
forName: Notification.Name("fromWidgetToHost"),
|
||||
forName: Notification.Name("fromWigetToRunner"),
|
||||
object: nil,
|
||||
queue: .main
|
||||
) { notification in
|
||||
HostBridge.shared.handleWidgetAction(from: notification.userInfo)
|
||||
}
|
||||
NotificationCenter.default.addObserver(
|
||||
forName: Notification.Name("llmpCarPlayAction"),
|
||||
forName: Notification.Name("llmpWidgetSaveCover"),
|
||||
object: nil,
|
||||
queue: .main
|
||||
) { notification in
|
||||
HostBridge.shared.handleCarPlayAction(from: notification.userInfo)
|
||||
guard let path = notification.userInfo?["path"] as? String else { return }
|
||||
WidgetAppUtils.shared.saveImageToFile(imagePath: path) { [weak self] in
|
||||
self?.scheduleWidgetReload()
|
||||
}
|
||||
}
|
||||
NotificationCenter.default.addObserver(
|
||||
forName: Notification.Name("llmpReloadWidgets"),
|
||||
object: nil,
|
||||
queue: .main
|
||||
) { [weak self] _ in
|
||||
self?.scheduleWidgetReload()
|
||||
}
|
||||
NotificationCenter.default.addObserver(
|
||||
forName: Notification.Name("llmpOpenWebView"),
|
||||
object: nil,
|
||||
queue: .main
|
||||
) { notification in
|
||||
HostBridge.shared.presentWebView(from: notification.userInfo)
|
||||
}
|
||||
NotificationCenter.default.addObserver(
|
||||
forName: Notification.Name("llmpShowToast"),
|
||||
object: nil,
|
||||
queue: .main
|
||||
) { notification in
|
||||
guard let message = notification.userInfo?["message"] as? String else { return }
|
||||
HostBridge.shared.showToast(message)
|
||||
}
|
||||
QqShareHost.shared.prepare()
|
||||
}
|
||||
|
||||
func application(
|
||||
_ app: UIApplication,
|
||||
open url: URL,
|
||||
options: [UIApplication.OpenURLOptionsKey: Any] = [:]
|
||||
) -> Bool {
|
||||
QqShareHost.shared.handleOpen(url)
|
||||
}
|
||||
|
||||
/// 合并切歌、播放状态、歌词行和封面完成时挤在一起的刷新请求。
|
||||
private func scheduleWidgetReload() {
|
||||
widgetReloadWorkItem?.cancel()
|
||||
let workItem = DispatchWorkItem {
|
||||
WidgetCenter.shared.reloadAllTimelines()
|
||||
}
|
||||
widgetReloadWorkItem = workItem
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3, execute: workItem)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user