mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 04:48:53 +00:00
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Introduced a chat interface with message list, empty state view, and support for user, assistant, and system messages. * Added a chat manager for session and message handling, including session creation, message sending, and error management. * Implemented various chat cell types (attachments, context references, workflow status, loading, and error cells) with corresponding data models and view models. * Enabled asynchronous message sending from the input box with error alerts and automatic session creation. * Added workflow and context-related models for advanced chat features. * **Enhancements** * Improved UI responsiveness with table view updates and dynamic empty state handling. * Provided a method to clear all attachments in the input box. * **Bug Fixes / Style** * Refined code formatting, access control, and minor stylistic improvements across multiple files for consistency. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
52 lines
1.4 KiB
Swift
52 lines
1.4 KiB
Swift
//
|
|
// ApplicationBridgedWindowScript.swift
|
|
// App
|
|
//
|
|
// Created by 秋星桥 on 2025/1/8.
|
|
//
|
|
|
|
import Foundation
|
|
import WebKit
|
|
|
|
/*
|
|
packages/frontend/apps/ios/src/app.tsx
|
|
*/
|
|
|
|
enum ApplicationBridgedWindowScript: String {
|
|
case getCurrentDocContentInMarkdown = "return await window.getCurrentDocContentInMarkdown();"
|
|
case getCurrentServerBaseUrl = "window.getCurrentServerBaseUrl()"
|
|
case getCurrentWorkspaceId = "window.getCurrentWorkspaceId();"
|
|
case getCurrentDocId = "window.getCurrentDocId();"
|
|
case getCurrentI18nLocale = "window.getCurrentI18nLocale();"
|
|
case createNewDocByMarkdownInCurrentWorkspace = "return await window.createNewDocByMarkdownInCurrentWorkspace(markdown, title);"
|
|
|
|
var requiresAsyncContext: Bool {
|
|
switch self {
|
|
case .getCurrentDocContentInMarkdown, .createNewDocByMarkdownInCurrentWorkspace: true
|
|
default: false
|
|
}
|
|
}
|
|
}
|
|
|
|
extension WKWebView {
|
|
func evaluateScript(_ script: ApplicationBridgedWindowScript, callback: @escaping (Any?) -> Void) {
|
|
if script.requiresAsyncContext {
|
|
callAsyncJavaScript(
|
|
script.rawValue,
|
|
arguments: [:],
|
|
in: nil,
|
|
in: .page
|
|
) { result in
|
|
switch result {
|
|
case let .success(input):
|
|
callback(input)
|
|
case .failure:
|
|
callback(nil)
|
|
}
|
|
}
|
|
} else {
|
|
evaluateJavaScript(script.rawValue) { output, _ in callback(output) }
|
|
}
|
|
}
|
|
}
|