pushdeer/ios/PushDeer-iOS/PushDeer/PushDeerApp.swift
hext c3d0cd13f5 新增功能: 桌面小部件, 展示最近消息, 支持收到推送自动刷新;
新增功能: 1分钟内删除两条消息, 会提示是否一键清空全部消息.
2022-04-19 00:35:56 +08:00

52 lines
1.8 KiB
Swift

//
// PushDeerApp.swift
// PushDeer
//
// Created by HEXT on 2021/12/25.
//
import SwiftUI
import WidgetKit
@main
struct PushDeerApp: App {
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
let store = AppState.shared
let persistenceController = PersistenceController.shared
var body: some Scene {
WindowGroup {
ContentView()
.onOpenURL(perform: { url in
print(#function, url)
#if !targetEnvironment(macCatalyst) && !APPCLIP && !SELFHOSTED
WXApi.handleOpen(url, delegate: WXDelegate.shared)
#endif
})
.onContinueUserActivity(NSUserActivityTypeBrowsingWeb, perform: { userActivity in
print(#function, userActivity.webpageURL as Any)
#if !targetEnvironment(macCatalyst) && !APPCLIP && !SELFHOSTED
WXApi.handleOpenUniversalLink(userActivity, delegate: WXDelegate.shared)
#endif
})
.onReceive(NotificationCenter.default.publisher(for: UIApplication.willEnterForegroundNotification)) { _ in
// ,
UIApplication.shared.applicationIconBadgeNumber = 0
// ,
if !AppState.shared.token.isEmpty {
Task {
let messageItems = try await HttpRequest.getMessages().messages
try MessageModel.saveAndUpdate(messageItems: messageItems)
}
}
}
.onReceive(NotificationCenter.default.publisher(for: UIApplication.willResignActiveNotification), perform: { _ in
// APP,
WidgetCenter.shared.reloadAllTimelines()
})
.environmentObject(store)
.environment(\.managedObjectContext, persistenceController.container.viewContext)
}
}
}