From fe7dd4322f790d9b8172e3153603505ddd4406ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Fri, 29 Nov 2024 14:40:37 +0800 Subject: [PATCH] Reload service on current profile update --- .../Views/Profile/EditProfileView.swift | 1 + Library/Database/Profile+Update.swift | 20 ++++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/ApplicationLibrary/Views/Profile/EditProfileView.swift b/ApplicationLibrary/Views/Profile/EditProfileView.swift index 65598ec..25043c0 100644 --- a/ApplicationLibrary/Views/Profile/EditProfileView.swift +++ b/ApplicationLibrary/Views/Profile/EditProfileView.swift @@ -166,6 +166,7 @@ public struct EditProfileView: View { #else try await ProfileUpdateTask.configure() #endif + try await profile.onProfileUpdated() } catch { alert = Alert(error) return diff --git a/Library/Database/Profile+Update.swift b/Library/Database/Profile+Update.swift index c3bed66..c64be83 100644 --- a/Library/Database/Profile+Update.swift +++ b/Library/Database/Profile+Update.swift @@ -13,8 +13,26 @@ public extension Profile { if let error { throw error } - try write(remoteContent) lastUpdated = Date() try await ProfileManager.update(self) + do { + let oldContent = try read() + if oldContent == remoteContent { + return + } + } catch {} + try write(remoteContent) + try await onProfileUpdated() } + + nonisolated func onProfileUpdated() async throws { + if await SharedPreferences.selectedProfileID.get() == id { + if let profile = try? await ExtensionProfile.load() { + if profile.status == .connected { + try LibboxNewStandaloneCommandClient()!.serviceReload() + } + } + } + } + }