Skip to content

Commit

Permalink
Updated some files
Browse files Browse the repository at this point in the history
  • Loading branch information
张柏睿 authored and 张柏睿 committed Nov 11, 2023
1 parent ccc1d85 commit 4df325c
Show file tree
Hide file tree
Showing 16 changed files with 761 additions and 197 deletions.
Binary file modified .DS_Store
Binary file not shown.
62 changes: 59 additions & 3 deletions DarockBili Watch App/DarockBiliApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,39 @@

import Darwin
import SwiftUI
import WatchKit
import DarockKit
import SDWebImage
import SDWebImagePDFCoder
import SDWebImageSVGCoder
import SDWebImageWebPCoder

//!!!: Debug Setting, Set false Before Release
let debug = false
var debug = false

var pShowTipText = ""
var pShowTipSymbol = ""
var pTipBoxOffset: CGFloat = 80

var isShowMemoryInScreen = false

var isInOfflineMode = false

var isInLowBatteryMode = false

@main
struct DarockBili_Watch_AppApp: App {
@WKApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
@Environment(\.scenePhase) var scenePhase
// Screen Time
@State var screenTimeCaculateTimer: Timer? = nil
@State var isMemoryWarningPresented = false
@State var showTipText = ""
@State var showTipSymbol = ""
@State var tipBoxOffset: CGFloat = 80
//Debug Controls
@State var isOfflineMode = false
@State var isLowBatteryMode = false
// Debug Controls
@State var isShowingDebugControls = false
@State var systemResourceRefreshTimer: Timer?
@State var memoryUsage: Float = 0.0
Expand All @@ -40,7 +50,11 @@ struct DarockBili_Watch_AppApp: App {
SignalErrorView()
} else {
ZStack {
ContentView()
if isOfflineMode {
OfflineMainView()
} else {
ContentView()
}
VStack {
Spacer()
if #available(watchOS 10, *) {
Expand Down Expand Up @@ -80,13 +94,19 @@ struct DarockBili_Watch_AppApp: App {
}
.sheet(isPresented: $isMemoryWarningPresented, content: {MemoryWarningView()})
.onAppear {
isInLowBatteryMode = UserDefaults.standard.bool(forKey: "IsInLowBatteryMode")

Timer.scheduledTimer(withTimeInterval: 0.05, repeats: true) { _ in
showTipText = pShowTipText
showTipSymbol = pShowTipSymbol
isLowBatteryMode = isInLowBatteryMode
UserDefaults.standard.set(isLowBatteryMode, forKey: "IsInLowBatteryMode")
Timer.scheduledTimer(withTimeInterval: 0.2, repeats: false) { timer in
tipBoxOffset = pTipBoxOffset
timer.invalidate()
}

isOfflineMode = isInOfflineMode
}

Timer.scheduledTimer(withTimeInterval: 5.0, repeats: true) { timer in
Expand All @@ -105,8 +125,22 @@ struct DarockBili_Watch_AppApp: App {
timer.invalidate()
}
}

WKInterfaceDevice.current().isBatteryMonitoringEnabled = true
}
.overlay {
VStack {
HStack {
if isLowBatteryMode {
Image(systemName: "circle")
.font(.system(size: 17, weight: .heavy))
.foregroundColor(.accentColor)
.offset(y: 10)
}
}
Spacer()
}
.ignoresSafeArea()
if isShowMemoryUsage {
VStack {
HStack {
Expand Down Expand Up @@ -161,6 +195,28 @@ struct DarockBili_Watch_AppApp: App {
}
}
}
.onChange(of: scenePhase) { value in
switch value {
case .background:
screenTimeCaculateTimer?.invalidate()
case .inactive:
break
case .active:
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
10 changes: 9 additions & 1 deletion DarockBili Watch App/Errors/NetworkFixView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import DarockKit
import Foundation

struct NetworkFixView: View {
@Environment(\.dismiss) var dismiss
@State var fixingItem = ""
@State var isProgressAdding = true
@State var progressTimer: Timer?
Expand Down Expand Up @@ -50,6 +51,13 @@ struct NetworkFixView: View {
NavigationLink(destination: {UserNetworkGuide()}, label: {
Text("问题来自您的网络连接,点此查看网络说明")
})
Button(action: {
isInOfflineMode = true
dismiss()
}, label: {
Text("进入离线模式")
.foregroundColor(.blue)
})
}
}
if isDarockIssue {
Expand Down Expand Up @@ -81,7 +89,7 @@ struct NetworkFixView: View {
}
}
fixingItem = "检查:网络连接"
let randTime = Double.random(in: 3.5...7.0)
let randTime = Double.random(in: 2.5...5.0)
Timer.scheduledTimer(withTimeInterval: randTime, repeats: false) { timer in
timer.invalidate()

Expand Down
21 changes: 15 additions & 6 deletions DarockBili Watch App/InMain/MainView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ struct MainView: View {
@State var newMajorVer = ""
@State var newBuildVer = ""
@State var isLoadingNew = false
@State var isFailedToLoad = false
var body: some View {
Group {
List {
Expand All @@ -58,7 +59,8 @@ struct MainView: View {
.bold()
Button(action: {
//tipWithText("Test")
Dynamic.PUICApplication.sharedPUICApplication._setStatusBarTimeHidden(true, animated: false, completion: nil)
// Dynamic.PUICApplication.sharedPUICApplication._setStatusBarTimeHidden(true, animated: false, completion: nil)
Dynamic.WatchKit.sharedPUICApplication._setStatusBarTimeHidden(true, animated: false)
}, label: {
Text("Debug")
})
Expand Down Expand Up @@ -104,11 +106,15 @@ struct MainView: View {
Button(action: {
LoadNewVideos()
}, label: {
if !isLoadingNew {
Text("加载更多")
.bold()
if !isFailedToLoad {
if !isLoadingNew {
Text("加载更多")
.bold()
} else {
ProgressView()
}
} else {
ProgressView()
Label("加载失败 轻触重试", systemImage: "xmark")
}
})
}
Expand Down Expand Up @@ -140,10 +146,11 @@ struct MainView: View {

func LoadNewVideos(clearWhenFinish: Bool = false) {
isLoadingNew = true
isFailedToLoad = false
let headers: HTTPHeaders = [
"cookie": "SESSDATA=\(sessdata)"
]
DarockKit.Network.shared.requestString("https://api.darock.top/bili/wbi/sign/\("ps=30".base64Encoded())") { respStr, isSuccess in
DarockKit.Network.shared.requestString("https://api.darock.top/bili/wbi/sign/\("ps=\(isInLowBatteryMode ? 10 : 30)".base64Encoded())") { respStr, isSuccess in
if isSuccess {
debugPrint(respStr.apiFixed())
DarockKit.Network.shared.requestJSON("https://api.bilibili.com/x/web-interface/wbi/index/top/feed/rcmd?\(respStr.apiFixed())", headers: headers) { respJson, isSuccess in
Expand All @@ -158,10 +165,12 @@ struct MainView: View {
}
isLoadingNew = false
} else {
isFailedToLoad = true
isNetworkFixPresented = true
}
}
} else {
isFailedToLoad = true
isNetworkFixPresented = true
}
}
Expand Down
21 changes: 21 additions & 0 deletions DarockBili Watch App/Offline/OfflineMainView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// OfflineMainView.swift
// DarockBili Watch App
//
// Created by WindowsMEMZ on 2023/11/3.
//

import SwiftUI

struct OfflineMainView: View {
var body: some View {
TabView {
DownloadsView()
.tag(1)
}
}
}

#Preview {
OfflineMainView()
}
36 changes: 0 additions & 36 deletions DarockBili Watch App/Others/AboutView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,42 +38,6 @@ struct AboutView: View {
isEasterEgg2Presented = true
}
.sheet(isPresented: $isEasterEgg2Presented, content: {EasterEgg2View()})
Text("ReX")
.foregroundColor(rexEasterEggColor)
.onTapGesture {
if easterEggText == "继续?" || easterEggText == "不是这里!" {
rexEasterEggCount += 1
if rexEasterEggCount == 6 {
rexEasterEggColor = .red
} else if rexEasterEggCount == 7 {
rexEasterEggColor = .orange
} else if rexEasterEggCount == 8 {
rexEasterEggColor = .yellow
} else if rexEasterEggCount == 9 {
rexEasterEggColor = .green
} else if rexEasterEggCount == 10 {
rexEasterEggColor = .cyan
} else if rexEasterEggCount == 11 {
rexEasterEggColor = .blue
} else if rexEasterEggCount == 12 {
rexEasterEggColor = .purple
} else if rexEasterEggCount == 13 {
rexEasterEggColor = .white
isEasterEggPresented = true
}
}
debugPrint(rexEasterEggCount)
}
.sheet(isPresented: $isEasterEggPresented, content: {EasterEggView()})
Button(action: {
let session = ASWebAuthenticationSession(url: URL(string: "https://wear.rexwe.net")!, callbackURLScheme: nil) { _, _ in

}
session.prefersEphemeralWebBrowserSession = true
session.start()
}, label: {
Label("来自ReX的消息:界面与交互设计来自 腕上生花 - ReX Design(wear.rexwe.net)", systemImage: "arrowshape.up")
})
}
Section {
NavigationLink(destination: {OpenSource()}, label: {
Expand Down
Loading

0 comments on commit 4df325c

Please sign in to comment.