Fix profile upate task
This commit is contained in:
@@ -5,16 +5,21 @@ import Library
|
||||
#if os(iOS) || os(tvOS)
|
||||
public class UIProfileUpdateTask: BGAppRefreshTask {
|
||||
private static let taskSchedulerPermittedIdentifier = "\(FilePath.packageName).update_profiles"
|
||||
|
||||
private static var registered = false
|
||||
|
||||
public static func configure() async throws {
|
||||
let success = BGTaskScheduler.shared.register(forTaskWithIdentifier: taskSchedulerPermittedIdentifier, using: nil) { task in
|
||||
NSLog("profile update task started")
|
||||
Task {
|
||||
await getAndupdateProfiles(task)
|
||||
if !registered {
|
||||
let success = BGTaskScheduler.shared.register(forTaskWithIdentifier: taskSchedulerPermittedIdentifier, using: nil) { task in
|
||||
NSLog("profile update task started")
|
||||
Task {
|
||||
await getAndupdateProfiles(task)
|
||||
}
|
||||
}
|
||||
}
|
||||
if !success {
|
||||
throw NSError(domain: "register failed", code: 0)
|
||||
if !success {
|
||||
throw NSError(domain: "register failed", code: 0)
|
||||
}
|
||||
registered = true
|
||||
}
|
||||
BGTaskScheduler.shared.cancelAllTaskRequests()
|
||||
let profiles = try await ProfileManager.listAutoUpdateEnabled()
|
||||
|
||||
@@ -170,11 +170,6 @@ public struct EditProfileView: View {
|
||||
do {
|
||||
try await Task.sleep(nanoseconds: UInt64(100 * Double(NSEC_PER_MSEC)))
|
||||
try await profile.updateRemoteProfile()
|
||||
#if os(iOS) || os(tvOS)
|
||||
try await UIProfileUpdateTask.configure()
|
||||
#else
|
||||
try await ProfileUpdateTask.configure()
|
||||
#endif
|
||||
} catch {
|
||||
alert = Alert(error)
|
||||
}
|
||||
@@ -194,6 +189,11 @@ public struct EditProfileView: View {
|
||||
private func saveProfile() async {
|
||||
do {
|
||||
_ = try await ProfileManager.update(profile)
|
||||
#if os(iOS) || os(tvOS)
|
||||
try await UIProfileUpdateTask.configure()
|
||||
#else
|
||||
try await ProfileUpdateTask.configure()
|
||||
#endif
|
||||
} catch {
|
||||
alert = Alert(error)
|
||||
return
|
||||
|
||||
@@ -247,5 +247,12 @@ public struct NewProfileView: View {
|
||||
autoUpdateInterval: autoUpdateInterval,
|
||||
lastUpdated: lastUpdated
|
||||
))
|
||||
if profileType == .remote {
|
||||
#if os(iOS) || os(tvOS)
|
||||
try await UIProfileUpdateTask.configure()
|
||||
#else
|
||||
try await ProfileUpdateTask.configure()
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,19 +18,19 @@ class ApplicationDelegate: NSObject, UIApplicationDelegate {
|
||||
}
|
||||
|
||||
private func setup() async {
|
||||
await setupBackground()
|
||||
if UIDevice.current.userInterfaceIdiom == .phone {
|
||||
await requestNetworkPermission()
|
||||
}
|
||||
}
|
||||
|
||||
private nonisolated func setupBackground() async {
|
||||
do {
|
||||
try await UIProfileUpdateTask.configure()
|
||||
NSLog("setup background task success")
|
||||
} catch {
|
||||
NSLog("setup background task error: \(error.localizedDescription)")
|
||||
}
|
||||
if UIDevice.current.userInterfaceIdiom == .phone {
|
||||
await requestNetworkPermission()
|
||||
}
|
||||
await setupBackground()
|
||||
}
|
||||
|
||||
private nonisolated func setupBackground() async {
|
||||
if #available(iOS 16.0, *) {
|
||||
do {
|
||||
let profileServer = try ProfileServer()
|
||||
|
||||
@@ -9,12 +9,12 @@ class ApplicationDelegate: NSObject, UIApplicationDelegate {
|
||||
NSLog("Here I stand")
|
||||
LibboxSetup(FilePath.sharedDirectory.relativePath, FilePath.workingDirectory.relativePath, FilePath.cacheDirectory.relativePath, true)
|
||||
Task {
|
||||
await setupBackground()
|
||||
await setup()
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
private nonisolated func setupBackground() async {
|
||||
private func setup() async {
|
||||
do {
|
||||
try await UIProfileUpdateTask.configure()
|
||||
NSLog("setup background task success")
|
||||
|
||||
Reference in New Issue
Block a user