Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

允许关闭屏幕使用时间 #105

Merged
merged 1 commit into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions DarockBili Watch App/DarockBiliApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
Expand All @@ -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 {
Expand Down Expand Up @@ -215,24 +215,24 @@ struct DarockBili_Watch_AppApp: App {
.onChange(of: scenePhase) { value in
switch value {
case .background:
//screenTimeCaculateTimer?.invalidate()
break
case .inactive:
break
case .active:
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
Expand Down
74 changes: 48 additions & 26 deletions DarockBili Watch App/Others/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
},
{
Expand Down
12 changes: 12 additions & 0 deletions Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@
}
}
}
},
"“屏幕使用时间”会记录您每天使用喵哩喵哩的时间并作出统计" : {

},
"%@" : {
"localizations" : {
Expand Down Expand Up @@ -4179,6 +4182,9 @@
},
"令枫" : {

},
"关闭“屏幕使用时间”" : {

},
"原神" : {
"localizations" : {
Expand All @@ -4205,6 +4211,12 @@
}
}
}
},
"将不再记录您的屏幕使用时间, 已记录的数据不会被删除" : {

},
"开启屏幕使用时间" : {

},
"确认" : {

Expand Down