diff --git a/ApplicationLibrary/Service/UIProfileUpdateTask.swift b/ApplicationLibrary/Service/UIProfileUpdateTask.swift index 07da12a..e1c5799 100644 --- a/ApplicationLibrary/Service/UIProfileUpdateTask.swift +++ b/ApplicationLibrary/Service/UIProfileUpdateTask.swift @@ -5,28 +5,34 @@ 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 { - if !registered { - let success = BGTaskScheduler.shared.register(forTaskWithIdentifier: taskSchedulerPermittedIdentifier, using: nil) { task in - NSLog("profile update task started") - Task { - await getAndupdateProfiles(task) + private actor Register { + private var registered = false + func configure() async throws { + if !registered { + let success = BGTaskScheduler.shared.register(forTaskWithIdentifier: taskSchedulerPermittedIdentifier, using: nil) { task in + NSLog("profile update task started") + Task { + await UIProfileUpdateTask.getAndupdateProfiles(task) + } } + if !success { + throw NSError(domain: "register failed", code: 0) + } + registered = true } - if !success { - throw NSError(domain: "register failed", code: 0) + BGTaskScheduler.shared.cancelAllTaskRequests() + let profiles = try await ProfileManager.listAutoUpdateEnabled() + if profiles.isEmpty { + return } - registered = true + try scheduleUpdate(ProfileUpdateTask.calculateEarliestBeginDate(profiles)) } - BGTaskScheduler.shared.cancelAllTaskRequests() - let profiles = try await ProfileManager.listAutoUpdateEnabled() - if profiles.isEmpty { - return - } - try scheduleUpdate(ProfileUpdateTask.calculateEarliestBeginDate(profiles)) + } + + private static let register = Register() + public static func configure() async throws { + try await register.configure() } private nonisolated static func getAndupdateProfiles(_ task: BGTask) async { diff --git a/ApplicationLibrary/Views/Profile/EditProfileView.swift b/ApplicationLibrary/Views/Profile/EditProfileView.swift index 4a12e25..c2a8741 100644 --- a/ApplicationLibrary/Views/Profile/EditProfileView.swift +++ b/ApplicationLibrary/Views/Profile/EditProfileView.swift @@ -170,6 +170,7 @@ public struct EditProfileView: View { do { try await Task.sleep(nanoseconds: UInt64(100 * Double(NSEC_PER_MSEC))) try await profile.updateRemoteProfile() + await performCallback() } catch { alert = Alert(error) } @@ -189,11 +190,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 + #if os(iOS) || os(tvOS) + try await UIProfileUpdateTask.configure() + #else + try await ProfileUpdateTask.configure() + #endif } catch { alert = Alert(error) return diff --git a/ApplicationLibrary/Views/Profile/NewProfileView.swift b/ApplicationLibrary/Views/Profile/NewProfileView.swift index 5476c6c..95b315f 100644 --- a/ApplicationLibrary/Views/Profile/NewProfileView.swift +++ b/ApplicationLibrary/Views/Profile/NewProfileView.swift @@ -248,11 +248,11 @@ public struct NewProfileView: View { lastUpdated: lastUpdated )) if profileType == .remote { -#if os(iOS) || os(tvOS) - try await UIProfileUpdateTask.configure() -#else - try await ProfileUpdateTask.configure() -#endif + #if os(iOS) || os(tvOS) + try await UIProfileUpdateTask.configure() + #else + try await ProfileUpdateTask.configure() + #endif } } } diff --git a/ApplicationLibrary/Views/Profile/ProfileView.swift b/ApplicationLibrary/Views/Profile/ProfileView.swift index 370e0aa..7821605 100644 --- a/ApplicationLibrary/Views/Profile/ProfileView.swift +++ b/ApplicationLibrary/Views/Profile/ProfileView.swift @@ -34,7 +34,7 @@ public struct ProfileView: View { public init() {} public var body: some View { - viewBuilder { + VStack { if isLoading { ProgressView().onAppear { Task { @@ -222,6 +222,9 @@ public struct ProfileView: View { isLoading = false } do { + if !profileList.isEmpty { + profileList.removeAll() + } profileList = try await ProfileManager.list() } catch { alert = Alert(error)