mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-17 18:16:15 +08:00
feat(ios): intelligent Switch Markdown View & Ephemeral Action View (#9823)
Co-authored-by: EYHN <cneyhn@gmail.com>
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
//
|
||||
// ApplicationBridgedWindowScript.swift
|
||||
// App
|
||||
//
|
||||
// Created by 秋星桥 on 2025/1/8.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import WebKit
|
||||
|
||||
enum ApplicationBridgedWindowScript: String {
|
||||
case getCurrentDocContentInMarkdown = "return await window.getCurrentDocContentInMarkdown();"
|
||||
case getCurrentServerBaseUrl = "window.getCurrentServerBaseUrl()"
|
||||
case getCurrentWorkspaceId = "window.getCurrentWorkspaceId();"
|
||||
case getCurrentDocId = "window.getCurrentDocId();"
|
||||
|
||||
var requiresAsyncContext: Bool {
|
||||
switch self {
|
||||
case .getCurrentDocContentInMarkdown: return true
|
||||
default: return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension WKWebView {
|
||||
func evaluateScript(_ script: ApplicationBridgedWindowScript, callback: @escaping (Any?) -> ()) {
|
||||
if script.requiresAsyncContext {
|
||||
callAsyncJavaScript(
|
||||
script.rawValue,
|
||||
arguments: [:],
|
||||
in: nil,
|
||||
in: .page
|
||||
) { result in
|
||||
switch result {
|
||||
case .success(let input):
|
||||
callback(input)
|
||||
case .failure:
|
||||
callback(nil)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
evaluateJavaScript(script.rawValue) { output, _ in callback(output) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user