diff --git a/macos/Sources/WeChatBridgeApp/ActionRunner.swift b/macos/Sources/WeChatBridgeApp/ActionRunner.swift index 525bdb2..c526432 100644 --- a/macos/Sources/WeChatBridgeApp/ActionRunner.swift +++ b/macos/Sources/WeChatBridgeApp/ActionRunner.swift @@ -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 } diff --git a/macos/Sources/WeChatBridgeApp/Feedback/CollectionCoordinator.swift b/macos/Sources/WeChatBridgeApp/Feedback/CollectionCoordinator.swift index d71c5d0..6607eb6 100644 --- a/macos/Sources/WeChatBridgeApp/Feedback/CollectionCoordinator.swift +++ b/macos/Sources/WeChatBridgeApp/Feedback/CollectionCoordinator.swift @@ -48,7 +48,7 @@ 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 } } @@ -56,7 +56,7 @@ final class CollectionCoordinator: ObservableObject { 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 } } diff --git a/macos/Sources/WeChatBridgeApp/ForwardTargets.swift b/macos/Sources/WeChatBridgeApp/ForwardTargets.swift index 8c1a9a4..9e76b4f 100644 --- a/macos/Sources/WeChatBridgeApp/ForwardTargets.swift +++ b/macos/Sources/WeChatBridgeApp/ForwardTargets.swift @@ -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 diff --git a/macos/Sources/WeChatBridgeApp/ShareEntryProbe.swift b/macos/Sources/WeChatBridgeApp/ShareEntryProbe.swift index f1f47b5..fff3937 100644 --- a/macos/Sources/WeChatBridgeApp/ShareEntryProbe.swift +++ b/macos/Sources/WeChatBridgeApp/ShareEntryProbe.swift @@ -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) }) { diff --git a/macos/Sources/WeChatBridgeApp/Views/Settings/ShareEntryList.swift b/macos/Sources/WeChatBridgeApp/Views/Settings/ShareEntryList.swift index 129a097..8de5196 100644 --- a/macos/Sources/WeChatBridgeApp/Views/Settings/ShareEntryList.swift +++ b/macos/Sources/WeChatBridgeApp/Views/Settings/ShareEntryList.swift @@ -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() @@ -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 @@ -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: diff --git a/macos/Sources/WeChatBridgeCore/AgentID.swift b/macos/Sources/WeChatBridgeCore/AgentID.swift index 3d788af..7a1e170 100644 --- a/macos/Sources/WeChatBridgeCore/AgentID.swift +++ b/macos/Sources/WeChatBridgeCore/AgentID.swift @@ -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"] } } @@ -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? { diff --git a/macos/Sources/WeChatBridgeCore/ShareAction.swift b/macos/Sources/WeChatBridgeCore/ShareAction.swift index 98fc009..cb14517 100644 --- a/macos/Sources/WeChatBridgeCore/ShareAction.swift +++ b/macos/Sources/WeChatBridgeCore/ShareAction.swift @@ -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 [] } } diff --git a/macos/Tests/WeChatBridgeCoreTests/ShareActionTests.swift b/macos/Tests/WeChatBridgeCoreTests/ShareActionTests.swift index 7d23f4d..2576d19 100644 --- a/macos/Tests/WeChatBridgeCoreTests/ShareActionTests.swift +++ b/macos/Tests/WeChatBridgeCoreTests/ShareActionTests.swift @@ -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.