mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-12 07:36:42 +08:00
7ac8b14b65
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Native/WASM Mermaid and Typst SVG preview rendering on desktop and mobile, plus cross-platform Preview plugin integrations. * **Improvements** * Centralized, sanitized rendering bridge with automatic Typst font-directory handling and configurable native renderer selection. * More consistent and robust error serialization and worker-backed preview flows for improved stability and performance. * **Tests** * Extensive unit and integration tests for preview rendering, font discovery, sanitization, and error serialization. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
79 lines
2.5 KiB
Swift
79 lines
2.5 KiB
Swift
import Capacitor
|
|
import Intelligents
|
|
import UIKit
|
|
|
|
class AFFiNEViewController: CAPBridgeViewController {
|
|
var intelligentsButton: IntelligentsButton?
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
webView?.allowsBackForwardNavigationGestures = true
|
|
navigationController?.navigationBar.isHidden = true
|
|
extendedLayoutIncludesOpaqueBars = false
|
|
edgesForExtendedLayout = []
|
|
let intelligentsButton = installIntelligentsButton()
|
|
intelligentsButton.delegate = self
|
|
self.intelligentsButton = intelligentsButton
|
|
dismissIntelligentsButton()
|
|
}
|
|
|
|
override func webViewConfiguration(for instanceConfiguration: InstanceConfiguration) -> WKWebViewConfiguration {
|
|
let configuration = super.webViewConfiguration(for: instanceConfiguration)
|
|
return configuration
|
|
}
|
|
|
|
override func webView(with frame: CGRect, configuration: WKWebViewConfiguration) -> WKWebView {
|
|
super.webView(with: frame, configuration: configuration)
|
|
}
|
|
|
|
override func capacitorDidLoad() {
|
|
let plugins: [CAPPlugin] = [
|
|
AuthPlugin(),
|
|
CookiePlugin(),
|
|
HashcashPlugin(),
|
|
NavigationGesturePlugin(),
|
|
NbStorePlugin(),
|
|
PayWallPlugin(associatedController: self),
|
|
PreviewPlugin(),
|
|
]
|
|
plugins.forEach { bridge?.registerPluginInstance($0) }
|
|
}
|
|
|
|
private var intelligentsButtonTimer: Timer?
|
|
private var isCheckingIntelligentEligibility = false
|
|
|
|
override func viewDidAppear(_ animated: Bool) {
|
|
super.viewDidAppear(animated)
|
|
IntelligentContext.shared.webView = webView
|
|
navigationController?.setNavigationBarHidden(false, animated: animated)
|
|
let timer = Timer.scheduledTimer(withTimeInterval: 3, repeats: true) { [weak self] _ in
|
|
self?.checkEligibilityOfIntelligent()
|
|
}
|
|
intelligentsButtonTimer = timer
|
|
RunLoop.main.add(timer, forMode: .common)
|
|
}
|
|
|
|
private func checkEligibilityOfIntelligent() {
|
|
guard !isCheckingIntelligentEligibility else { return }
|
|
assert(intelligentsButton != nil)
|
|
guard intelligentsButton?.isHidden ?? false else { return } // already eligible
|
|
isCheckingIntelligentEligibility = true
|
|
IntelligentContext.shared.webView = webView
|
|
IntelligentContext.shared.preparePresent { [self] result in
|
|
DispatchQueue.main.async {
|
|
defer { self.isCheckingIntelligentEligibility = false }
|
|
switch result {
|
|
case .failure: break
|
|
case .success:
|
|
self.presentIntelligentsButton()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
override func viewDidDisappear(_ animated: Bool) {
|
|
super.viewDidDisappear(animated)
|
|
intelligentsButtonTimer?.invalidate()
|
|
}
|
|
}
|