Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions macos/Resources/Localizations/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"移到废纸篓" = "Move to Trash";
"复制到剪贴板" = "Copy to Clipboard";
"发给 %@" = "Send to %@";
"发给 Antigravity" = "Send to Antigravity";
"发给豆包" = "Send to Doubao";
"发给 WeSight" = "Send to WeSight";
"发给 DeepSeek Harness" = "Send to DeepSeek Harness";
Expand All @@ -43,6 +44,8 @@
"还没有添加自定义应用。" = "No custom apps added yet.";
"已取消" = "Cancelled";
"这条转发没有指定目标 App。" = "This forward has no target app.";
"聊天记录过长已截断,完整内容见:%@" = "Transcript truncated; full text saved at: %@";
"其余 %d 个附件已解压至:%@" = "%d additional attachments extracted to: %@";
"Codex" = "Codex";
"Claude" = "Claude";
"豆包" = "Doubao";
Expand Down Expand Up @@ -126,6 +129,7 @@
"只复制,不自动粘贴" = "Copies only; does not paste automatically";
"管理…" = "Manage…";
"入口没有出现在微信菜单里?" = "Entry missing from WeChat’s menu?";
"激活 Antigravity 并直接粘贴到输入框。" = "Brings Antigravity forward and pastes straight into its input.";
"激活 ChatGPT 并直接粘贴到输入框。" = "Brings ChatGPT forward and pastes straight into its input.";
"激活 Claude 并直接粘贴到输入框。" = "Brings Claude forward and pastes straight into its input.";
"激活豆包并直接粘贴到输入框。" = "Brings Doubao forward and pastes straight into its input.";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"移到废纸篓" = "移到废纸篓";
"复制到剪贴板" = "复制到剪贴板";
"发给 %@" = "发给 %@";
"发给 Antigravity" = "发给 Antigravity";
"发给豆包" = "发给豆包";
"发给 WeSight" = "发给 WeSight";
"发给 DeepSeek Harness" = "发给 DeepSeek Harness";
Expand All @@ -43,6 +44,8 @@
"还没有添加自定义应用。" = "还没有添加自定义应用。";
"已取消" = "已取消";
"这条转发没有指定目标 App。" = "这条转发没有指定目标 App。";
"聊天记录过长已截断,完整内容见:%@" = "聊天记录过长已截断,完整内容见:%@";
"其余 %d 个附件已解压至:%@" = "其余 %d 个附件已解压至:%@";
"Codex" = "Codex";
"Claude" = "Claude";
"豆包" = "豆包";
Expand Down Expand Up @@ -126,6 +129,7 @@
"只复制,不自动粘贴" = "只复制,不自动粘贴";
"管理…" = "管理…";
"入口没有出现在微信菜单里?" = "入口没有出现在微信菜单里?";
"激活 Antigravity 并直接粘贴到输入框。" = "激活 Antigravity 并直接粘贴到输入框。";
"激活 ChatGPT 并直接粘贴到输入框。" = "激活 ChatGPT 并直接粘贴到输入框。";
"激活 Claude 并直接粘贴到输入框。" = "激活 Claude 并直接粘贴到输入框。";
"激活豆包并直接粘贴到输入框。" = "激活豆包并直接粘贴到输入框。";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"CFBundleDisplayName" = "Send to Antigravity";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"CFBundleDisplayName" = "发给 Antigravity";
4 changes: 2 additions & 2 deletions macos/Scripts/check-release-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ plutil -lint "$APP_INFO" "$SHARE_INFO" "$APP_ENTITLEMENTS" "$SHARE_ENTITLEMENTS"
plutil -lint "$ROOT"/Resources/Localizations/*/*.strings "$ROOT"/Resources/ShareLocalizations/*/*/*.strings >/dev/null
python3 -m json.tool "$SHARED/Skills/catalog.json" >/dev/null

if [ "${#SHARE_SLOTS[@]}" -ne 12 ]; then
echo "expected 12 Share-menu entries, found ${#SHARE_SLOTS[@]}" >&2
if [ "${#SHARE_SLOTS[@]}" -ne 13 ]; then
echo "expected 13 Share-menu entries, found ${#SHARE_SLOTS[@]}" >&2
exit 1
fi

Expand Down
2 changes: 2 additions & 0 deletions macos/Scripts/share-slots.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ SHARE_SLOTS=(
"WorkBuddy|WeChatBridgeShareWorkBuddy|ShareWorkBuddy|workBuddy|发给 WorkBuddy"
"WeSight|WeChatBridgeShareWeSight|ShareWeSight|weSight|发给 WeSight"
"DeepSeekHarness|WeChatBridgeShareDeepSeekHarness|ShareDeepSeekHarness|deepSeekHarness|发给 DeepSeek Harness"
"Antigravity|WeChatBridgeShareAntigravity|ShareAntigravity|antigravity|发给 Antigravity"
"Obsidian|WeChatBridgeShareObsidian|ShareObsidian|obsidian|沉淀到 Obsidian"
"Collection|WeChatBridgeShareCollection|ShareCollection|collect|分批收集到微信流"
"Folder|WeChatBridgeShareFolder|ShareFolder|folder|沉淀到文件夹"
Expand All @@ -42,6 +43,7 @@ share_logo_name() {
QwenWork) printf '%s' "02-qwen.png" ;;
WorkBuddy) printf '%s' "06-workbuddy.png" ;;
WeSight) printf '%s' "07-wesight.png" ;;
Antigravity) printf '%s' "08-antigravity.png" ;;
Obsidian) printf '%s' "05-obsidian.png" ;;
esac
}
43 changes: 29 additions & 14 deletions macos/Sources/WeChatBridgeApp/ActionRunner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ final class ActionRunner {
// Nothing is shown: the share sheet said 「已复制到剪贴板」 a moment
// ago and is still on screen. A second capsule saying it again is
// WeChatBridge talking over the system.
case .codex, .claude, .doubao, .qwen, .workBuddy, .weSight, .deepSeekHarness, .obsidian, .folder, .custom:
case .antigravity, .codex, .claude, .doubao, .qwen, .workBuddy, .weSight, .deepSeekHarness, .obsidian, .folder, .custom:
// Shares and WeChat captures share the same clipboard queue.
//
// Read here rather than where the panel opens. This forward may wait
Expand Down Expand Up @@ -432,19 +432,34 @@ final class ActionRunner {
: skills.promptContext(agent: agent)
)
}
let prompt = doubaoReadsLocalArchive
? [
L10n.text("请直接读取并解压以下本机文件,使用其中的内容完成场景要求。"),
scenePrompt,
].compactMap { $0 }.joined(separator: "\n\n")
: scenePrompt
// The prompt, if 入口 attaches one: a first ⌘V before the files, or
// folded into the one line a terminal gets. See `PastePlan`.
let plan = PastePlan.make(
urls: promptURLs,
pathOnly: pathOnly,
prompt: prompt
)
let plan: [PastePayload]
if bundleIdentifier == ShareAction.antigravity.targetBundleIdentifier,
!configuredPathOnly,
arrival.urls.contains(where: { $0.pathExtension.lowercased() == "zip" }) {
let urls = arrival.urls
let extractedPlan = await Task.detached(priority: .userInitiated) {
AntigravityPayload.buildPlan(urls: urls, scenePrompt: scenePrompt)
}.value
plan = extractedPlan ?? PastePlan.make(
urls: arrival.urls,
pathOnly: false,
prompt: scenePrompt
)
} else {
let prompt = doubaoReadsLocalArchive
? [
L10n.text("请直接读取并解压以下本机文件,使用其中的内容完成场景要求。"),
scenePrompt,
].compactMap { $0 }.joined(separator: "\n\n")
: scenePrompt
// The prompt, if 入口 attaches one: a first ⌘V before the files, or
// folded into the one line a terminal gets. See `PastePlan`.
plan = PastePlan.make(
urls: promptURLs,
pathOnly: pathOnly,
prompt: prompt
)
}
// Written again here, not just in the extension: this is the process
// that is about to press ⌘V, so it owns what ⌘V will produce.
writePasteboard(plan)
Expand Down
2 changes: 1 addition & 1 deletion macos/Sources/WeChatBridgeApp/AppModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ final class AppModel: ObservableObject {
// Already copied, by the extension, and already recorded as
// such by `BatchState.initial`. Nothing left to do.
return false
case .codex, .claude, .doubao, .qwen, .workBuddy, .weSight, .deepSeekHarness, .obsidian, .folder, .custom:
case .antigravity, .codex, .claude, .doubao, .qwen, .workBuddy, .weSight, .deepSeekHarness, .obsidian, .folder, .custom:
// A forward whose one-shot request is already gone: the file was
// consumed by a run that then died before it could act, or the
// extension never managed to write it. Either way nothing can be
Expand Down
9 changes: 9 additions & 0 deletions macos/Sources/WeChatBridgeApp/AutoPaste.swift
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,15 @@ enum AutoPaste {
let application = AXUIElementCreateApplication(pid)
// The same one-second leash `restoreWindows` uses.
AXUIElementSetMessagingTimeout(application, 1)
if let focusedRef = attribute(application, kAXFocusedUIElementAttribute),
CFGetTypeID(focusedRef) == AXUIElementGetTypeID() {
let focused = focusedRef as! AXUIElement
let role = attribute(focused, kAXRoleAttribute) as? String
if (role == kAXTextAreaRole || role == kAXTextFieldRole),
(attribute(focused, kAXEnabledAttribute) as? Bool) ?? true {
return
}
}
guard let window = focusedWindow(of: application),
let field = editableElements(in: window)
.max(by: { $0.frame.maxY < $1.frame.maxY })?.element
Expand Down
1 change: 1 addition & 0 deletions macos/Sources/WeChatBridgeApp/ForwardTargets.swift
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ final class ForwardTargets: ObservableObject {
ForwardDestination(action: .workBuddy, target: nil),
ForwardDestination(action: .weSight, target: nil),
ForwardDestination(action: .deepSeekHarness, target: nil),
ForwardDestination(action: .antigravity, target: nil),
ForwardDestination(action: .obsidian, target: nil),
] + targets.map { ForwardDestination(action: .custom, target: $0) }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ struct ShareEntryList: View {
private static func bundledLogo(for action: ShareAction) -> NSImage? {
let file: String
switch action {
case .antigravity: file = "08-antigravity.png"
case .codex: file = "04-chatgpt.png"
case .claude: file = "03-claude.png"
case .doubao: file = "01-doubao.png"
Expand All @@ -187,7 +188,7 @@ struct ShareEntryList: View {
/// table of symbols would be a second answer to "which icon is this entry".
static func symbol(for action: ShareAction) -> String {
switch action {
case .codex, .claude, .doubao, .qwen, .workBuddy, .weSight, .deepSeekHarness: "paperplane"
case .antigravity, .codex, .claude, .doubao, .qwen, .workBuddy, .weSight, .deepSeekHarness: "paperplane"
case .obsidian: "book.closed"
case .collect: "tray.and.arrow.down"
case .folder: "folder"
Expand All @@ -199,7 +200,7 @@ struct ShareEntryList: View {
private func detail(for action: ShareAction) -> String {
if compactDetails {
switch action {
case .codex, .claude, .doubao, .qwen, .workBuddy, .weSight, .deepSeekHarness:
case .antigravity, .codex, .claude, .doubao, .qwen, .workBuddy, .weSight, .deepSeekHarness:
guard let bundleIdentifier = action.installedTargetBundleIdentifier else {
return L10n.text("未安装")
}
Expand All @@ -224,6 +225,7 @@ struct ShareEntryList: View {
}

switch action {
case .antigravity: return L10n.text("激活 Antigravity 并直接粘贴到输入框。")
case .codex: return L10n.text("激活 ChatGPT 并直接粘贴到输入框。")
case .claude: return L10n.text("激活 Claude 并直接粘贴到输入框。")
case .doubao: return L10n.text("激活豆包并直接粘贴到输入框。")
Expand All @@ -242,7 +244,7 @@ struct ShareEntryList: View {
private func detailIsWarning(for action: ShareAction) -> Bool {
guard compactDetails else { return false }
switch action {
case .codex, .claude, .doubao, .qwen, .workBuddy, .weSight, .deepSeekHarness:
case .antigravity, .codex, .claude, .doubao, .qwen, .workBuddy, .weSight, .deepSeekHarness:
return action.installedTargetBundleIdentifier.map {
!InstalledApp.lookup($0).isInstalled
} ?? true
Expand Down
170 changes: 170 additions & 0 deletions macos/Sources/WeChatBridgeCore/AntigravityPayload.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
import Foundation
import UniformTypeIdentifiers

/// Unpacks WeChat chat-archive ZIPs for Antigravity and produces a paste plan
/// with the chat transcript (and optional scene prompt) followed by the
/// extracted image files, so the user sees text + image attachments straight
/// inside the chat composer.
public enum AntigravityPayload {
public static let maxInlineImages = 10
public static let maxInlineCharacters = 20_000
private static let staleAge: TimeInterval = 24 * 60 * 60

public static func buildPlan(
urls: [URL],
scenePrompt: String?,
extractionRoot: URL = URL(fileURLWithPath: "/tmp/wxbridge/extracted", isDirectory: true),
maxInlineImages: Int = maxInlineImages,
maxInlineCharacters: Int = maxInlineCharacters
) -> [PastePayload]? {
guard !urls.isEmpty else { return nil }
let fileManager = FileManager.default
pruneStaleExtractions(in: extractionRoot, fileManager: fileManager)

let batchDir = makeBatchDirectory(for: urls, under: extractionRoot, fileManager: fileManager)
var transcripts: [String] = []
var transcriptURLs: [URL] = []
var imageURLs: [URL] = []
var otherFiles: [URL] = []

for (index, url) in urls.enumerated() {
if url.pathExtension.lowercased() == "zip" {
let subDir = urls.count == 1
? batchDir
: batchDir.appendingPathComponent("batch-\(index + 1)", isDirectory: true)
do {
try fileManager.createDirectory(at: subDir, withIntermediateDirectories: true)
let data = try Data(contentsOf: url, options: .mappedIfSafe)
let transcript = try? WeChatNativeArchive.transcript(data)
let extractedNames = try WeChatNativeArchive.extract(data, to: subDir)

if let transcript {
let trimmed = transcript.body.trimmingCharacters(in: .whitespacesAndNewlines)
if !trimmed.isEmpty {
transcripts.append(trimmed)
}
let txtURL = subDir.appendingPathComponent(transcript.path)
if fileManager.fileExists(atPath: txtURL.path) {
transcriptURLs.append(txtURL)
}
}

var archiveImages: [(name: String, url: URL)] = []
for name in extractedNames where name != transcript?.path {
let fileURL = subDir.appendingPathComponent(name)
if isImageFile(fileURL) {
archiveImages.append((name: name, url: fileURL))
} else {
otherFiles.append(fileURL)
}
}

let body = transcript?.body ?? ""
archiveImages.sort { lhs, rhs in
let lhsOrder = transcriptOrder(for: lhs.name, fileURL: lhs.url, in: body)
let rhsOrder = transcriptOrder(for: rhs.name, fileURL: rhs.url, in: body)
if lhsOrder != rhsOrder { return lhsOrder < rhsOrder }
return lhs.name < rhs.name
}
imageURLs.append(contentsOf: archiveImages.map(\.url))
} catch {
otherFiles.append(url)
}
} else if isImageFile(url) {
imageURLs.append(url)
} else {
otherFiles.append(url)
}
}

var textSections: [String] = []
if let prompt = scenePrompt?.trimmingCharacters(in: .whitespacesAndNewlines), !prompt.isEmpty {
textSections.append(prompt)
}

let combinedTranscript = transcripts.joined(separator: "\n\n---\n\n")
if !combinedTranscript.isEmpty {
if combinedTranscript.count > maxInlineCharacters {
textSections.append(String(combinedTranscript.prefix(maxInlineCharacters)) + "\n…")
if !transcriptURLs.isEmpty {
let paths = FilePasteboard.shellLine(for: transcriptURLs)
.trimmingCharacters(in: .whitespaces)
textSections.append(L10n.format("聊天记录过长已截断,完整内容见:%@", paths))
}
} else {
textSections.append(combinedTranscript)
}
}

let overflowImages = max(0, imageURLs.count - maxInlineImages)
let extraCount = overflowImages + otherFiles.count
if extraCount > 0 {
textSections.append(
L10n.format(
"其余 %d 个附件已解压至:%@",
extraCount,
FilePasteboard.shellQuoted(batchDir.path)
)
)
}

var payloads: [PastePayload] = []
let finalText = textSections.joined(separator: "\n\n")
if !finalText.isEmpty {
payloads.append(.text(finalText))
}
let inlineImages = Array(imageURLs.prefix(maxInlineImages))
if !inlineImages.isEmpty {
payloads.append(.files(inlineImages))
}
return payloads.isEmpty ? nil : payloads
}

private static func isImageFile(_ url: URL) -> Bool {
guard let type = UTType(filenameExtension: url.pathExtension) else { return false }
return type.conforms(to: .image)
}

private static func transcriptOrder(for name: String, fileURL: URL, in body: String) -> Int {
guard !body.isEmpty else { return Int.max }
let fileName = fileURL.lastPathComponent
if let range = body.range(of: fileName) ?? body.range(of: name) {
return body.distance(from: body.startIndex, to: range.lowerBound)
}
return Int.max
}

private static func makeBatchDirectory(
for urls: [URL],
under root: URL,
fileManager: FileManager
) -> URL {
let readyPrefix = urls.lazy.compactMap { url -> String? in
let components = url.pathComponents
guard let readyIndex = components.lastIndex(of: "Ready"),
components.indices.contains(readyIndex + 1) else { return nil }
let raw = components[readyIndex + 1].replacingOccurrences(of: "-", with: "")
return raw.isEmpty ? nil : String(raw.prefix(8))
}.first ?? "batch"
let unique = String(UUID().uuidString.replacingOccurrences(of: "-", with: "").prefix(6))
let directory = root.appendingPathComponent("\(readyPrefix)-\(unique)", isDirectory: true)
try? fileManager.createDirectory(at: directory, withIntermediateDirectories: true)
return directory
}

private static func pruneStaleExtractions(in root: URL, fileManager: FileManager) {
guard let children = try? fileManager.contentsOfDirectory(
at: root,
includingPropertiesForKeys: [.contentModificationDateKey],
options: [.skipsHiddenFiles]
) else { return }
let cutoff = Date().addingTimeInterval(-staleAge)
for child in children {
let modified = (try? child.resourceValues(forKeys: [.contentModificationDateKey]))?
.contentModificationDate ?? .distantPast
if modified < cutoff {
try? fileManager.removeItem(at: child)
}
}
}
}
2 changes: 1 addition & 1 deletion macos/Sources/WeChatBridgeCore/BatchState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public struct BatchState: Codable, Sendable, Hashable {
action: action,
targetName: targetName
)
case .collect, .codex, .claude, .doubao, .qwen, .workBuddy, .weSight, .deepSeekHarness, .obsidian, .folder, .custom:
case .collect, .antigravity, .codex, .claude, .doubao, .qwen, .workBuddy, .weSight, .deepSeekHarness, .obsidian, .folder, .custom:
return BatchState(outcome: nil, action: action, targetName: targetName)
}
}
Expand Down
Loading