From bf0bef6af5e66404d73363111195b5cc11d58d7c Mon Sep 17 00:00:00 2001 From: p-x9 <50244599+p-x9@users.noreply.github.com> Date: Wed, 12 Oct 2022 22:04:37 +0900 Subject: [PATCH] fix UserDefaults suites that should be synchronized --- Sources/AppContainer/AppContainer.swift | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Sources/AppContainer/AppContainer.swift b/Sources/AppContainer/AppContainer.swift index 0d8e27e..b39115d 100644 --- a/Sources/AppContainer/AppContainer.swift +++ b/Sources/AppContainer/AppContainer.swift @@ -363,6 +363,18 @@ extension AppContainer { // MARK: - UserDefaults extension AppContainer { private func syncUserDefaults() throws { + let preferencesUrl = homeDirectoryUrl.appendingPathComponent("Library/Preferences") + let suites = try fileManager.contentsOfDirectory(atPath: preferencesUrl.path) + .filter { $0.hasSuffix(".plist") } + .compactMap { $0.components(separatedBy: ".plist").first } + .filter { !cachedSuiteNames.contains($0) } + cachedSuiteNames += suites + + if let standard = groupIdentifier ?? Bundle.main.bundleIdentifier, + !cachedSuiteNames.contains(standard) { + cachedSuiteNames.append(standard) + } + cachedSuiteNames.forEach { syncUserDefaults(suiteName: $0) }