mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-17 10:06:17 +08:00
9529adf33e
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * The "Intelligents" button is now only shown in debug builds; it will not appear in production versions. * **Bug Fixes** * Removed all references to the "Intelligents" plugin and related UI, ensuring a cleaner production app experience. * **Chores** * Cleaned up project settings and removed redundant or empty configuration entries. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
83 lines
2.7 KiB
Swift
83 lines
2.7 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(),
|
|
// IntelligentsPlugin(representController: self), // no longer put in use
|
|
NbStorePlugin(),
|
|
]
|
|
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:
|
|
#if DEBUG
|
|
// only show the button in debug mode before we get done
|
|
self.presentIntelligentsButton()
|
|
#else
|
|
break
|
|
#endif
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
override func viewDidDisappear(_ animated: Bool) {
|
|
super.viewDidDisappear(animated)
|
|
intelligentsButtonTimer?.invalidate()
|
|
}
|
|
}
|