Enable iCloud sync by default, remove user toggle
- CloudKit sync is now always enabled for all users - Remove useCloudKit setting and toggle from Settings - Remove CloudKitSyncMonitor usage (package can be removed) - Remove container switching logic since sync is always on - Update SharedModelContainer defaults to enable CloudKit 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -20,12 +20,8 @@ final class DataController: ObservableObject {
|
||||
container.mainContext
|
||||
}
|
||||
|
||||
private var useCloudKit: Bool {
|
||||
GroupUserDefaults.groupDefaults.bool(forKey: UserDefaultsStore.Keys.useCloudKit.rawValue)
|
||||
}
|
||||
|
||||
// Listeners for data changes (keeping existing pattern)
|
||||
var switchContainerListeners = [(() -> Void)]()
|
||||
private var editedDataClosure = [() -> Void]()
|
||||
|
||||
// Computed properties for earliest/latest entries
|
||||
@@ -46,19 +42,9 @@ final class DataController: ObservableObject {
|
||||
}
|
||||
|
||||
private init() {
|
||||
let cloudKit = GroupUserDefaults.groupDefaults.bool(forKey: UserDefaultsStore.Keys.useCloudKit.rawValue)
|
||||
container = SharedModelContainer.createWithFallback(useCloudKit: cloudKit)
|
||||
container = SharedModelContainer.createWithFallback(useCloudKit: true)
|
||||
}
|
||||
|
||||
// MARK: - Container Switching (for CloudKit toggle)
|
||||
|
||||
func switchContainer() {
|
||||
save()
|
||||
container = SharedModelContainer.createWithFallback(useCloudKit: useCloudKit)
|
||||
for listener in switchContainerListeners {
|
||||
listener()
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Listener Management
|
||||
|
||||
|
||||
@@ -102,7 +102,7 @@ final class WidgetDataProvider: MoodDataReading {
|
||||
if let existing = _container {
|
||||
return existing
|
||||
}
|
||||
let newContainer = SharedModelContainer.createWithFallback(useCloudKit: false)
|
||||
let newContainer = SharedModelContainer.createWithFallback(useCloudKit: true)
|
||||
_container = newContainer
|
||||
return newContainer
|
||||
}
|
||||
|
||||
@@ -28,10 +28,10 @@ enum SharedModelContainer {
|
||||
private static let logger = Logger(subsystem: Bundle.main.bundleIdentifier ?? "com.tt.ifeel", category: "SharedModelContainer")
|
||||
|
||||
/// Creates a ModelContainer with the appropriate configuration for app group sharing
|
||||
/// - Parameter useCloudKit: Whether to enable CloudKit sync
|
||||
/// - Parameter useCloudKit: Whether to enable CloudKit sync (defaults to true)
|
||||
/// - Returns: Configured ModelContainer
|
||||
/// - Throws: SharedModelContainerError if creation fails
|
||||
static func create(useCloudKit: Bool = false) throws -> ModelContainer {
|
||||
static func create(useCloudKit: Bool = true) throws -> ModelContainer {
|
||||
let schema = Schema([MoodEntryModel.self])
|
||||
let storeURL = try Self.storeURL
|
||||
|
||||
@@ -61,9 +61,9 @@ enum SharedModelContainer {
|
||||
}
|
||||
|
||||
/// Creates a ModelContainer, falling back to in-memory storage if shared container fails
|
||||
/// - Parameter useCloudKit: Whether to enable CloudKit sync
|
||||
/// - Parameter useCloudKit: Whether to enable CloudKit sync (defaults to true)
|
||||
/// - Returns: Configured ModelContainer (shared or in-memory fallback)
|
||||
static func createWithFallback(useCloudKit: Bool = false) -> ModelContainer {
|
||||
static func createWithFallback(useCloudKit: Bool = true) -> ModelContainer {
|
||||
do {
|
||||
return try create(useCloudKit: useCloudKit)
|
||||
} catch {
|
||||
|
||||
@@ -35,11 +35,6 @@ class DayViewViewModel: ObservableObject {
|
||||
init(addMonthStartWeekdayPadding: Bool) {
|
||||
self.addMonthStartWeekdayPadding = addMonthStartWeekdayPadding
|
||||
|
||||
DataController.shared.switchContainerListeners.append { [weak self] in
|
||||
guard let self = self else { return }
|
||||
self.getGroupedData(addMonthStartWeekdayPadding: self.addMonthStartWeekdayPadding)
|
||||
}
|
||||
|
||||
DataController.shared.addNewDataListener { [weak self] in
|
||||
guard let self = self else { return }
|
||||
withAnimation {
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import CloudKitSyncMonitor
|
||||
import UniformTypeIdentifiers
|
||||
import StoreKit
|
||||
import TipKit
|
||||
@@ -461,10 +460,8 @@ struct SettingsView: View {
|
||||
|
||||
@State private var showSpecialThanks = false
|
||||
@State private var showWhyBGMode = false
|
||||
@ObservedObject var syncMonitor = SyncMonitor.shared
|
||||
@StateObject private var healthService = HealthService.shared
|
||||
|
||||
@AppStorage(UserDefaultsStore.Keys.useCloudKit.rawValue, store: GroupUserDefaults.groupDefaults) private var useCloudKit = false
|
||||
@AppStorage(UserDefaultsStore.Keys.deleteEnable.rawValue, store: GroupUserDefaults.groupDefaults) private var deleteEnabled = true
|
||||
@AppStorage(UserDefaultsStore.Keys.theme.rawValue, store: GroupUserDefaults.groupDefaults) private var theme: Theme = .system
|
||||
@AppStorage(UserDefaultsStore.Keys.textColor.rawValue, store: GroupUserDefaults.groupDefaults) private var textColor: Color = DefaultTextColor.textColor
|
||||
@@ -505,11 +502,6 @@ struct SettingsView: View {
|
||||
Text("Test builds only")
|
||||
addTestDataCell
|
||||
clearDB
|
||||
// randomIcons
|
||||
|
||||
if useCloudKit {
|
||||
cloudKitStatus
|
||||
}
|
||||
// fixWeekday
|
||||
exportData
|
||||
importData
|
||||
@@ -1004,42 +996,6 @@ struct SettingsView: View {
|
||||
.cornerRadius(Constants.viewsCornerRaidus, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight])
|
||||
}
|
||||
|
||||
private var cloudKitEnable: some View {
|
||||
ZStack {
|
||||
theme.currentTheme.secondaryBGColor
|
||||
VStack {
|
||||
Toggle(isOn: $useCloudKit, label: {
|
||||
Text(String(localized: "settings_use_cloudkit_title"))
|
||||
.foregroundColor(textColor)
|
||||
})
|
||||
.onChange(of: useCloudKit) { _, newValue in
|
||||
EventLogger.log(event: "toggle_use_cloudkit", withData: ["value": newValue])
|
||||
}
|
||||
.padding()
|
||||
Text(String(localized: "settings_use_cloudkit_body"))
|
||||
.foregroundColor(textColor)
|
||||
}
|
||||
.padding(.bottom)
|
||||
}
|
||||
.fixedSize(horizontal: false, vertical: true)
|
||||
.cornerRadius(Constants.viewsCornerRaidus, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight])
|
||||
}
|
||||
|
||||
private var cloudKitStatus: some View {
|
||||
ZStack {
|
||||
theme.currentTheme.secondaryBGColor
|
||||
VStack {
|
||||
Image(systemName: syncMonitor.syncStateSummary.symbolName)
|
||||
.foregroundColor(syncMonitor.syncStateSummary.symbolColor)
|
||||
Text( syncMonitor.syncStateSummary.isBroken ? "cloudkit is broken" : "cloudkit is good")
|
||||
.foregroundColor(textColor)
|
||||
}
|
||||
.padding()
|
||||
}
|
||||
.fixedSize(horizontal: false, vertical: true)
|
||||
.cornerRadius(Constants.viewsCornerRaidus, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight])
|
||||
}
|
||||
|
||||
private var canDelete: some View {
|
||||
ZStack {
|
||||
theme.currentTheme.secondaryBGColor
|
||||
|
||||
Reference in New Issue
Block a user