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:
Lakr 2025-06-20 19:03:16 +08:00 committed by GitHub
parent e978147a16
commit 10e981aa6d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 126 additions and 37 deletions

View File

@ -5,8 +5,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apollographql/apollo-ios",
"state" : {
"revision" : "9aa748d6f0526a744d49d59a2383dc7fdf9d645b",
"version" : "1.18.0"
"revision" : "39fea7617346c0731be25f61afd537e7032fb562",
"version" : "1.22.0"
}
},
{
@ -18,15 +18,6 @@
"version" : "5.7.1"
}
},
{
"identity" : "sqlite.swift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/stephencelis/SQLite.swift.git",
"state" : {
"revision" : "392dd6058624d9f6c5b4c769d165ddd8c7293394",
"version" : "0.15.4"
}
},
{
"identity" : "swift-collections",
"kind" : "remoteSourceControl",
@ -36,15 +27,6 @@
"version" : "1.2.0"
}
},
{
"identity" : "swift-toolchain-sqlite",
"kind" : "remoteSourceControl",
"location" : "https://github.com/swiftlang/swift-toolchain-sqlite",
"state" : {
"revision" : "b626d3002773b1a1304166643e7f118f724b2132",
"version" : "1.0.4"
}
},
{
"identity" : "swifterswift",
"kind" : "remoteSourceControl",

View File

@ -8,15 +8,21 @@
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: return true
case .getCurrentDocContentInMarkdown, .createNewDocByMarkdownInCurrentWorkspace: return true
default: return false
}
}

View File

@ -1 +1,2 @@
.build
apollo-ios-cli

View File

@ -14,7 +14,7 @@ let package = Package(
.library(name: "AffineGraphQL", targets: ["AffineGraphQL"]),
],
dependencies: [
.package(url: "https://github.com/apollographql/apollo-ios", exact: "1.18.0"),
.package(url: "https://github.com/apollographql/apollo-ios", exact: "1.22.0"),
],
targets: [
.target(

View File

@ -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"),

View File

@ -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) {

View File

@ -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) }
}
}
}

View File

@ -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()
}

View File

@ -0,0 +1,29 @@
#!/bin/zsh
cd "$(dirname "$0")"
set -euo pipefail
VERSION=$(grep -o 'apollo-ios", exact: "[^"]*"' "App/Packages/AffineGraphQL/Package.swift" | sed 's/.*exact: "\([^"]*\)".*/\1/')
[ -z "$VERSION" ] && { echo "❌ Failed to extract version"; exit 1; }
echo "📦 Apollo Version: $VERSION"
sed -i '' "s|apollo-ios\.git\", from: \"[^\"]*\"|apollo-ios.git\", from: \"$VERSION\"|" "App/Packages/Intelligents/Package.swift"
echo "✅ Version synced"
mkdir -p "App/Packages/AffineGraphQL/apollo-ios-cli"
curl -L "https://github.com/apollographql/apollo-ios/releases/download/$VERSION/apollo-ios-cli.tar.gz" | tar -xz -C "App/Packages/AffineGraphQL/apollo-ios-cli"
echo "✅ CLI downloaded"
CLI_BIN=$(find App/Packages/AffineGraphQL/apollo-ios-cli -type f -perm +111 -name 'apollo-ios-cli' | head -n 1)
[ -z "$CLI_BIN" ] && { echo "❌ apollo-ios-cli executable not found"; exit 1; }
echo "🔧 Using binary tool at: $CLI_BIN"
$CLI_BIN generate --path "apollo-codegen-config.json" --ignore-version-mismatch
echo "✅ Code generated"
rm -rf "App/Packages/AffineGraphQL/apollo-ios-cli"
echo "🧹 Cleaned up"

View File

@ -10,10 +10,7 @@ const PackageRoot = iosPackage.path;
console.log('[*] PackageRoot', PackageRoot);
console.log('[*] graphql...');
execSync(
`${PackageRoot}/App/Packages/AffineGraphQL/apollo-ios-cli generate --path ${PackageRoot}/apollo-codegen-config.json --ignore-version-mismatch`,
{ stdio: 'inherit' }
);
execSync(`${PackageRoot}/apollo-codegen-chore.sh`, { stdio: 'inherit' });
console.log('[*] rust...');
execSync(