refactor: continue cleanup for 2.0

This commit is contained in:
Lakr
2025-06-16 16:50:40 +08:00
parent d3591dcdc1
commit 6d0516175d
14 changed files with 26 additions and 319 deletions
@@ -13,7 +13,6 @@
50802D612D112F8700694021 /* Intelligents in Frameworks */ = {isa = PBXBuildFile; productRef = 50802D602D112F8700694021 /* Intelligents */; };
50A285D72D112A5E000D5A6D /* Localizable.xcstrings in Resources */ = {isa = PBXBuildFile; fileRef = 50A285D62D112A5E000D5A6D /* Localizable.xcstrings */; };
50A285D82D112A5E000D5A6D /* InfoPlist.xcstrings in Resources */ = {isa = PBXBuildFile; fileRef = 50A285D52D112A5E000D5A6D /* InfoPlist.xcstrings */; };
50A285DC2D112B24000D5A6D /* Intelligents in Frameworks */ = {isa = PBXBuildFile; productRef = 50A285DB2D112B24000D5A6D /* Intelligents */; };
50FF428A2D2E757E0050AA83 /* ApplicationBridgedWindowScript.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50FF42892D2E757E0050AA83 /* ApplicationBridgedWindowScript.swift */; };
50FF428C2D2E77CC0050AA83 /* AffineViewController+AIButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50FF428B2D2E77CC0050AA83 /* AffineViewController+AIButton.swift */; };
9D52FC432D26CDBF00105D0A /* JSValueContainerExt.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9D52FC422D26CDB600105D0A /* JSValueContainerExt.swift */; };
@@ -88,7 +87,6 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
50A285DC2D112B24000D5A6D /* Intelligents in Frameworks */,
9DFCD1462D27D1D70028C92B /* libaffine_mobile_native.a in Frameworks */,
50802D612D112F8700694021 /* Intelligents in Frameworks */,
2E0DD47B57B994A104B25EED /* Pods_AFFiNE.framework in Frameworks */,
@@ -617,10 +615,6 @@
isa = XCSwiftPackageProductDependency;
productName = Intelligents;
};
50A285DB2D112B24000D5A6D /* Intelligents */ = {
isa = XCSwiftPackageProductDependency;
productName = Intelligents;
};
/* End XCSwiftPackageProductDependency section */
};
rootObject = 504EC2FC1FED79650016851F /* Project object */;
@@ -1,41 +0,0 @@
{
"pins" : [
{
"identity" : "apollo-ios",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apollographql/apollo-ios",
"state" : {
"revision" : "9aa748d6f0526a744d49d59a2383dc7fdf9d645b",
"version" : "1.18.0"
}
},
{
"identity" : "sqlite.swift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/stephencelis/SQLite.swift.git",
"state" : {
"revision" : "a95fc6df17d108bd99210db5e8a9bac90fe984b8",
"version" : "0.15.3"
}
},
{
"identity" : "swift-collections",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-collections",
"state" : {
"revision" : "c1805596154bb3a265fd91b8ac0c4433b4348fb0",
"version" : "1.2.0"
}
},
{
"identity" : "swift-eventsource",
"kind" : "remoteSourceControl",
"location" : "https://github.com/LaunchDarkly/swift-eventsource.git",
"state" : {
"revision" : "57051701c58a93603ffa2051f8e9cf0c8cff7814",
"version" : "3.3.0"
}
}
],
"version" : 2
}
@@ -3,19 +3,28 @@
{
"identity" : "apollo-ios",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apollographql/apollo-ios.git",
"location" : "https://github.com/apollographql/apollo-ios",
"state" : {
"revision" : "9aa748d6f0526a744d49d59a2383dc7fdf9d645b",
"version" : "1.18.0"
}
},
{
"identity" : "snapkit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/SnapKit/SnapKit.git",
"state" : {
"revision" : "2842e6e84e82eb9a8dac0100ca90d9444b0307f4",
"version" : "5.7.1"
}
},
{
"identity" : "sqlite.swift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/stephencelis/SQLite.swift.git",
"state" : {
"revision" : "a95fc6df17d108bd99210db5e8a9bac90fe984b8",
"version" : "0.15.3"
"revision" : "392dd6058624d9f6c5b4c769d165ddd8c7293394",
"version" : "0.15.4"
}
},
{
@@ -28,12 +37,12 @@
}
},
{
"identity" : "swift-eventsource",
"identity" : "swift-toolchain-sqlite",
"kind" : "remoteSourceControl",
"location" : "https://github.com/LaunchDarkly/swift-eventsource.git",
"location" : "https://github.com/swiftlang/swift-toolchain-sqlite",
"state" : {
"revision" : "57051701c58a93603ffa2051f8e9cf0c8cff7814",
"version" : "3.3.0"
"revision" : "b626d3002773b1a1304166643e7f118f724b2132",
"version" : "1.0.4"
}
}
],
@@ -5,11 +5,10 @@
// Created by on 2025/1/8.
//
import ChidoriMenu
import Intelligents
import UIKit
extension AFFiNEViewController: IntelligentsButtonDelegate, IntelligentsFocusApertureViewDelegate {
extension AFFiNEViewController: IntelligentsButtonDelegate {
func onIntelligentsButtonTapped(_ button: IntelligentsButton) {
guard let webView else {
assertionFailure() // ? wdym ?
@@ -18,110 +17,5 @@ extension AFFiNEViewController: IntelligentsButtonDelegate, IntelligentsFocusApe
button.beginProgress()
let group = DispatchGroup()
group.enter()
webView.evaluateScript(.getCurrentServerBaseUrl) { result in
self.baseUrl = result as? String
print("[*] setting baseUrl: \(self.baseUrl ?? "")")
group.leave()
}
group.enter()
webView.evaluateScript(.getCurrentDocId) { result in
self.documentID = result as? String
print("[*] setting documentID: \(self.documentID ?? "")")
group.leave()
}
group.enter()
webView.evaluateScript(.getCurrentWorkspaceId) { result in
self.workspaceID = result as? String
print("[*] setting workspaceID: \(self.workspaceID ?? "")")
group.leave()
}
group.enter()
webView.evaluateScript(.getCurrentDocContentInMarkdown) { input in
self.documentContent = input as? String
print("[*] setting documentContent: \(self.documentContent?.count ?? 0) chars")
group.leave()
}
DispatchQueue.global().asyncAfter(deadline: .now()) {
group.wait()
DispatchQueue.main.async {
button.stopProgress()
webView.resignFirstResponder()
self.openIntelligentsSheet()
}
}
}
@discardableResult
func openIntelligentsSheet() -> IntelligentsFocusApertureView? {
dismissIntelligentsButton()
view.resignFirstResponder()
// stop scroll on webview
if let contentOffset = webView?.scrollView.contentOffset {
webView?.scrollView.contentOffset = contentOffset
}
let focus = IntelligentsFocusApertureView()
focus.prepareAnimationWith(
capturingTargetContentView: webView ?? .init(),
coveringRootViewController: self
)
focus.delegate = self
focus.executeAnimationKickIn()
dismissIntelligentsButton()
return focus
}
func openSimpleChat() {
let targetController = IntelligentsChatController()
presentIntoCurrentContext(withTargetController: targetController)
}
func focusApertureRequestAction(
from view: IntelligentsFocusApertureView,
actionType: IntelligentsFocusApertureViewActionType
) {
switch actionType {
case .translateTo:
var actions: [UIAction] = []
for lang in IntelligentsEphemeralActionController.EphemeralAction.Language.allCases {
actions.append(.init(title: lang.rawValue) { [weak self] _ in
guard let self else { return }
let controller = IntelligentsEphemeralActionController(
action: .translate(to: lang)
)
controller.workspaceID = workspaceID ?? ""
controller.documentID = documentID ?? ""
controller.documentContent = documentContent ?? ""
controller.configure(previewImage: view.capturedImage ?? .init())
presentIntoCurrentContext(withTargetController: controller)
})
}
view.present(menu: .init(children: actions)) { controller in
controller.overrideUserInterfaceStyle = .dark
} controllerDidPresent: { _ in }
case .summary:
let controller = IntelligentsEphemeralActionController(
action: .summarize
)
controller.configure(previewImage: view.capturedImage ?? .init())
controller.workspaceID = workspaceID ?? ""
controller.documentID = documentID ?? ""
controller.documentContent = documentContent ?? ""
presentIntoCurrentContext(withTargetController: controller)
case .chatWithAI:
let controller = IntelligentsChatController()
controller.metadata[.documentID] = documentID
controller.metadata[.workspaceID] = workspaceID
controller.metadata[.content] = documentContent
presentIntoCurrentContext(withTargetController: controller)
case .dismiss:
presentIntelligentsButton()
}
}
}
@@ -3,13 +3,6 @@ import Intelligents
import UIKit
class AFFiNEViewController: CAPBridgeViewController {
var baseUrl: String? {
didSet { Intelligents.setUpstreamEndpoint(baseUrl ?? "") }
}
var documentID: String?
var workspaceID: String?
var documentContent: String?
override func viewDidLoad() {
super.viewDidLoad()
webView?.allowsBackForwardNavigationGestures = true
@@ -1711,6 +1711,7 @@ extension UniffiError: Equatable, Hashable {}
extension UniffiError: Foundation.LocalizedError {
public var errorDescription: String? {
String(reflecting: self)
@@ -1718,6 +1719,8 @@ extension UniffiError: Foundation.LocalizedError {
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
@@ -1,4 +1,7 @@
module affine_mobile_nativeFFI {
header "affine_mobile_nativeFFI.h"
export *
use "Darwin"
use "_Builtin_stdbool"
use "_Builtin_stdint"
}
@@ -1,14 +0,0 @@
{
"pins" : [
{
"identity" : "apollo-ios",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apollographql/apollo-ios.git",
"state" : {
"revision" : "6ecc75281dab2fa231cb0d5fed3a3713826fecae",
"version" : "1.21.0"
}
}
],
"version" : 2
}
@@ -1,31 +0,0 @@
// @generated
// This file was automatically generated and should not be edited.
@_exported import ApolloAPI
public struct License: AffineGraphQL.SelectionSet, Fragment {
public static var fragmentDefinition: StaticString {
#"fragment license on License { __typename expiredAt installedAt quantity recurring validatedAt variant }"#
}
public let __data: DataDict
public init(_dataDict: DataDict) { __data = _dataDict }
public static var __parentType: any ApolloAPI.ParentType { AffineGraphQL.Objects.License }
public static var __selections: [ApolloAPI.Selection] { [
.field("__typename", String.self),
.field("expiredAt", AffineGraphQL.DateTime?.self),
.field("installedAt", AffineGraphQL.DateTime.self),
.field("quantity", Int.self),
.field("recurring", GraphQLEnum<AffineGraphQL.SubscriptionRecurring>.self),
.field("validatedAt", AffineGraphQL.DateTime.self),
.field("variant", GraphQLEnum<AffineGraphQL.SubscriptionVariant>?.self),
] }
public var expiredAt: AffineGraphQL.DateTime? { __data["expiredAt"] }
public var installedAt: AffineGraphQL.DateTime { __data["installedAt"] }
public var quantity: Int { __data["quantity"] }
public var recurring: GraphQLEnum<AffineGraphQL.SubscriptionRecurring> { __data["recurring"] }
public var validatedAt: AffineGraphQL.DateTime { __data["validatedAt"] }
public var variant: GraphQLEnum<AffineGraphQL.SubscriptionVariant>? { __data["variant"] }
}
@@ -1,77 +0,0 @@
{
"pins" : [
{
"identity" : "apollo-ios",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apollographql/apollo-ios.git",
"state" : {
"revision" : "c3f48d45ec1300bc95243bf19f67284f9dc0d14a",
"version" : "1.15.3"
}
},
{
"identity" : "msdisplaylink",
"kind" : "remoteSourceControl",
"location" : "https://github.com/Lakr233/MSDisplayLink",
"state" : {
"revision" : "6e92b5513e3473e064685e64056c4ac46470e7b0",
"version" : "2.0.3"
}
},
{
"identity" : "networkimage",
"kind" : "remoteSourceControl",
"location" : "https://github.com/gonzalezreal/NetworkImage",
"state" : {
"revision" : "2849f5323265386e200484b0d0f896e73c3411b9",
"version" : "6.0.1"
}
},
{
"identity" : "springinterpolation",
"kind" : "remoteSourceControl",
"location" : "https://github.com/Lakr233/SpringInterpolation",
"state" : {
"revision" : "f9d1ee3d2466bdb00fd0ade7f256ed20229c8413",
"version" : "1.3.0"
}
},
{
"identity" : "sqlite.swift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/stephencelis/SQLite.swift.git",
"state" : {
"revision" : "a95fc6df17d108bd99210db5e8a9bac90fe984b8",
"version" : "0.15.3"
}
},
{
"identity" : "swift-cmark",
"kind" : "remoteSourceControl",
"location" : "https://github.com/swiftlang/swift-cmark",
"state" : {
"revision" : "3ccff77b2dc5b96b77db3da0d68d28068593fa53",
"version" : "0.5.0"
}
},
{
"identity" : "swift-eventsource",
"kind" : "remoteSourceControl",
"location" : "https://github.com/LaunchDarkly/swift-eventsource.git",
"state" : {
"revision" : "57051701c58a93603ffa2051f8e9cf0c8cff7814",
"version" : "3.3.0"
}
},
{
"identity" : "swift-markdown-ui",
"kind" : "remoteSourceControl",
"location" : "https://github.com/gonzalezreal/swift-markdown-ui",
"state" : {
"revision" : "5f613358148239d0292c0cef674a3c2314737f9e",
"version" : "2.4.1"
}
}
],
"version" : 2
}
@@ -15,14 +15,14 @@ let package = Package(
dependencies: [
.package(path: "../AffineGraphQL"),
.package(url: "https://github.com/apollographql/apollo-ios.git", from: "1.18.0"),
.package(url: "https://github.com/LaunchDarkly/swift-eventsource.git", from: "3.3.0"),
.package(url: "https://github.com/apple/swift-collections", from: "1.2.0"),
.package(url: "https://github.com/SnapKit/SnapKit.git", .upToNextMajor(from: "5.0.1"))
],
targets: [
.target(name: "Intelligents", dependencies: [
"AffineGraphQL",
"SnapKit",
.product(name: "Apollo", package: "apollo-ios"),
.product(name: "LDSwiftEventSource", package: "swift-eventsource"),
.product(name: "OrderedCollections", package: "swift-collections"),
]),
]
@@ -6,17 +6,6 @@ import Apollo
import Foundation
public enum Intelligents {
public private(set) static var qlClient: ApolloClient = createQlClient()
public static func setUpstreamEndpoint(_ upstream: String) {
guard let url = URL(string: upstream) else {
assertionFailure()
return
}
print("[*] setting up upstream endpoint to \(url.absoluteString)")
Constant.affineUpstreamURL = url
qlClient = createQlClient()
}
}
private extension Intelligents {
@@ -29,18 +18,4 @@ private extension Intelligents {
}
}
}
static func createQlClient() -> ApolloClient {
let store = ApolloStore(cache: InMemoryNormalizedCache())
let provider = DefaultInterceptorProvider(
client: URLSessionCookieClient(),
shouldInvalidateClientOnDeinit: true,
store: store
)
let transport = RequestChainNetworkTransport(
interceptorProvider: provider,
endpointURL: Constant.affineUpstreamURL.appendingPathComponent("graphql")
)
return .init(networkTransport: transport, store: store)
}
}
@@ -19,7 +19,7 @@ public extension UIViewController {
button.translatesAutoresizingMaskIntoConstraints = false
[
button.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor, constant: -20),
button.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor, constant: -20 - Constant.affineTabbarHeight),
button.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor, constant: -20 - 44),
button.widthAnchor.constraint(equalToConstant: 50),
button.heightAnchor.constraint(equalToConstant: 50),
].forEach { $0.isActive = true }
@@ -32,7 +32,6 @@ public class IntelligentsButton: UIView {
image.image = .init(named: "spark", in: .module, with: .none)
image.contentMode = .scaleAspectFit
image.tintColor = .accent
addSubview(image)
let imageInsetValue: CGFloat = 12
image.translatesAutoresizingMaskIntoConstraints = false