chore: update codegen cli and apollo version on iOS (#12879)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Added support for creating new documents from markdown and retrieving the current locale in the iOS app. - Introduced a shell script to automate Apollo iOS code generation tasks. - **Improvements** - Upgraded the Apollo iOS library to version 1.22.0 for improved performance and compatibility. - Enhanced metadata handling in the app to include document ID, workspace ID, server URL, and locale. - Improved JavaScript execution integration for document and workspace operations. - **Bug Fixes** - Fixed button appearance in the input bar by setting a static corner radius for the send button. - **Chores** - Removed unused dependencies and updated .gitignore entries for cleaner project management. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -14,7 +14,7 @@ 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/apollographql/apollo-ios.git", from: "1.22.0"),
|
||||
.package(url: "https://github.com/apple/swift-collections", from: "1.2.0"),
|
||||
.package(url: "https://github.com/devxoul/Then", from: "3.0.0"),
|
||||
.package(url: "https://github.com/SnapKit/SnapKit.git", from: "5.7.1"),
|
||||
|
||||
@@ -97,6 +97,7 @@ class InputBoxFunctionBar: UIView {
|
||||
make.width.height.equalTo(32)
|
||||
}
|
||||
}
|
||||
sendButton.layer.cornerRadius = 16
|
||||
updateColors()
|
||||
}
|
||||
|
||||
@@ -105,14 +106,6 @@ class InputBoxFunctionBar: UIView {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
override func layoutSubviews() {
|
||||
super.layoutSubviews()
|
||||
sendButton.layer.cornerRadius = sendButton.bounds.height / 2
|
||||
for button in [toolButton, networkButton, deepThinkingButton] {
|
||||
button.layer.cornerRadius = button.bounds.height / 2
|
||||
}
|
||||
}
|
||||
|
||||
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
|
||||
super.traitCollectionDidChange(previousTraitCollection)
|
||||
if traitCollection.hasDifferentColorAppearance(comparedTo: previousTraitCollection) {
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
//
|
||||
// ApplicationBridgedWindowScript.swift
|
||||
// App
|
||||
//
|
||||
// Created by 秋星桥 on 2025/1/8.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import WebKit
|
||||
|
||||
/*
|
||||
packages/frontend/apps/ios/src/app.tsx
|
||||
*/
|
||||
|
||||
enum BridgedWindowScript: 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: return true
|
||||
default: return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension WKWebView {
|
||||
func evaluateScript(_ script: BridgedWindowScript, 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) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,14 @@ public class IntelligentContext {
|
||||
|
||||
public var webView: WKWebView!
|
||||
|
||||
public private(set) var metadata: [MetadataKey: Any] = [:]
|
||||
public enum MetadataKey: String {
|
||||
case currentDocId
|
||||
case currentWorkspaceId
|
||||
case currentServerBaseUrl
|
||||
case currentI18nLocale
|
||||
}
|
||||
|
||||
public lazy var temporaryDirectory: URL = {
|
||||
let tempDir = FileManager.default.temporaryDirectory
|
||||
return tempDir.appendingPathComponent("IntelligentContext")
|
||||
@@ -25,7 +33,27 @@ public class IntelligentContext {
|
||||
public func preparePresent(_ completion: @escaping () -> Void) {
|
||||
DispatchQueue.global(qos: .userInitiated).async { [self] in
|
||||
prepareTemporaryDirectory()
|
||||
// TODO: used to gathering information, populate content from webview, etc.
|
||||
|
||||
let group = DispatchGroup()
|
||||
var newMetadata: [MetadataKey: Any] = [:]
|
||||
let keysAndScripts: [(MetadataKey, BridgedWindowScript)] = [
|
||||
(.currentDocId, .getCurrentDocId),
|
||||
(.currentWorkspaceId, .getCurrentWorkspaceId),
|
||||
(.currentServerBaseUrl, .getCurrentServerBaseUrl),
|
||||
(.currentI18nLocale, .getCurrentI18nLocale)
|
||||
]
|
||||
for (key, script) in keysAndScripts {
|
||||
DispatchQueue.main.async {
|
||||
self.webView.evaluateScript(script) { value in
|
||||
newMetadata[key] = value // if unable to fetch, clear it
|
||||
group.leave()
|
||||
}
|
||||
}
|
||||
group.enter()
|
||||
}
|
||||
self.metadata = newMetadata
|
||||
group.wait()
|
||||
print("IntelligentContext metadata prepared: \(self.metadata)")
|
||||
DispatchQueue.main.async {
|
||||
completion()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user