Skip to content

Commit b4e3414

Browse files
committed
Initial commit
0 parents  commit b4e3414

83 files changed

Lines changed: 5043 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: iOS CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- master
8+
- develop
9+
pull_request:
10+
11+
jobs:
12+
build-and-test:
13+
runs-on: macos-14
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v4
17+
18+
- name: Set up Ruby
19+
uses: ruby/setup-ruby@v1
20+
with:
21+
ruby-version: 3.2
22+
bundler-cache: true
23+
24+
- name: Install SwiftLint
25+
run: brew install swiftlint
26+
27+
- name: Install dependencies
28+
run: bundle install
29+
30+
- name: Run Fastlane CI lane
31+
env:
32+
LC_ALL: en_US.UTF-8
33+
LANG: en_US.UTF-8
34+
run: bundle exec fastlane ci
35+
36+

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
*.DS_Store
2+
*.xcbkptlist
3+
*.xcuserstate
4+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"colors" : [
3+
{
4+
"idiom" : "universal"
5+
}
6+
],
7+
"info" : {
8+
"author" : "xcode",
9+
"version" : 1
10+
}
11+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
{
2+
"images" : [
3+
{
4+
"filename" : "_476a6b67-8167-4bf5-af60-36cad605a51d.jpeg",
5+
"idiom" : "universal",
6+
"platform" : "ios",
7+
"size" : "1024x1024"
8+
},
9+
{
10+
"idiom" : "mac",
11+
"scale" : "1x",
12+
"size" : "16x16"
13+
},
14+
{
15+
"idiom" : "mac",
16+
"scale" : "2x",
17+
"size" : "16x16"
18+
},
19+
{
20+
"idiom" : "mac",
21+
"scale" : "1x",
22+
"size" : "32x32"
23+
},
24+
{
25+
"idiom" : "mac",
26+
"scale" : "2x",
27+
"size" : "32x32"
28+
},
29+
{
30+
"idiom" : "mac",
31+
"scale" : "1x",
32+
"size" : "128x128"
33+
},
34+
{
35+
"idiom" : "mac",
36+
"scale" : "2x",
37+
"size" : "128x128"
38+
},
39+
{
40+
"idiom" : "mac",
41+
"scale" : "1x",
42+
"size" : "256x256"
43+
},
44+
{
45+
"idiom" : "mac",
46+
"scale" : "2x",
47+
"size" : "256x256"
48+
},
49+
{
50+
"idiom" : "mac",
51+
"scale" : "1x",
52+
"size" : "512x512"
53+
},
54+
{
55+
"idiom" : "mac",
56+
"scale" : "2x",
57+
"size" : "512x512"
58+
}
59+
],
60+
"info" : {
61+
"author" : "xcode",
62+
"version" : 1
63+
}
64+
}
65.9 KB
Loading

App/Assets.xcassets/Contents.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"info" : {
3+
"author" : "xcode",
4+
"version" : 1
5+
}
6+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//
2+
// ImageGroupView.swift
3+
// Smth
4+
//
5+
// Created by Tony Clark on 2023/10/15.
6+
//
7+
8+
import SwiftUI
9+
10+
struct ImageGroupView: View {
11+
12+
let attachments: [Attachment]
13+
14+
var body: some View {
15+
// GeometryReader { geometry in
16+
VStack (alignment: .leading) {
17+
let images = attachments.filter { attachment in
18+
return !attachment.id.isEmpty
19+
}
20+
ForEach(0..<(images.count + 2) / 3, id: \.self) { groupIndex in
21+
HStack {
22+
ForEach(0..<3, id: \.self) { itemIndex in
23+
let index = groupIndex * 3 + itemIndex
24+
if index < images.count {
25+
AsyncImage(url: URL.init(string: images[index].ks3Url ?? images[index].cdnUrl)) { image in
26+
image.resizable().aspectRatio(contentMode: .fill)
27+
.frame(width: 100, height: 80).clipped()
28+
} placeholder: {
29+
Image(systemName: "photo.fill").resizable().frame(width: 100, height: 80).clipped()
30+
}
31+
}
32+
}
33+
}
34+
}
35+
}
36+
// }
37+
}
38+
}

App/Components/WebView.swift

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
//
2+
// WebView.swift
3+
// Smth
4+
//
5+
// Created by Tony Clark on 2023/9/29.
6+
//
7+
8+
import SwiftUI
9+
import WebKit
10+
11+
#if os(iOS)
12+
typealias WebViewRepresentable = UIViewRepresentable
13+
#elseif os(macOS)
14+
typealias WebViewRepresentable = NSViewRepresentable
15+
#endif
16+
17+
struct WebView: WebViewRepresentable {
18+
19+
let url: URL
20+
let onComplete: () -> Void?
21+
// @Binding var isLoading: Bool
22+
// @Binding var error: Error?
23+
24+
func makeCoordinator() -> Coordinator {
25+
Coordinator(self)
26+
}
27+
#if os(iOS)
28+
func makeUIView(context: Context) -> WKWebView {
29+
makeView(context: context)
30+
}
31+
32+
func updateUIView(_ uiView: WKWebView, context: Context) {
33+
// This space is left intentionally blank.
34+
}
35+
#endif
36+
37+
#if os(macOS)
38+
public func makeNSView(context: Context) -> WKWebView {
39+
makeView(context: context)
40+
}
41+
42+
public func updateNSView(_ view: WKWebView, context: Context) {
43+
44+
}
45+
#endif
46+
47+
private func makeView(context: Context) -> WKWebView {
48+
let wkwebView = WKWebView()
49+
wkwebView.navigationDelegate = context.coordinator
50+
wkwebView.load(URLRequest(url: url))
51+
return wkwebView
52+
}
53+
54+
class Coordinator: NSObject, WKNavigationDelegate {
55+
var parent: WebView
56+
57+
init(_ parent: WebView) {
58+
self.parent = parent
59+
}
60+
61+
func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {
62+
//parent.isLoading = true
63+
}
64+
65+
func webView(_ webView: WKWebView, didCommit navigation: WKNavigation!) {
66+
//parent.isLoading = false
67+
}
68+
69+
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
70+
webView.evaluateJavaScript("document.cookie") { (result, error) in
71+
if let cookieString = result as? String {
72+
print("Cookies: \(cookieString)")
73+
// 在这里处理获取到的 Cookie
74+
}
75+
}
76+
}
77+
78+
func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction) async -> WKNavigationActionPolicy {
79+
let cookies = try? await WKWebsiteDataStore.default().httpCookieStore.allCookies()
80+
var isLoggedIn = false
81+
cookies?.forEach { cookie in
82+
HTTPCookieStorage.shared.setCookie(cookie)
83+
if cookie.name == "kbs-key" {
84+
isLoggedIn = true
85+
self.parent.onComplete()
86+
}
87+
}
88+
89+
if isLoggedIn {
90+
LoginState.shared.markLoggedIn()
91+
} else {
92+
LoginState.shared.markLoggedOut()
93+
}
94+
return .allow
95+
}
96+
97+
func webView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: Error) {
98+
print("loading error: \(error)")
99+
// parent.isLoading = false
100+
// parent.error = error
101+
}
102+
}
103+
}

0 commit comments

Comments
 (0)