Skip to content
Merged
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
2 changes: 1 addition & 1 deletion macos/Sources/WeChatBridgeApp/ActionRunner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ final class ActionRunner {
// resolves one or stops — so reaching here means a build mismatch about
// the intent schema. The files are still on the clipboard, and saying so
// beats pretending an app is missing.
guard let bundleIdentifier = target?.bundleIdentifier ?? action.targetBundleIdentifier else {
guard let bundleIdentifier = target?.bundleIdentifier ?? action.installedTargetBundleIdentifier else {
fallBack(arrival, message: L10n.text("这条转发没有指定目标 App。"))
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ final class CollectionCoordinator: ObservableObject {
var destinations: [ForwardDestination] {
targets.destinations.filter { destination in
if destination.action == .obsidian { return preferences.obsidianVaultPath?.isEmpty == false }
guard let bundle = destination.target?.bundleIdentifier ?? destination.action.targetBundleIdentifier else { return false }
guard let bundle = destination.target?.bundleIdentifier ?? destination.action.installedTargetBundleIdentifier else { return false }
return InstalledApp.lookup(bundle).isInstalled
}
}
var chosenDestination: ForwardDestination? { destinations.first { $0.id == selection } }
var isFileDestination: Bool { selection == "copy" || selection == "folder" }
var scenes: [WeChatScene] {
guard !isFileDestination else { return [] }
let bundle = chosenDestination?.target?.bundleIdentifier ?? chosenDestination?.action.targetBundleIdentifier
let bundle = chosenDestination?.target?.bundleIdentifier ?? chosenDestination?.action.installedTargetBundleIdentifier
let agent = bundle.flatMap(AgentID.matching(bundleIdentifier:))
return preferences.scenes.enabledScenes.filter { scene in agent.map { scene.compatibleAgents.contains($0) } ?? true }
}
Expand Down
9 changes: 9 additions & 0 deletions macos/Sources/WeChatBridgeApp/ForwardTargets.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ import UniformTypeIdentifiers
/// icon fetch; the settings pane asks for every row on every frame, so the
/// answer is remembered. Main-actor only, which is why the cache needs no lock.
@MainActor
extension ShareAction {
/// The bundle identifier to drive on this Mac: the first of
/// `targetBundleIdentifiers` that is installed, else the primary one so a
/// missing app still reads as 未安装 under its usual name.
var installedTargetBundleIdentifier: String? {
targetBundleIdentifiers.first { InstalledApp.lookup($0).isInstalled } ?? targetBundleIdentifier
}
}

struct InstalledApp {
let bundleIdentifier: String
/// Nil when the app is not on this Mac — the row then says 未安装 rather
Expand Down
3 changes: 2 additions & 1 deletion macos/Sources/WeChatBridgeApp/ShareEntryProbe.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ final class ShareEntryProbe: ObservableObject {
}

func installationFailure(for action: ShareAction) -> String? {
if let identifier = action.targetBundleIdentifier, !isAppInstalled(identifier) {
let identifiers = action.targetBundleIdentifiers
if !identifiers.isEmpty, !identifiers.contains(where: isAppInstalled) {
return L10n.format("请先安装 %@,再开启此入口。", action.targetDisplayName)
}
if action == .custom && !customTargets().contains(where: { isAppInstalled($0.bundleIdentifier) }) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ struct ShareEntryList: View {

@ViewBuilder
private func entryIcon(_ action: ShareAction) -> some View {
if let bundleIdentifier = action.targetBundleIdentifier,
if let bundleIdentifier = action.installedTargetBundleIdentifier,
InstalledApp.lookup(bundleIdentifier).isInstalled {
Image(nsImage: InstalledApp.lookup(bundleIdentifier).icon)
.resizable()
Expand Down Expand Up @@ -200,7 +200,7 @@ struct ShareEntryList: View {
if compactDetails {
switch action {
case .codex, .claude, .doubao, .qwen, .workBuddy, .weSight, .deepSeekHarness:
guard let bundleIdentifier = action.targetBundleIdentifier else {
guard let bundleIdentifier = action.installedTargetBundleIdentifier else {
return L10n.text("未安装")
}
return InstalledApp.lookup(bundleIdentifier).isInstalled
Expand Down Expand Up @@ -243,7 +243,7 @@ struct ShareEntryList: View {
guard compactDetails else { return false }
switch action {
case .codex, .claude, .doubao, .qwen, .workBuddy, .weSight, .deepSeekHarness:
return action.targetBundleIdentifier.map {
return action.installedTargetBundleIdentifier.map {
!InstalledApp.lookup($0).isInstalled
} ?? true
case .obsidian:
Expand Down
24 changes: 16 additions & 8 deletions macos/Sources/WeChatBridgeCore/AgentID.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,22 @@ public enum AgentID: String, Codable, CaseIterable, Hashable, Identifiable, Send
}
}

public var bundleIdentifier: String {
/// The primary bundle identifier. See `bundleIdentifiers` for every
/// identifier the same agent ships under.
public var bundleIdentifier: String { bundleIdentifiers[0] }

/// Every bundle identifier this agent is known to ship under, primary first.
/// WorkBuddy has two: the WeChat-distributed build is
/// `com.tencent.workbuddy.mac`, the public download is
/// `com.workbuddy.workbuddy` (issue #44).
public var bundleIdentifiers: [String] {
switch self {
case .chatGPTCodex: return "com.openai.codex"
case .claude: return "com.anthropic.claudefordesktop"
case .doubao: return "com.bot.pc.doubao"
case .qwenWork: return "com.alibaba.qwenwork"
case .workBuddy: return "com.tencent.workbuddy.mac"
case .weSight: return "ai.wesight.app"
case .chatGPTCodex: return ["com.openai.codex"]
case .claude: return ["com.anthropic.claudefordesktop"]
case .doubao: return ["com.bot.pc.doubao"]
case .qwenWork: return ["com.alibaba.qwenwork"]
case .workBuddy: return ["com.tencent.workbuddy.mac", "com.workbuddy.workbuddy"]
case .weSight: return ["ai.wesight.app"]
}
}

Expand All @@ -46,7 +54,7 @@ public enum AgentID: String, Codable, CaseIterable, Hashable, Identifiable, Send
}

public static func matching(bundleIdentifier: String) -> AgentID? {
allCases.first { $0.bundleIdentifier == bundleIdentifier }
allCases.first { $0.bundleIdentifiers.contains(bundleIdentifier) }
}

public static func matching(_ action: ShareAction) -> AgentID? {
Expand Down
31 changes: 21 additions & 10 deletions macos/Sources/WeChatBridgeCore/ShareAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,22 +74,33 @@ public enum ShareAction: String, Codable, Sendable, CaseIterable {

/// The app this action drives, if any. Resolved by bundle identifier rather
/// than by name so a renamed or relocated app still works.
public var targetBundleIdentifier: String? {
///
/// This is the primary identifier only. Code that looks the app up on this
/// Mac should try every entry of `targetBundleIdentifiers`.
public var targetBundleIdentifier: String? { targetBundleIdentifiers.first }

/// Every bundle identifier the target app is known to ship under, primary
/// first. Empty when the action drives no app.
///
/// WorkBuddy has two: the WeChat-distributed build is
/// `com.tencent.workbuddy.mac`, the public download is
/// `com.workbuddy.workbuddy` (issue #44).
public var targetBundleIdentifiers: [String] {
switch self {
case .codex: return "com.openai.codex"
case .claude: return "com.anthropic.claudefordesktop"
case .doubao: return "com.bot.pc.doubao"
case .qwen: return "com.alibaba.qwenwork"
case .workBuddy: return "com.tencent.workbuddy.mac"
case .weSight: return "ai.wesight.app"
case .deepSeekHarness: return "com.deepseek.dsh"
case .obsidian: return "md.obsidian"
case .codex: return ["com.openai.codex"]
case .claude: return ["com.anthropic.claudefordesktop"]
case .doubao: return ["com.bot.pc.doubao"]
case .qwen: return ["com.alibaba.qwenwork"]
case .workBuddy: return ["com.tencent.workbuddy.mac", "com.workbuddy.workbuddy"]
case .weSight: return ["ai.wesight.app"]
case .deepSeekHarness: return ["com.deepseek.dsh"]
case .obsidian: return ["md.obsidian"]
// `.custom` has no fixed destination and no destination in its intent
// either. `ActionRunner` resolves one from the user's own list, or takes
// the one a 发给 ▸ menu inside WeChatBridge named.
// `.folder` delivers to a path, not a process — the app writes the
// note itself and no app is ever launched.
case .collect, .clipboard, .custom, .folder: return nil
case .collect, .clipboard, .custom, .folder: return []
}
}

Expand Down
12 changes: 12 additions & 0 deletions macos/Tests/WeChatBridgeCoreTests/ShareActionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@ final class ShareActionTests: XCTestCase {
XCTAssertNil(ShareAction.custom.targetBundleIdentifier)
}

/// Issue #44: WorkBuddy ships under two bundle identifiers, and the
/// public download (`com.workbuddy.workbuddy`) read as 未安装.
func testWorkBuddyIsKnownUnderBothBundleIdentifiers() {
XCTAssertEqual(
ShareAction.workBuddy.targetBundleIdentifiers,
["com.tencent.workbuddy.mac", "com.workbuddy.workbuddy"]
)
XCTAssertEqual(AgentID.matching(bundleIdentifier: "com.workbuddy.workbuddy"), .workBuddy)
XCTAssertEqual(AgentID.matching(bundleIdentifier: "com.tencent.workbuddy.mac"), .workBuddy)
XCTAssertEqual(ShareAction.clipboard.targetBundleIdentifiers, [])
}

/// The folder entry travels in manifests and intents like every other
/// action: a build that cannot decode `folder` would drop the request, so
/// the round trip is pinned here.
Expand Down
Loading