diff --git a/DarockBili Watch App/DarockBiliApp.swift b/DarockBili Watch App/DarockBiliApp.swift index 6ad54d033..d8d4546a2 100644 --- a/DarockBili Watch App/DarockBiliApp.swift +++ b/DarockBili Watch App/DarockBiliApp.swift @@ -49,6 +49,7 @@ struct DarockBili_Watch_AppApp: App { @WKApplicationDelegateAdaptor(AppDelegate.self) var appDelegate @Environment(\.scenePhase) var scenePhase // Screen Time + @AppStorage("IsScreenTimeEnabled") var isScreenTimeEnabled = true @State var screenTimeCaculateTimer: Timer? = nil @State var isMemoryWarningPresented = false @State var showTipText = "" @@ -63,7 +64,6 @@ struct DarockBili_Watch_AppApp: App { @State var isShowMemoryUsage = false var body: some Scene { WindowGroup { - if UserDefaults.standard.string(forKey: "NewSignalError") ?? "" != "" { SignalErrorView() } else { @@ -215,7 +215,6 @@ struct DarockBili_Watch_AppApp: App { .onChange(of: scenePhase) { value in switch value { case .background: - //screenTimeCaculateTimer?.invalidate() break case .inactive: break @@ -223,16 +222,17 @@ struct DarockBili_Watch_AppApp: App { updateBuvid() WKInterfaceDevice.current().isBatteryMonitoringEnabled = true - if screenTimeCaculateTimer == nil { - Timer.scheduledTimer(withTimeInterval: 1, repeats: true) { timer in - screenTimeCaculateTimer = timer - let df = DateFormatter() - df.dateFormat = "yyyy-MM-dd" - let dateStr = df.string(from: Date.now) - UserDefaults.standard.set(UserDefaults.standard.integer(forKey: "ScreenTime\(dateStr)") + 1, forKey: "ScreenTime\(dateStr)") + + if isScreenTimeEnabled { + if screenTimeCaculateTimer == nil { + Timer.scheduledTimer(withTimeInterval: 1, repeats: true) { timer in + screenTimeCaculateTimer = timer + let df = DateFormatter() + df.dateFormat = "yyyy-MM-dd" + let dateStr = df.string(from: Date.now) + UserDefaults.standard.set(UserDefaults.standard.integer(forKey: "ScreenTime\(dateStr)") + 1, forKey: "ScreenTime\(dateStr)") + } } - } else { - //screenTimeCaculateTimer!.fire() } @unknown default: break diff --git a/DarockBili Watch App/Others/SettingsView.swift b/DarockBili Watch App/Others/SettingsView.swift index e07a82f08..f8be7f4e9 100644 --- a/DarockBili Watch App/Others/SettingsView.swift +++ b/DarockBili Watch App/Others/SettingsView.swift @@ -327,40 +327,62 @@ struct NetworkSettingsView: View { } struct ScreenTimeSettingsView: View { + @AppStorage("IsScreenTimeEnabled") var isScreenTimeEnabled = true @State var screenTimes = [Int]() @State var mainBarData = [SingleTimeBarMarkData]() @State var dayAverageTime = 0 // Minutes var body: some View { List { - Section { - VStack { - HStack { - Text("Screen-time.daily-average") - .font(.system(size: 14)) - .foregroundColor(.gray) - Spacer() - } - HStack { - Text("Screen-time.minutes.\(dayAverageTime)") - .font(.system(size: 20)) - Spacer() - } - Chart(mainBarData) { - BarMark( - x: .value("name", $0.name), - y: .value("time", $0.time) - ) -// RuleMark( -// y: .value("Highlight", dayAverageTime) -// ) -// .foregroundStyle(.green) - } - .chartYAxis { - AxisMarks(preset: .aligned, position: .trailing) { value in - AxisValueLabel("Screen-time.minutes.\(value.index)") + if isScreenTimeEnabled { + Section { + VStack { + HStack { + Text("Screen-time.daily-average") + .font(.system(size: 14)) + .foregroundColor(.gray) + Spacer() + } + HStack { + Text("Screen-time.minutes.\(dayAverageTime)") + .font(.system(size: 20)) + Spacer() + } + Chart(mainBarData) { + BarMark( + x: .value("name", $0.name), + y: .value("time", $0.time) + ) + // RuleMark( + // y: .value("Highlight", dayAverageTime) + // ) + // .foregroundStyle(.green) + } + .chartYAxis { + AxisMarks(preset: .aligned, position: .trailing) { value in + AxisValueLabel("Screen-time.minutes.\(value.index)") + } } } } + Section { + Button(role: .destructive, action: { + isScreenTimeEnabled = false + }, label: { + Text("关闭“屏幕使用时间”") + }) + } footer: { + Text("将不再记录您的屏幕使用时间, 已记录的数据不会被删除") + } + } else { + Section { + Button(action: { + isScreenTimeEnabled = true + }, label: { + Text("开启屏幕使用时间") + }) + } footer: { + Text("“屏幕使用时间”会记录您每天使用喵哩喵哩的时间并作出统计") + } } } .onAppear { diff --git a/DarockBili.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/DarockBili.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 3e389a431..4a0061db3 100644 --- a/DarockBili.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/DarockBili.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -113,8 +113,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/SDWebImage/SDWebImageWebPCoder", "state" : { - "revision" : "db4603921b31a6ce0f8c26d36d6a3fffc2dba481", - "version" : "0.14.2" + "revision" : "acfb824ca5cd9dbde2c43dc6b5a008c6757dee85", + "version" : "0.14.3" } }, { diff --git a/Localizable.xcstrings b/Localizable.xcstrings index cec7398ad..36df82eb2 100644 --- a/Localizable.xcstrings +++ b/Localizable.xcstrings @@ -80,6 +80,9 @@ } } } + }, + "“屏幕使用时间”会记录您每天使用喵哩喵哩的时间并作出统计" : { + }, "%@" : { "localizations" : { @@ -4179,6 +4182,9 @@ }, "令枫" : { + }, + "关闭“屏幕使用时间”" : { + }, "原神" : { "localizations" : { @@ -4205,6 +4211,12 @@ } } } + }, + "将不再记录您的屏幕使用时间, 已记录的数据不会被删除" : { + + }, + "开启屏幕使用时间" : { + }, "确认" : {