diff --git a/Chinese Time.xcodeproj/project.pbxproj b/Chinese Time.xcodeproj/project.pbxproj index 0b8d4b1..7fe0ede 100644 --- a/Chinese Time.xcodeproj/project.pbxproj +++ b/Chinese Time.xcodeproj/project.pbxproj @@ -1440,8 +1440,8 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - APP_BUILD = 95; - APP_VERSION = 5.0; + APP_BUILD = 97; + APP_VERSION = 5.0.1; ASSETCATALOG_COMPILER_APPICON_NAME = ""; ASSETCATALOG_COMPILER_GENERATE_ASSET_SYMBOL_FRAMEWORKS = SwiftUI; ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; @@ -1520,8 +1520,8 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - APP_BUILD = 95; - APP_VERSION = 5.0; + APP_BUILD = 97; + APP_VERSION = 5.0.1; ASSETCATALOG_COMPILER_APPICON_NAME = ""; ASSETCATALOG_COMPILER_GENERATE_ASSET_SYMBOL_FRAMEWORKS = SwiftUI; ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; diff --git a/Chinese Time.xcodeproj/xcuserdata/leo.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/Chinese Time.xcodeproj/xcuserdata/leo.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist index 4d008e7..66fe9f1 100644 --- a/Chinese Time.xcodeproj/xcuserdata/leo.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/Chinese Time.xcodeproj/xcuserdata/leo.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -3,102 +3,4 @@ uuid = "17FF20B8-95CE-4A9A-9D52-A57C1B74571D" type = "1" version = "2.0"> - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Shared/DataModel/MetaLayout.swift b/Shared/DataModel/MetaLayout.swift index d0bca07..5c6ff9a 100644 --- a/Shared/DataModel/MetaLayout.swift +++ b/Shared/DataModel/MetaLayout.swift @@ -222,6 +222,7 @@ extension String { } } + @ObservationIgnored var initialized = false var globalMonth: Bool = false var apparentTime: Bool = false var locationEnabled: Bool = true @@ -342,6 +343,8 @@ extension String { } } + initialized = true + globalMonth = values["globalMonth"]?.boolValue ?? globalMonth apparentTime = values["apparentTime"]?.boolValue ?? apparentTime locationEnabled = values["locationEnabled"]?.boolValue ?? locationEnabled diff --git a/Shared/DataModel/Model.swift b/Shared/DataModel/Model.swift index 06233ff..4c70569 100644 --- a/Shared/DataModel/Model.swift +++ b/Shared/DataModel/Model.swift @@ -460,7 +460,7 @@ extension Array { static let dayTimeName = ["夜中", "日出", "日中", "日入"] static let moonTimeName = ["月出", "月中", "月入"] static let moonPhases = ["朔", "望"] - static let holidays = ["正月一日": "元旦", "正月十五": "上元", "三月三日": "上巳", "五月五日": "端午", "七月七日": "七夕", "七月十五": "中元", "九月九日": "重陽", "八月十五": "中秋", "冬月十五": "下元", "大年三十": "除夕"] + static let holidays = ["正月一日": "元旦", "正月十五": "上元", "三月三日": "上巳", "五月五日": "端午", "七月七日": "七夕", "七月十五": "中元", "九月九日": "重陽", "八月十五": "中秋", "十月十五": "下元", "大年三十": "除夕"] static let start: Date = { var components = DateComponents() components.year = 1901 diff --git a/Shared/Setting/LayoutSetting.swift b/Shared/Setting/LayoutSetting.swift index c46350c..bc5611c 100644 --- a/Shared/Setting/LayoutSetting.swift +++ b/Shared/Setting/LayoutSetting.swift @@ -14,6 +14,7 @@ struct LayoutSettingCell: View { let validation: ((V) -> V)? let completion: (() -> Void)? @State var tempValue: V + @FocusState var isFocused: Bool init(text: Text, value: Binding, validation: ((V) -> V)? = nil, completion: (() -> Void)? = nil) { self.text = text @@ -34,14 +35,14 @@ struct LayoutSettingCell: View { formatter.minimumFractionDigits = 0 return formatter }()) + .focused($isFocused) .autocorrectionDisabled() - .onSubmit { - if let validation = validation { - tempValue = validation(tempValue) - } - value = tempValue - if let completion = completion { - completion() + .onSubmit(of: .text) { + commit() + } + .onChange(of: isFocused) { _, newValue in + if !newValue { + commit() } } .task { @@ -61,6 +62,16 @@ struct LayoutSettingCell: View { .padding(.trailing, 10) } } + + func commit() { + if let validation = validation { + tempValue = validation(tempValue) + } + value = tempValue + if let completion = completion { + completion() + } + } } #if os(macOS) diff --git a/Shared/Setting/Location.swift b/Shared/Setting/Location.swift index 6246909..174fb90 100644 --- a/Shared/Setting/Location.swift +++ b/Shared/Setting/Location.swift @@ -145,6 +145,7 @@ struct OnSubmitTextField: View { let formatter: NumberFormatter @Binding var value: V @State var tempValue: V + @FocusState var isFocused: Bool init(_ title: LocalizedStringKey, value: Binding, formatter: NumberFormatter) { self.title = title @@ -155,9 +156,15 @@ struct OnSubmitTextField: View { var body: some View { TextField(title, value: $tempValue, formatter: formatter) - .onSubmit { + .focused($isFocused) + .onSubmit(of: .text) { value = tempValue } + .onChange(of: isFocused) { _, newValue in + if !newValue { + value = tempValue + } + } } } #endif diff --git a/Shared/Setting/ThemesList.swift b/Shared/Setting/ThemesList.swift index 2b65673..2f72e67 100644 --- a/Shared/Setting/ThemesList.swift +++ b/Shared/Setting/ThemesList.swift @@ -217,7 +217,7 @@ struct ThemesList: View { if let target = target, !target.isNil { watchLayout.update(from: target.code!) #if os(iOS) - let _ = WatchConnectivityManager.shared.sendLayout(watchLayout.encode(includeOffset: false)) + WatchConnectivityManager.shared.sendLayout(watchLayout.encode(includeOffset: false)) #elseif os(macOS) if let delegate = AppDelegate.instance { delegate.update() diff --git a/Shared/WatchConnectivity.swift b/Shared/WatchConnectivity.swift index 4d9ca4e..3ed44d4 100644 --- a/Shared/WatchConnectivity.swift +++ b/Shared/WatchConnectivity.swift @@ -21,18 +21,21 @@ final class WatchConnectivityManager: NSObject, WCSessionDelegate { func session(_ session: WCSession, didReceiveMessage message: [String: Any]) { if let newLayout = message["layout"] as? String { #if os(watchOS) - Task(priority: .userInitiated) { - let modelContext = ThemeData.context + Task(priority: .background) { let watchLayout = WatchLayout.shared watchLayout.update(from: newLayout) + LocationManager.shared.enabled = watchLayout.locationEnabled + let modelContext = ThemeData.context watchLayout.saveDefault(context: modelContext) try? modelContext.save() - LocationManager.shared.enabled = watchLayout.locationEnabled } #endif } else if let request = message["request"] as? String, request == "layout" { #if os(iOS) - self.sendLayout(WatchLayout.shared.encode(includeOffset: false)) + let watchLayout = WatchLayout.shared + if watchLayout.initialized { + sendLayout(watchLayout.encode(includeOffset: false)) + } #endif } } diff --git a/Watch/Views/ContentView.swift b/Watch/Views/ContentView.swift index 5d934e7..846deb8 100644 --- a/Watch/Views/ContentView.swift +++ b/Watch/Views/ContentView.swift @@ -25,7 +25,7 @@ struct WatchFaceTab: View { Setting() } } - .tabViewStyle(VerticalPageTabViewStyle(transitionStyle: .identity)) + .tabViewStyle(VerticalPageTabViewStyle(transitionStyle: .blur)) .onAppear { watchSetting.size = proxy.size }