diff --git a/NearFuture.xcodeproj/project.pbxproj b/NearFuture.xcodeproj/project.pbxproj index 4a1acc3..3aeae7e 100644 --- a/NearFuture.xcodeproj/project.pbxproj +++ b/NearFuture.xcodeproj/project.pbxproj @@ -652,7 +652,7 @@ REGISTER_APP_GROUPS = YES; SDKROOT = macosx; SWIFT_EMIT_LOC_STRINGS = YES; - SWIFT_VERSION = 5.0; + SWIFT_VERSION = 6.0; }; name = Debug; }; @@ -684,7 +684,7 @@ REGISTER_APP_GROUPS = YES; SDKROOT = macosx; SWIFT_EMIT_LOC_STRINGS = YES; - SWIFT_VERSION = 5.0; + SWIFT_VERSION = 6.0; }; name = Release; }; @@ -866,7 +866,8 @@ SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO; SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD = YES; SWIFT_EMIT_LOC_STRINGS = YES; - SWIFT_VERSION = 5.0; + SWIFT_STRICT_CONCURRENCY = complete; + SWIFT_VERSION = 6.0; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; @@ -916,7 +917,8 @@ SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO; SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD = YES; SWIFT_EMIT_LOC_STRINGS = YES; - SWIFT_VERSION = 5.0; + SWIFT_STRICT_CONCURRENCY = complete; + SWIFT_VERSION = 6.0; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Release; diff --git a/NearFutureWidgets/NearFutureWidgets.swift b/NearFutureWidgets/NearFutureWidgets.swift index 1f9f41d..8ace7d0 100644 --- a/NearFutureWidgets/NearFutureWidgets.swift +++ b/NearFutureWidgets/NearFutureWidgets.swift @@ -154,25 +154,25 @@ struct EventWidgetView: View { .foregroundColor(event.date < Date() ? .red : .primary) .padding(.trailing, -12) } else { - Button( - intent: CompleteEvent( - eventID: IntentParameter( - title: LocalizedStringResource( - stringLiteral: event.id.uuidString - ) - ) - ) - ) { - if event.complete { - Circle() - .frame(width: 10) - .foregroundStyle(.green) - } else { - Circle() - .frame(width: 10) - .foregroundStyle(.gray) - } - } +// Button( +// intent: CompleteEvent( +// eventID: IntentParameter( +// title: LocalizedStringResource( +// stringLiteral: event.id.uuidString +// ) +// ) +// ) +// ) { +// if event.complete { +// Circle() +// .frame(width: 10) +// .foregroundStyle(.green) +// } else { +// Circle() +// .frame(width: 10) +// .foregroundStyle(.gray) +// } +// } Text(daysUntilEvent(event.date).long) .font(.caption) .multilineTextAlignment(.trailing) diff --git a/Shared/CompleteEventButton.swift b/Shared/CompleteEventButton.swift index 96524f8..31f9636 100644 --- a/Shared/CompleteEventButton.swift +++ b/Shared/CompleteEventButton.swift @@ -11,7 +11,7 @@ struct CompleteEventButton: View { @ObservedObject var viewModel: EventViewModel @Binding var event: Event - @State var timer: Timer? + @MainActor @State var timer: Timer? @State var largeTick: Bool = false @State var completeInProgress: Bool = false @State var completeStartTime: Date = .now @@ -35,24 +35,27 @@ struct CompleteEventButton: View { progress = 0 timer = Timer(timeInterval: 0.02, repeats: true) { timer in - guard completeInProgress else { return } - guard timer.isValid else { return } - let elapsed = Date().timeIntervalSince(completeStartTime) - progress = min(1, elapsed) - #if canImport(UIKit) - UIImpactFeedbackGenerator(style: .light).impactOccurred() - #endif - - if progress >= 1 { - withAnimation { completeInProgress = false } - viewModel.completeEvent(&event) + DispatchQueue.main.sync { + guard completeInProgress else { return } + guard let timer = self.timer else { return } + guard timer.isValid else { return } + let elapsed = Date().timeIntervalSince(completeStartTime) + progress = min(1, elapsed) #if canImport(UIKit) - DispatchQueue.main.asyncAfter(deadline: .now()+0.02) { - UINotificationFeedbackGenerator().notificationOccurred(.success) - } + UIImpactFeedbackGenerator(style: .light).impactOccurred() #endif - timer.invalidate() - progress = 0 + + if progress >= 1 { + withAnimation { completeInProgress = false } + viewModel.completeEvent(&event) +#if canImport(UIKit) + DispatchQueue.main.asyncAfter(deadline: .now()+0.02) { + UINotificationFeedbackGenerator().notificationOccurred(.success) + } +#endif + timer.invalidate() + progress = 0 + } } } RunLoop.main.add(timer!, forMode: .common) diff --git a/Shared/Model/Events.swift b/Shared/Model/Events.swift index ccb86d7..0d9835d 100644 --- a/Shared/Model/Events.swift +++ b/Shared/Model/Events.swift @@ -496,6 +496,7 @@ func getBuildID() -> String { return "\(build)" } +@MainActor func getDevice() -> (sf: String, label: String) { #if canImport(UIKit) let asi = ProcessInfo().isiOSAppOnMac diff --git a/Shared/Model/Settings.swift b/Shared/Model/Settings.swift index a01d61d..35fcf4b 100644 --- a/Shared/Model/Settings.swift +++ b/Shared/Model/Settings.swift @@ -18,6 +18,7 @@ struct NFSettings: Codable, Equatable { var prevAppVersion: String = getVersion()+getBuildID() } +@MainActor class SettingsViewModel: ObservableObject { @Published var settings: NFSettings = NFSettings() @@ -36,7 +37,7 @@ class SettingsViewModel: ObservableObject { "pink" ] - @Published var device: (sf: String, label: String) + @Published var device: (sf: String, label: String) = ("", "") init(load: Bool = true) { self.device = getDevice()