Skip to content

Commit

Permalink
visionOS Support & watchOS merging (#255)
Browse files Browse the repository at this point in the history
* Added visionOS target(non-buildable)

* Removed some data unused

* Merging code for watchOS into MeowBili folder
  • Loading branch information
WindowsMEMZ authored Feb 20, 2024
1 parent e9bf66c commit 1b2eaa2
Show file tree
Hide file tree
Showing 37 changed files with 1,325 additions and 57 deletions.
Binary file added Artwork/VisionAppIco-Back.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Artwork/VisionAppIco-Front.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
374 changes: 356 additions & 18 deletions DarockBili.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/Alamofire/Alamofire",
"state" : {
"revision" : "f82c23a8a7ef8dc1a49a8bfc6a96883e79121864",
"version" : "5.5.0"
"revision" : "3dc6a42c7727c49bf26508e29b0a0b35f9c7e1ad",
"version" : "5.8.1"
}
},
{
Expand Down Expand Up @@ -42,7 +42,7 @@
"location" : "https://github.com/Darock-Studio/DarockKit",
"state" : {
"branch" : "main",
"revision" : "eee2eb242a2008d628990cbdaf7ee27b400df2d9"
"revision" : "b4d26e8c8c37572708f2aa13eb6377c55f18dabc"
}
},
{
Expand Down Expand Up @@ -104,8 +104,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/SDWebImage/SDWebImage.git",
"state" : {
"revision" : "59730af512c06fb569c119d737df4c1c499e001d",
"version" : "5.18.10"
"revision" : "b11493f76481dff17ac8f45274a6b698ba0d3af5",
"version" : "5.18.11"
}
},
{
Expand Down Expand Up @@ -140,8 +140,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/SDWebImage/SDWebImageWebPCoder",
"state" : {
"revision" : "db4603921b31a6ce0f8c26d36d6a3fffc2dba481",
"version" : "0.14.2"
"revision" : "8a33fb3ca75a01267f775f891f7d61f675e95072",
"version" : "0.14.5"
}
},
{
Expand Down Expand Up @@ -176,8 +176,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/scinfu/SwiftSoup",
"state" : {
"revision" : "f83c097597094a04124eb6e0d1e894d24129af87",
"version" : "2.7.0"
"revision" : "1d39e56d364cba79ce43b341f9661b534cccb18d",
"version" : "2.7.1"
}
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"images" : [
{
"filename" : "VisionAppIco-Back.png",
"idiom" : "vision",
"scale" : "2x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"info" : {
"author" : "xcode",
"version" : 1
},
"layers" : [
{
"filename" : "Front.solidimagestacklayer"
},
{
"filename" : "Middle.solidimagestacklayer"
},
{
"filename" : "Back.solidimagestacklayer"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"images" : [
{
"filename" : "VisionAppIco-Front.png",
"idiom" : "vision",
"scale" : "2x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"images" : [
{
"idiom" : "vision",
"scale" : "2x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
31 changes: 31 additions & 0 deletions MeowBili/Bangumi/BangumiDetailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ import DarockKit
import Alamofire
import SwiftyJSON
import CachedAsyncImage
#if !os(visionOS)
import SDWebImageSwiftUI
#endif

struct BangumiDetailView: View {
public static var willPlayBangumiLink = ""
Expand Down Expand Up @@ -118,6 +120,7 @@ struct BangumiDetailView: View {
var body: some View {
VStack {
Spacer()
#if !os(visionOS)
WebImage(url: URL(string: bangumiData.cover + "@130w_180h")!, options: [.progressiveLoad, .scaleDownLargeImages])
.placeholder {
RoundedRectangle(cornerRadius: 13)
Expand All @@ -135,6 +138,34 @@ struct BangumiDetailView: View {
.onTapGesture {
isCoverImageViewPresented = true
}
#else
AsyncImage(url: URL(string: bangumiData.cover + "@130w_180h")!) { phase in
switch phase {
case .empty:
RoundedRectangle(cornerRadius: 13)
.frame(width: 65, height: 90)
.foregroundColor(Color(hex: 0x3D3D3D))
.redacted(reason: .placeholder)
case .success(let image):
image.resizable()
case .failure(let error):
RoundedRectangle(cornerRadius: 13)
.frame(width: 65, height: 90)
.foregroundColor(Color(hex: 0x3D3D3D))
.redacted(reason: .placeholder)
}
}
.scaledToFit()
.frame(width: 65, height: 90)
.cornerRadius(13)
.shadow(color: .black.opacity(0.5), radius: 5, x: 1, y: 2)
.offset(y: 8)
.sheet(isPresented: $isCoverImageViewPresented, content: {ImageViewerView(url: bangumiData.cover)})
.onTapGesture {
isCoverImageViewPresented = true
}
#endif

Spacer()
.frame(height: 20)
Marquee {
Expand Down
2 changes: 2 additions & 0 deletions MeowBili/Errors/NetwokFixView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,9 @@ public func CheckBApiError(from input: JSON, noTip: Bool = false) -> Bool {
}
let msg = errorCodeTextDic[code] ?? (input["message"].string ?? "")
if !noTip {
#if !os(visionOS)
AlertKitAPI.present(title: msg, icon: .error, style: .iOS17AppleMusic, haptic: .error)
#endif
}
return false
}
Expand Down
89 changes: 89 additions & 0 deletions MeowBili/Extension/UIExt.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,17 @@ import SwiftUI
import DarockKit
import Alamofire
import Foundation
#if !os(visionOS)
import SDWebImageSwiftUI
#endif
import MobileCoreServices
import AuthenticationServices

@ViewBuilder func VideoCard(_ videoDetails: [String: String], onAppear: @escaping () -> Void = {}) -> some View {
NavigationLink(destination: {VideoDetailView(videoDetails: videoDetails).onAppear { onAppear() }}, label: {
VStack {
HStack {
#if !os(visionOS)
WebImage(url: URL(string: videoDetails["Pic"]! + "@200w")!, options: [.progressiveLoad, .scaleDownLargeImages])
.placeholder {
RoundedRectangle(cornerRadius: 7)
Expand All @@ -41,6 +44,27 @@ import AuthenticationServices
.scaledToFit()
.frame(width: 100)
.cornerRadius(7)
#else
AsyncImage(url: URL(string: videoDetails["Pic"]! + "@200w")!) { phase in
switch phase {
case .empty:
RoundedRectangle(cornerRadius: 7)
.frame(width: 100, height: 60)
.foregroundColor(Color(hex: 0x3D3D3D))
.redacted(reason: .placeholder)
case .success(let image):
image.resizable()
case .failure(let error):
RoundedRectangle(cornerRadius: 7)
.frame(width: 100, height: 60)
.foregroundColor(Color(hex: 0x3D3D3D))
.redacted(reason: .placeholder)
}
}
.scaledToFit()
.frame(width: 100)
.cornerRadius(7)
#endif
Text(videoDetails["Title"]!)
.font(.system(size: 14, weight: .bold))
.lineLimit(4)
Expand Down Expand Up @@ -88,17 +112,25 @@ import AuthenticationServices
if action == "Like" {
AF.request("https://api.bilibili.com/x/web-interface/archive/like", method: .post, parameters: ["bvid": videoDetails["BV"]!, "like": 1, "eab_x": 2, "ramval": 0, "source": "web_normal", "ga": 1, "csrf": biliJct], headers: headers).response { _ in
if items.count == 1 {
#if !os(visionOS)
AlertKitAPI.present(title: "已点赞", icon: .done, style: .iOS17AppleMusic, haptic: .success)
#endif
} else if item == items.last! {
#if !os(visionOS)
AlertKitAPI.present(title: "已完成\(items.count)项操作", icon: .done, style: .iOS17AppleMusic, haptic: .success)
#endif
}
}
} else if action == "Coin" {
AF.request("https://api.bilibili.com/x/web-interface/coin/add", method: .post, parameters: BiliVideoCoin(bvid: videoDetails["BV"]!, multiply: 1, csrf: biliJct), headers: headers).response { _ in
if items.count == 1 {
#if !os(visionOS)
AlertKitAPI.present(title: "已投币", icon: .done, style: .iOS17AppleMusic, haptic: .success)
#endif
} else if item == items.last! {
#if !os(visionOS)
AlertKitAPI.present(title: "已完成\(items.count)项操作", icon: .done, style: .iOS17AppleMusic, haptic: .success)
#endif
}
}
} else if action == "Favorite" {
Expand All @@ -108,9 +140,13 @@ import AuthenticationServices
if !CheckBApiError(from: respJson) { return }
AF.request("https://api.bilibili.com/x/v3/fav/resource/deal", method: .post, parameters: ["rid": avid, "type": 2, "add_media_ids": respJson["data"]["list"][0]["id"].int ?? 0, "csrf": biliJct], headers: headers).response { _ in
if items.count == 1 {
#if !os(visionOS)
AlertKitAPI.present(title: "已收藏", icon: .done, style: .iOS17AppleMusic, haptic: .success)
#endif
} else if item == items.last! {
#if !os(visionOS)
AlertKitAPI.present(title: "已完成\(items.count)项操作", icon: .done, style: .iOS17AppleMusic, haptic: .success)
#endif
}
}
}
Expand All @@ -128,6 +164,7 @@ import AuthenticationServices
NavigationLink(destination: {BangumiDetailView(bangumiData: bangumiData)}, label: {
VStack {
HStack {
#if !os(visionOS)
WebImage(url: URL(string: bangumiData.cover + "@100w")!, options: [.progressiveLoad, .scaleDownLargeImages])
.placeholder {
RoundedRectangle(cornerRadius: 7)
Expand All @@ -139,6 +176,27 @@ import AuthenticationServices
.scaledToFit()
.frame(width: 50)
.cornerRadius(7)
#else
AsyncImage(url: URL(string: bangumiData.cover + "@100w")!) { phase in
switch phase {
case .empty:
RoundedRectangle(cornerRadius: 7)
.frame(width: 50, height: 30)
.foregroundColor(Color(hex: 0x3D3D3D))
.redacted(reason: .placeholder)
case .success(let image):
image.resizable()
case .failure(let error):
RoundedRectangle(cornerRadius: 7)
.frame(width: 50, height: 30)
.foregroundColor(Color(hex: 0x3D3D3D))
.redacted(reason: .placeholder)
}
}
.scaledToFit()
.frame(width: 50)
.cornerRadius(7)
#endif
Text(bangumiData.title)
.font(.system(size: 14, weight: .bold))
.lineLimit(2)
Expand Down Expand Up @@ -170,6 +228,7 @@ import AuthenticationServices
NavigationLink(destination: {LiveDetailView(liveDetails: liveDetails)}, label: {
VStack {
HStack {
#if !os(visionOS)
WebImage(url: URL(string: liveDetails["Cover"]! + "@100w")!, options: [.progressiveLoad, .scaleDownLargeImages])
.placeholder {
RoundedRectangle(cornerRadius: 7)
Expand All @@ -181,6 +240,27 @@ import AuthenticationServices
.scaledToFit()
.frame(width: 50)
.cornerRadius(7)
#else
AsyncImage(url: URL(string: liveDetails["Cover"]! + "@100w")!) { phase in
switch phase {
case .empty:
RoundedRectangle(cornerRadius: 7)
.frame(width: 50, height: 30)
.foregroundColor(Color(hex: 0x3D3D3D))
.redacted(reason: .placeholder)
case .success(let image):
image.resizable()
case .failure(let error):
RoundedRectangle(cornerRadius: 7)
.frame(width: 50, height: 30)
.foregroundColor(Color(hex: 0x3D3D3D))
.redacted(reason: .placeholder)
}
}
.scaledToFit()
.frame(width: 50)
.cornerRadius(7)
#endif
Text(liveDetails["Title"]!)
.font(.system(size: 14, weight: .bold))
.lineLimit(2)
Expand Down Expand Up @@ -231,8 +311,13 @@ import AuthenticationServices
.foregroundColor(.gray)
}
}
#if !os(visionOS)
WebImage(url: URL(string: article["Pic"]! + "@100w"), options: [.progressiveLoad])
.cornerRadius(4)
#else
AsyncImage(url: URL(string: article["Pic"]! + "@100w"))
.cornerRadius(4)
#endif
}
}
})
Expand Down Expand Up @@ -269,6 +354,7 @@ struct zoomable: ViewModifier {
}
}

#if !os(visionOS)
extension Indicator where T == ProgressView<EmptyView, EmptyView> {
static var activity: Indicator {
Indicator { isAnimating, progress in
Expand All @@ -282,6 +368,7 @@ extension Indicator where T == ProgressView<EmptyView, EmptyView> {
}
}
}
#endif

struct UIImageTransfer: Transferable {
let image: UIImage
Expand Down Expand Up @@ -345,7 +432,9 @@ struct CopyableView<V: View>: View {
.contextMenu {
Button(action: {
UIPasteboard.general.string = content
#if !os(visionOS)
AlertKitAPI.present(title: "已复制", subtitle: "简介内容已复制到剪贴板", icon: .done, style: .iOS17AppleMusic, haptic: .success)
#endif
}, label: {
Label("复制", systemImage: "doc.on.doc")
})
Expand Down
Loading

0 comments on commit 1b2eaa2

Please sign in to comment.