From 617f2631c7d7810b7322df03dd46e7ebf64969ef Mon Sep 17 00:00:00 2001 From: WindowsMEMZ Date: Sat, 30 Nov 2024 22:30:42 +0800 Subject: [PATCH] Update for Darock Browser Connectivity --- Localizable.xcstrings | 4 + MeowBili/InMain/ContentView.swift | 135 +++++++++++++++--------------- MeowBili/MeowBiliApp.swift | 91 +++++++------------- 3 files changed, 100 insertions(+), 130 deletions(-) diff --git a/Localizable.xcstrings b/Localizable.xcstrings index faf73aa60..696ee233a 100644 --- a/Localizable.xcstrings +++ b/Localizable.xcstrings @@ -9858,8 +9858,12 @@ } } } + }, + "在使用本 App 前,您需要先知晓以下信息:\n· 本 App 由第三方开发者以及部分社区用户贡献,与哔哩哔哩无合作关系,哔哩哔哩是上海宽娱数码科技有限公司的商标。\n· 本 App 并不是哔哩哔哩的替代品,我们建议您在能够使用官方客户端时尽量使用官方客户端。\n· 本 App 均使用来源于网络的公开信息进行开发。\n· 本 App 中和B站相关的功能完全免费\n· 本 App 中所呈现的B站内容来自哔哩哔哩官方。" : { + }, "在使用本 App 前,您需要先知晓以下信息:\n· 本 App 由第三方开发者以及部分社区用户贡献,与哔哩哔哩无合作关系,哔哩哔哩是上海宽娱数码科技有限公司的商标。\n· 本 App 并不是哔哩哔哩的替代品,我们建议您在能够使用官方客户端时尽量使用官方客户端。\n· 本 App 均使用来源于网络的公开信息进行开发。\n· 本 App 中和B站相关的功能完全免费\n· 本 App 中所呈现的B站内容来自哔哩哔哩官方。\n· 本 App 的开发者、负责人和实际责任人是%@\n 联系QQ:3245146430" : { + "extractionState" : "stale", "localizations" : { "en" : { "stringUnit" : { diff --git a/MeowBili/InMain/ContentView.swift b/MeowBili/InMain/ContentView.swift index b3fc49f48..5a1b81dad 100644 --- a/MeowBili/InMain/ContentView.swift +++ b/MeowBili/InMain/ContentView.swift @@ -41,83 +41,81 @@ struct ContentView: View { @State var isNewFeaturePresented = false @FocusState var isSearchKeyboardFocused: Bool var body: some View { - NavigationStack { - TabView(selection: $mainTabSelection.onUpdate { oldValue, newValue in - if oldValue == newValue && newValue == 4 { - isSearchKeyboardFocused = true - } - }) { - MainView(mainTabSelection: $mainTabSelection) + TabView(selection: $mainTabSelection.onUpdate { oldValue, newValue in + if oldValue == newValue && newValue == 4 { + isSearchKeyboardFocused = true + } + }) { + MainView(mainTabSelection: $mainTabSelection) #if !os(watchOS) - .toolbar { - ToolbarItem(placement: .topBarLeading) { - if dedeUserID != "" { - Button(action: { - mainTabSelection = 2 - }, label: { - WebImage(url: URL(string: userFaceUrl)) - .resizable() - .placeholder { - Circle() - .frame(width: 35, height: 35) - .redacted(reason: .placeholder) - } - .frame(width: 35, height: 35) - .clipShape(Circle()) - }) - .buttonStyle(.borderless) - } + .toolbar { + ToolbarItem(placement: .topBarLeading) { + if dedeUserID != "" { + Button(action: { + mainTabSelection = 2 + }, label: { + WebImage(url: URL(string: userFaceUrl)) + .resizable() + .placeholder { + Circle() + .frame(width: 35, height: 35) + .redacted(reason: .placeholder) + } + .frame(width: 35, height: 35) + .clipShape(Circle()) + }) + .buttonStyle(.borderless) } } + } #endif - .tag(1) - .tabItem { - Label("navbar.suggest", systemImage: "sparkles") - } - PersonAccountView() - .tag(2) - .tabItem { - Label("navbar.my", systemImage: "person.fill") - } - UserDynamicMainView() - .tag(3) - .tabItem { - Label("navbar.dynamic", systemImage: "rectangle.stack.fill") - } -#if !os(watchOS) - SearchMainView(isSearchKeyboardFocused: $isSearchKeyboardFocused) - .tag(4) - .tabItem { - Label("搜索", systemImage: "magnifyingglass") - } -#endif - } - .accessibility(identifier: "MainTabView") - #if os(watchOS) - .sheet(isPresented: $isAudioControllerPresented, content: { AudioControllerView() }) - .sheet(isPresented: $isNewFeaturePresented, onDismiss: { - isNewFeatureTipped = true - }, content: { NewFeaturesView() }) - #endif - .sheet(isPresented: $isTermsPresented, onDismiss: { - isReadTerms = true - }, content: { TermsListView() }) - .onAppear { -#if os(watchOS) - if !isNewFeatureTipped { - isNewFeaturePresented = true + .tag(1) + .tabItem { + Label("navbar.suggest", systemImage: "sparkles") } - if !isReadTerms { - isTermsPresented = true + PersonAccountView() + .tag(2) + .tabItem { + Label("navbar.my", systemImage: "person.fill") } - Timer.scheduledTimer(withTimeInterval: 0.5, repeats: true) { _ in - if pShouldPresentAudioController { - pShouldPresentAudioController = false - isAudioControllerPresented = true - } + UserDynamicMainView() + .tag(3) + .tabItem { + Label("navbar.dynamic", systemImage: "rectangle.stack.fill") } +#if !os(watchOS) + SearchMainView(isSearchKeyboardFocused: $isSearchKeyboardFocused) + .tag(4) + .tabItem { + Label("搜索", systemImage: "magnifyingglass") + } +#endif + } + .accessibility(identifier: "MainTabView") +#if os(watchOS) + .sheet(isPresented: $isAudioControllerPresented, content: { AudioControllerView() }) + .sheet(isPresented: $isNewFeaturePresented, onDismiss: { + isNewFeatureTipped = true + }, content: { NewFeaturesView() }) #endif + .sheet(isPresented: $isTermsPresented, onDismiss: { + isReadTerms = true + }, content: { TermsListView() }) + .onAppear { +#if os(watchOS) + if !isNewFeatureTipped { + isNewFeaturePresented = true + } + if !isReadTerms { + isTermsPresented = true } + Timer.scheduledTimer(withTimeInterval: 0.5, repeats: true) { _ in + if pShouldPresentAudioController { + pShouldPresentAudioController = false + isAudioControllerPresented = true + } + } +#endif } .onAppear { updateBiliTicket(csrf: biliJct) @@ -145,7 +143,6 @@ struct TermsListView: View { · 本 App 均使用来源于网络的公开信息进行开发。 · 本 App 中和B站相关的功能完全免费 · 本 App 中所呈现的B站内容来自哔哩哔哩官方。 - · 本 App 的开发者、负责人和实际责任人是\(Text("WindowsMEMZ").foregroundColor(Color.accentColor))\n 联系QQ:3245146430 """) Button(action: { isReadTerms = true diff --git a/MeowBili/MeowBiliApp.swift b/MeowBili/MeowBiliApp.swift index 5068fe896..e9d21d9a6 100644 --- a/MeowBili/MeowBiliApp.swift +++ b/MeowBili/MeowBiliApp.swift @@ -148,11 +148,7 @@ struct DarockBili_Watch_AppApp: App { @State var fileLockerInput = "" @State var recoveryCodeInput = "" // Navigators - @State var isUrlOpenVideoPresented = false - @State var urlOpenVideoDetails = [String: String]() - #if !os(watchOS) - @State var shouldShowAppName = false - #endif + @State var urlOpenVideoDetails: [String: String]? var body: some SwiftUI.Scene { WindowGroup { if fileLockerPwd != "" { @@ -192,8 +188,12 @@ struct DarockBili_Watch_AppApp: App { } } else { ZStack { - #if os(watchOS) - ContentView() + NavigationStack { + ContentView() + .navigationDestination(item: $urlOpenVideoDetails) { detail in + VideoDetailView(videoDetails: detail) + } + } if isReduceBrightness { Rectangle() .fill(Color.black) @@ -201,54 +201,6 @@ struct DarockBili_Watch_AppApp: App { .opacity(reduceBrightnessPercent) .allowsHitTesting(false) } - #else - NavigationStack { - ZStack { - // Hide NavigationLinks behind - NavigationLink("", isActive: $isUrlOpenVideoPresented, destination: { VideoDetailView(videoDetails: urlOpenVideoDetails) }) - ContentView() - } - } - .onOpenURL { url in - let dec = url.absoluteString.urlDecoded() - let spd = dec.split(separator: "/").dropFirst() - debugPrint(spd) - switch spd[1] { - case "withvideodetail": - let kvs = dec.split(separator: "/", maxSplits: 1).dropFirst()[2].split(separator: "&") // e.g.: ["BV=xxx", "Title=xxx"] - urlOpenVideoDetails.removeAll() - for kv in kvs { - let kav = kv.split(separator: "=") - urlOpenVideoDetails.updateValue(String(kav[1]), forKey: String(kav[0])) - } - isUrlOpenVideoPresented = true - case "openbvid": - let bvid = spd[2] - urlOpenVideoDetails = ["Pic": "", "Title": "Loading...", "BV": String(bvid), "UP": "Loading...", "View": "1", "Danmaku": "1"] - isUrlOpenVideoPresented = true - default: - break - } - } - if shouldShowAppName { - VStack { - Spacer() - .frame(height: 12) - ZStack { - Capsule() - .fill(Color.accentColor) - .frame(width: 60, height: 20) - HStack { - Text("喵哩喵哩") - .foregroundStyle(Color.white) - .font(.system(size: 12, weight: .medium)) - } - } - Spacer() - } - .ignoresSafeArea() - } - #endif } .blur(radius: isLuminanceReduced && blurWhenScreenSleep ? 12 : 0) .onAppear { @@ -361,9 +313,30 @@ struct DarockBili_Watch_AppApp: App { .onContinueUserActivity(NSUserActivityTypeBrowsingWeb) { activity in if let url = activity.webpageURL, let bvid = url.absoluteString.split(separator: "darock.top/meowbili/video/", maxSplits: 1)[from: 1] { urlOpenVideoDetails = ["Pic": "", "Title": "Loading...", "BV": String(bvid), "UP": "Loading...", "View": "1", "Danmaku": "1"] - isUrlOpenVideoPresented = true } } + #if os(iOS) + .onOpenURL { url in + let dec = url.absoluteString.urlDecoded() + let spd = dec.split(separator: "/").dropFirst() + debugPrint(spd) + switch spd[1] { + case "withvideodetail": + let kvs = dec.split(separator: "/", maxSplits: 1).dropFirst()[2].split(separator: "&") // e.g.: ["BV=xxx", "Title=xxx"] + var details = [String: String]() + for kv in kvs { + let kav = kv.split(separator: "=") + details.updateValue(String(kav[1]), forKey: String(kav[0])) + } + urlOpenVideoDetails = details + case "openbvid": + let bvid = spd[2] + urlOpenVideoDetails = ["Pic": "", "Title": "Loading...", "BV": String(bvid), "UP": "Loading...", "View": "1", "Danmaku": "1"] + default: + break + } + } + #endif } } .onChange(of: scenePhase) { @@ -371,9 +344,7 @@ struct DarockBili_Watch_AppApp: App { case .background: break case .inactive: - #if os(iOS) - shouldShowAppName = false - #endif + break case .active: SDImageCodersManager.shared.addCoder(SDImageWebPCoder.shared) SDImageCodersManager.shared.addCoder(SDImageSVGCoder.shared) @@ -388,8 +359,6 @@ struct DarockBili_Watch_AppApp: App { WKInterfaceDevice.current().isBatteryMonitoringEnabled = true #else InitHapticEngine() - - shouldShowAppName = true #endif if isScreenTimeEnabled {