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:
@@ -5,8 +5,8 @@
|
|||||||
"kind" : "remoteSourceControl",
|
"kind" : "remoteSourceControl",
|
||||||
"location" : "https://github.com/apollographql/apollo-ios",
|
"location" : "https://github.com/apollographql/apollo-ios",
|
||||||
"state" : {
|
"state" : {
|
||||||
"revision" : "9aa748d6f0526a744d49d59a2383dc7fdf9d645b",
|
"revision" : "39fea7617346c0731be25f61afd537e7032fb562",
|
||||||
"version" : "1.18.0"
|
"version" : "1.22.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -18,15 +18,6 @@
|
|||||||
"version" : "5.7.1"
|
"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",
|
"identity" : "swift-collections",
|
||||||
"kind" : "remoteSourceControl",
|
"kind" : "remoteSourceControl",
|
||||||
@@ -36,15 +27,6 @@
|
|||||||
"version" : "1.2.0"
|
"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",
|
"identity" : "swifterswift",
|
||||||
"kind" : "remoteSourceControl",
|
"kind" : "remoteSourceControl",
|
||||||
|
|||||||
@@ -8,15 +8,21 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
import WebKit
|
import WebKit
|
||||||
|
|
||||||
|
/*
|
||||||
|
packages/frontend/apps/ios/src/app.tsx
|
||||||
|
*/
|
||||||
|
|
||||||
enum ApplicationBridgedWindowScript: String {
|
enum ApplicationBridgedWindowScript: String {
|
||||||
case getCurrentDocContentInMarkdown = "return await window.getCurrentDocContentInMarkdown();"
|
case getCurrentDocContentInMarkdown = "return await window.getCurrentDocContentInMarkdown();"
|
||||||
case getCurrentServerBaseUrl = "window.getCurrentServerBaseUrl()"
|
case getCurrentServerBaseUrl = "window.getCurrentServerBaseUrl()"
|
||||||
case getCurrentWorkspaceId = "window.getCurrentWorkspaceId();"
|
case getCurrentWorkspaceId = "window.getCurrentWorkspaceId();"
|
||||||
case getCurrentDocId = "window.getCurrentDocId();"
|
case getCurrentDocId = "window.getCurrentDocId();"
|
||||||
|
case getCurrentI18nLocale = "window.getCurrentI18nLocale();"
|
||||||
|
case createNewDocByMarkdownInCurrentWorkspace = "return await window.createNewDocByMarkdownInCurrentWorkspace(markdown, title);"
|
||||||
|
|
||||||
var requiresAsyncContext: Bool {
|
var requiresAsyncContext: Bool {
|
||||||
switch self {
|
switch self {
|
||||||
case .getCurrentDocContentInMarkdown: return true
|
case .getCurrentDocContentInMarkdown, .createNewDocByMarkdownInCurrentWorkspace: return true
|
||||||
default: return false
|
default: return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1 +1,2 @@
|
|||||||
.build
|
.build
|
||||||
|
apollo-ios-cli
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ let package = Package(
|
|||||||
.library(name: "AffineGraphQL", targets: ["AffineGraphQL"]),
|
.library(name: "AffineGraphQL", targets: ["AffineGraphQL"]),
|
||||||
],
|
],
|
||||||
dependencies: [
|
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: [
|
targets: [
|
||||||
.target(
|
.target(
|
||||||
|
|||||||
Binary file not shown.
@@ -14,7 +14,7 @@ let package = Package(
|
|||||||
],
|
],
|
||||||
dependencies: [
|
dependencies: [
|
||||||
.package(path: "../AffineGraphQL"),
|
.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/apple/swift-collections", from: "1.2.0"),
|
||||||
.package(url: "https://github.com/devxoul/Then", from: "3.0.0"),
|
.package(url: "https://github.com/devxoul/Then", from: "3.0.0"),
|
||||||
.package(url: "https://github.com/SnapKit/SnapKit.git", from: "5.7.1"),
|
.package(url: "https://github.com/SnapKit/SnapKit.git", from: "5.7.1"),
|
||||||
|
|||||||
@@ -97,6 +97,7 @@ class InputBoxFunctionBar: UIView {
|
|||||||
make.width.height.equalTo(32)
|
make.width.height.equalTo(32)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
sendButton.layer.cornerRadius = 16
|
||||||
updateColors()
|
updateColors()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,14 +106,6 @@ class InputBoxFunctionBar: UIView {
|
|||||||
fatalError("init(coder:) has not been implemented")
|
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?) {
|
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
|
||||||
super.traitCollectionDidChange(previousTraitCollection)
|
super.traitCollectionDidChange(previousTraitCollection)
|
||||||
if traitCollection.hasDifferentColorAppearance(comparedTo: 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 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 = {
|
public lazy var temporaryDirectory: URL = {
|
||||||
let tempDir = FileManager.default.temporaryDirectory
|
let tempDir = FileManager.default.temporaryDirectory
|
||||||
return tempDir.appendingPathComponent("IntelligentContext")
|
return tempDir.appendingPathComponent("IntelligentContext")
|
||||||
@@ -25,7 +33,27 @@ public class IntelligentContext {
|
|||||||
public func preparePresent(_ completion: @escaping () -> Void) {
|
public func preparePresent(_ completion: @escaping () -> Void) {
|
||||||
DispatchQueue.global(qos: .userInitiated).async { [self] in
|
DispatchQueue.global(qos: .userInitiated).async { [self] in
|
||||||
prepareTemporaryDirectory()
|
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 {
|
DispatchQueue.main.async {
|
||||||
completion()
|
completion()
|
||||||
}
|
}
|
||||||
|
|||||||
29
packages/frontend/apps/ios/apollo-codegen-chore.sh
Executable file
29
packages/frontend/apps/ios/apollo-codegen-chore.sh
Executable 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"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -10,10 +10,7 @@ const PackageRoot = iosPackage.path;
|
|||||||
console.log('[*] PackageRoot', PackageRoot);
|
console.log('[*] PackageRoot', PackageRoot);
|
||||||
|
|
||||||
console.log('[*] graphql...');
|
console.log('[*] graphql...');
|
||||||
execSync(
|
execSync(`${PackageRoot}/apollo-codegen-chore.sh`, { stdio: 'inherit' });
|
||||||
`${PackageRoot}/App/Packages/AffineGraphQL/apollo-ios-cli generate --path ${PackageRoot}/apollo-codegen-config.json --ignore-version-mismatch`,
|
|
||||||
{ stdio: 'inherit' }
|
|
||||||
);
|
|
||||||
|
|
||||||
console.log('[*] rust...');
|
console.log('[*] rust...');
|
||||||
execSync(
|
execSync(
|
||||||
|
|||||||
Reference in New Issue
Block a user