diff --git a/PRODUCT_CAPABILITIES.zh-CN.md b/PRODUCT_CAPABILITIES.zh-CN.md index 9535e22..d1dfee9 100644 --- a/PRODUCT_CAPABILITIES.zh-CN.md +++ b/PRODUCT_CAPABILITIES.zh-CN.md @@ -1,7 +1,7 @@ # 微信流(WeChatBridge)产品能力文档 > 基于 main 分支当前代码整理 -> 平台:macOS 14 及以上 +> 平台:macOS 13 及以上 > 文档日期:2026-09-20 ## 1. 产品定义 @@ -206,7 +206,7 @@ ## 10. 已知限制 -1. 仅支持 macOS 14 及以上。 +1. 仅支持 macOS 13(Ventura)及以上。 2. 微信分享菜单入口数量在构建时固定,不能为每个已安装应用动态生成。 3. 任意应用扩展通过“发送到自定义”解决。 4. 自动粘贴依赖辅助功能权限、目标 App 可激活性和窗口焦点。 diff --git a/README.md b/README.md index 66d9d66..19354ac 100644 --- a/README.md +++ b/README.md @@ -66,10 +66,10 @@ | 平台 | 下载地址 | 提取密码 | | --- | --- | --- | -| macOS 14+(Apple Silicon 与 Intel) | [wwbsr.lanzout.com/b0umjur8h](https://wwbsr.lanzout.com/b0umjur8h) | `向明` | +| macOS 13+(Apple Silicon 与 Intel) | [wwbsr.lanzout.com/b0umjur8h](https://wwbsr.lanzout.com/b0umjur8h) | `向明` | | Windows | [wwbsr.lanzout.com/b0umjur4d](https://wwbsr.lanzout.com/b0umjur4d) | `向明` | -macOS 版打开 DMG,把「微信流」拖入「应用程序」即可;Windows 版解压后按目录内说明运行。iOS 版正在开发中,进群可以第一时间知道进展。 +macOS 版打开 DMG,把「微信流」拖入「应用程序」即可(图标带 🚫 或提示「无法验证」见[常见问题](USAGE.zh-CN.md#常见问题));Windows 版解压后按目录内说明运行。iOS 版正在开发中,进群可以第一时间知道进展。 ## 加入交流群 diff --git a/README_EN.md b/README_EN.md index d18ba93..c6abf7d 100644 --- a/README_EN.md +++ b/README_EN.md @@ -66,10 +66,10 @@ Free to download. All installers are distributed through Lanzou Cloud, and the e | Platform | Download | Password | | --- | --- | --- | -| macOS 14+ (Apple Silicon and Intel) | [wwbsr.lanzout.com/b0umjur8h](https://wwbsr.lanzout.com/b0umjur8h) | `向明` | +| macOS 13+ (Apple Silicon and Intel) | [wwbsr.lanzout.com/b0umjur8h](https://wwbsr.lanzout.com/b0umjur8h) | `向明` | | Windows | [wwbsr.lanzout.com/b0umjur4d](https://wwbsr.lanzout.com/b0umjur4d) | `向明` | -On macOS, open the DMG and drag WeChatBridge into Applications. On Windows, unzip the archive and follow the instructions inside. An iOS version is in development—join the group to hear about it first. +On macOS, open the DMG and drag WeChatBridge into Applications (if the icon shows a 🚫 or macOS says it cannot verify the app, see the [FAQ](USAGE_EN.md#faq)). On Windows, unzip the archive and follow the instructions inside. An iOS version is in development—join the group to hear about it first. ## Join the community diff --git a/USAGE.zh-CN.md b/USAGE.zh-CN.md index dc7219a..36d0ad0 100644 --- a/USAGE.zh-CN.md +++ b/USAGE.zh-CN.md @@ -110,6 +110,20 @@ ## 常见问题 +**图标上有个 🚫,拖不进「应用程序」?** +这是 0.1.15 及更早的安装包只支持 macOS 14 的标志。新版本已支持 macOS 13(Ventura)及以上,重新下载最新版即可。macOS 12 及更早版本暂不支持。 + +**提示「Apple 无法验证“微信流”是否包含恶意软件」或「已损坏」?** +早期安装包没有经过 Apple 公证,新版本会修复。已经下载的旧包可以这样打开(只对从本项目蓝奏云链接下载的安装包这样做): + +1. 先把「微信流」拖进「应用程序」,双击打开一次,在弹窗里点「完成」。 +2. 打开「系统设置 → 隐私与安全性」,滚到底部,在「已阻止使用“微信流”」旁点「仍要打开」,输入开机密码确认。 +3. 如果没有出现「仍要打开」,在「终端」里执行下面这行后再双击打开: + + ```bash + xattr -dr com.apple.quarantine /Applications/微信流.app + ``` + **入口没有出现在微信菜单里?** 先确认对应开关已打开,再到「系统设置 → 通用 → 登录项与扩展 → 共享」里检查扩展是否启用。系统有时需要重启微信才会刷新菜单。 diff --git a/USAGE_EN.md b/USAGE_EN.md index c75cac7..e9b8726 100644 --- a/USAGE_EN.md +++ b/USAGE_EN.md @@ -109,6 +109,20 @@ Conversation content only comes from files WeChat exports on your request. WeCha ## FAQ +**The icon shows a 🚫 and will not drag into Applications.** +Builds up to 0.1.15 required macOS 14. Newer builds run on macOS 13 (Ventura) and later; download the latest one. macOS 12 and earlier are not supported. + +**macOS says “Apple could not verify WeChatBridge is free of malware” or that it “is damaged”.** +Early builds were not notarized by Apple; newer builds are. To open an older build you already downloaded (only one that came from this project's Lanzou link): + +1. Drag WeChatBridge into Applications, double-click it once, and click “Done” in the alert. +2. Open “System Settings → Privacy & Security”, scroll to the bottom, click “Open Anyway” next to the WeChatBridge notice, and confirm with your login password. +3. If “Open Anyway” does not appear, run this in Terminal and double-click the app again: + + ```bash + xattr -dr com.apple.quarantine /Applications/微信流.app + ``` + **The entries are missing from the WeChat menu.** Confirm the switch is on, then check the extension under “System Settings → General → Login Items & Extensions → Sharing”. WeChat sometimes needs a restart before the menu refreshes. diff --git a/macos/Package.swift b/macos/Package.swift index 2aded52..2a006eb 100644 --- a/macos/Package.swift +++ b/macos/Package.swift @@ -7,7 +7,7 @@ import PackageDescription // `Scripts/make-app.sh` assembles and signs the bundle around them. let package = Package( name: "WeChatBridge", - platforms: [.macOS(.v14), .iOS(.v17)], + platforms: [.macOS(.v13), .iOS(.v17)], products: [ .executable(name: "WeChatBridge", targets: ["WeChatBridgeApp"]), .executable(name: "WeChatBridgeShare", targets: ["WeChatBridgeShare"]), diff --git a/macos/Resources/Info.plist b/macos/Resources/Info.plist index 10bcfec..0dff535 100644 --- a/macos/Resources/Info.plist +++ b/macos/Resources/Info.plist @@ -4,14 +4,14 @@ CFBundleDevelopmentRegion zh-Hans + CFBundleDisplayName + 微信流 CFBundleExecutable WeChatBridge CFBundleIconFile AppIcon CFBundleIdentifier com.xiangming.wechatbridge - CFBundleDisplayName - 微信流 CFBundleInfoDictionaryVersion 6.0 CFBundleName @@ -38,7 +38,7 @@ DKStorageMode shared LSMinimumSystemVersion - 14.0 + 13.0 LSUIElement NSHumanReadableCopyright diff --git a/macos/Resources/Share-Info.plist b/macos/Resources/Share-Info.plist index 3c66443..46bcbfb 100644 --- a/macos/Resources/Share-Info.plist +++ b/macos/Resources/Share-Info.plist @@ -22,12 +22,12 @@ 18 DKAppGroupIdentifier DLKMC3ZRZQ.com.xiangming.wechatbridge.shared - DKStorageMode - shared DKShareAction clipboard + DKStorageMode + shared LSMinimumSystemVersion - 14.0 + 13.0 NSExtension NSExtensionAttributes diff --git a/macos/Scripts/make-app.sh b/macos/Scripts/make-app.sh index 94b2e38..8cade47 100755 --- a/macos/Scripts/make-app.sh +++ b/macos/Scripts/make-app.sh @@ -14,11 +14,14 @@ CONFIG="${CONFIG:-release}" # rebuild. A stable Developer ID or Apple Development identity is picked # automatically when the keychain has one; ad-hoc stays the fallback so a clone # without any certificate still builds. +# TEAM_ID narrows the search to one team's certificates, so a keychain holding +# several teams' identities never signs with the wrong one by accident. select_identity() { local found for PREFIX in "Developer ID Application:" "Apple Development:"; do found="$(security find-identity -v -p codesigning 2>/dev/null \ - | awk -v prefix="$PREFIX" 'index($0, prefix) { print $2; exit }')" + | awk -v prefix="$PREFIX" -v team="${TEAM_ID:+($TEAM_ID)\"}" \ + 'index($0, prefix) && (team == "" || index($0, team)) { print $2; exit }')" if [ -n "$found" ]; then printf '%s' "$found" return diff --git a/macos/Scripts/release.sh b/macos/Scripts/release.sh index d55a59c..726c5bc 100755 --- a/macos/Scripts/release.sh +++ b/macos/Scripts/release.sh @@ -42,9 +42,22 @@ if [ "$REQUIRE_TAG" = "1" ]; then fi fi -IDENTITY="${IDENTITY:-$(security find-identity -v -p codesigning 2>/dev/null | awk '/Developer ID Application:/ {print $2; exit}')}" +# Pin the identity to one team. Picking "the first Developer ID in the +# keychain" signs with whichever certificate happens to be installed, which is +# how a release ends up under somebody else's name or not notarizable at all. +TEAM_ID="${TEAM_ID:-}" +if [ -z "${IDENTITY:-}" ]; then + if [ -z "$TEAM_ID" ]; then + echo "set TEAM_ID to the Apple Developer team that owns the Developer ID certificate" >&2 + security find-identity -v -p codesigning | grep 'Developer ID Application:' >&2 || true + exit 1 + fi + IDENTITY="$(security find-identity -v -p codesigning 2>/dev/null \ + | awk -v team="($TEAM_ID)\"" '/Developer ID Application:/ && index($0, team) {print $2; exit}')" +fi if [ -z "$IDENTITY" ]; then - echo "no valid Developer ID Application identity was found" >&2 + echo "no valid Developer ID Application identity for team $TEAM_ID was found" >&2 + echo "create one at developer.apple.com → Certificates → Developer ID Application" >&2 exit 1 fi @@ -99,6 +112,8 @@ if [ "$NOTARIZE" = "1" ]; then notarize_artifact "$DMG" dmg xcrun stapler staple "$DMG" xcrun stapler validate "$DMG" + # The same check a downloaded copy will face on a user's Mac. + "$ROOT/Scripts/verify-gatekeeper.sh" "$DMG" else echo "warning: NOTARIZE=0; this DMG is not publishable" >&2 fi diff --git a/macos/Scripts/verify-gatekeeper.sh b/macos/Scripts/verify-gatekeeper.sh new file mode 100755 index 0000000..d6e43e1 --- /dev/null +++ b/macos/Scripts/verify-gatekeeper.sh @@ -0,0 +1,84 @@ +#!/usr/bin/env bash +# Check a DMG the way a user's Mac will see it after downloading, before it is +# uploaded anywhere. A DMG that fails here shows users "Apple could not verify +# 微信流 is free of malware" (or "is damaged") and will not open. +# +# Scripts/verify-gatekeeper.sh dist/WeChatBridge-0.1.16.dmg +# +# It also reports the lowest macOS the app accepts, so a build that would show +# the 🚫 badge on an older Mac is caught too. +set -euo pipefail + +DMG="${1:?usage: verify-gatekeeper.sh path/to/app.dmg}" +EXPECTED_MIN_OS="${EXPECTED_MIN_OS:-13.0}" +FAILED=0 +fail() { echo "✗ $*" >&2; FAILED=1; } +pass() { echo "✓ $*"; } + +if [ ! -f "$DMG" ]; then + echo "missing DMG: $DMG" >&2 + exit 1 +fi + +# The disk image itself: Developer ID signature plus a stapled ticket. +if spctl -a -t open --context context:primary-signature -vv "$DMG" 2>&1 | grep -q 'source=Notarized Developer ID'; then + pass "DMG is notarized" +else + fail "DMG is not notarized (spctl: $(spctl -a -t open --context context:primary-signature "$DMG" 2>&1 | tr '\n' ' '))" +fi +if xcrun stapler validate "$DMG" >/dev/null 2>&1; then + pass "DMG has a stapled ticket" +else + fail "DMG has no stapled ticket; offline Macs cannot verify it" +fi + +MOUNT_POINT="$(mktemp -d "${TMPDIR:-/tmp}/wcb-gatekeeper.XXXXXX")" +cleanup() { hdiutil detach "$MOUNT_POINT" -quiet 2>/dev/null || true; rmdir "$MOUNT_POINT" 2>/dev/null || true; } +trap cleanup EXIT +hdiutil attach "$DMG" -nobrowse -readonly -noautoopen -mountpoint "$MOUNT_POINT" >/dev/null + +APP="$(find "$MOUNT_POINT" -maxdepth 1 -name '*.app' -print -quit)" +if [ -z "$APP" ]; then + echo "no .app inside $DMG" >&2 + exit 1 +fi + +# The app: what Finder checks once it has been dragged to Applications. +ASSESSMENT="$(spctl -a -t exec -vv "$APP" 2>&1 || true)" +if printf '%s' "$ASSESSMENT" | grep -q 'source=Notarized Developer ID'; then + pass "app is notarized ($(printf '%s' "$ASSESSMENT" | sed -n 's/^origin=//p'))" +else + fail "app would be blocked by Gatekeeper: $(printf '%s' "$ASSESSMENT" | tr '\n' ' ')" +fi +if xcrun stapler validate "$APP" >/dev/null 2>&1; then + pass "app has a stapled ticket" +else + fail "app has no stapled ticket" +fi +if codesign --verify --deep --strict "$APP" 2>/dev/null; then + pass "app signature is intact" +else + fail "app signature does not verify" +fi + +MIN_OS="$(/usr/libexec/PlistBuddy -c 'Print :LSMinimumSystemVersion' "$APP/Contents/Info.plist")" +if [ "$MIN_OS" = "$EXPECTED_MIN_OS" ]; then + pass "runs on macOS $MIN_OS and later" +else + fail "LSMinimumSystemVersion is $MIN_OS, expected $EXPECTED_MIN_OS" +fi +ARCHS="$(lipo -archs "$APP/Contents/MacOS/WeChatBridge")" +case " $ARCHS " in + *" arm64 "*) ;; + *) fail "app has no arm64 slice ($ARCHS)" ;; +esac +case " $ARCHS " in + *" x86_64 "*) pass "universal binary ($ARCHS)" ;; + *) fail "app has no x86_64 slice ($ARCHS); Intel Macs cannot run it" ;; +esac + +if [ "$FAILED" = "1" ]; then + echo "this DMG is not ready to publish" >&2 + exit 1 +fi +echo "ready to publish: $DMG" diff --git a/macos/Sources/WeChatBridgeApp/Design/Compat.swift b/macos/Sources/WeChatBridgeApp/Design/Compat.swift new file mode 100644 index 0000000..acba161 --- /dev/null +++ b/macos/Sources/WeChatBridgeApp/Design/Compat.swift @@ -0,0 +1,112 @@ +import SwiftUI + +// The app ships to macOS 13 (Ventura) as well, because plenty of Intel Macs +// stop there. These wrappers use the macOS 14 SwiftUI API when it exists and the +// closest macOS 13 equivalent otherwise, so call sites stay one line. +extension View { + /// `onChange(of:initial:_:)` on macOS 14; the single-value form on 13, with + /// the previous value tracked here so the closure shape stays the same. + @ViewBuilder + func compatOnChange(of value: V, perform action: @escaping (V, V) -> Void) -> some View { + if #available(macOS 14, *) { + onChange(of: value) { old, new in action(old, new) } + } else { + modifier(LegacyOnChange(value: value, action: action)) + } + } + + /// The bounce is cosmetic, so macOS 13.0–13.2 simply keeps the default. + @ViewBuilder + func compatScrollBounceBasedOnSize() -> some View { + if #available(macOS 13.3, *) { + scrollBounceBehavior(.basedOnSize) + } else { + self + } + } + + /// A scroll view already starts at the top on macOS 13. + @ViewBuilder + func compatDefaultScrollAnchorTop() -> some View { + if #available(macOS 14, *) { + defaultScrollAnchor(.top) + } else { + self + } + } + + /// macOS 13 draws its focus ring on these custom controls; nothing breaks. + @ViewBuilder + func compatFocusEffectDisabled() -> some View { + if #available(macOS 14, *) { + focusEffectDisabled() + } else { + self + } + } + + /// Keyboard navigation for a focused custom control. macOS 14 uses + /// `onKeyPress`; macOS 13 has no key-press modifier, so arrows go through + /// `onMoveCommand` and Return/Space are left to the mouse. + @ViewBuilder + func compatKeyCommands( + up: (() -> Void)? = nil, + down: (() -> Void)? = nil, + left: (() -> Void)? = nil, + right: (() -> Void)? = nil, + commit: (() -> Void)? = nil + ) -> some View { + if #available(macOS 14, *) { + let handlers = Self.keyHandlers(up: up, down: down, left: left, right: right, commit: commit) + onKeyPress(keys: Set(handlers.keys)) { press in + guard let handler = handlers[press.key] else { return .ignored } + handler() + return .handled + } + } else { + onMoveCommand { direction in + switch direction { + case .up: up?() + case .down: down?() + case .left: left?() + case .right: right?() + @unknown default: break + } + } + } + } + + private static func keyHandlers( + up: (() -> Void)?, + down: (() -> Void)?, + left: (() -> Void)?, + right: (() -> Void)?, + commit: (() -> Void)? + ) -> [KeyEquivalent: () -> Void] { + var handlers: [KeyEquivalent: () -> Void] = [:] + if let up { handlers[.upArrow] = up } + if let down { handlers[.downArrow] = down } + if let left { handlers[.leftArrow] = left } + if let right { handlers[.rightArrow] = right } + if let commit { + handlers[.return] = commit + handlers[.space] = commit + } + return handlers + } +} + +private struct LegacyOnChange: ViewModifier { + let value: V + let action: (V, V) -> Void + @State private var previous: V? + + func body(content: Content) -> some View { + content + .onAppear { previous = value } + .onChange(of: value) { new in + action(previous ?? new, new) + previous = new + } + } +} diff --git a/macos/Sources/WeChatBridgeApp/Design/FormControls.swift b/macos/Sources/WeChatBridgeApp/Design/FormControls.swift index 9a14daf..d60c7e5 100644 --- a/macos/Sources/WeChatBridgeApp/Design/FormControls.swift +++ b/macos/Sources/WeChatBridgeApp/Design/FormControls.swift @@ -166,7 +166,7 @@ struct SettingsTextFieldStyle: TextFieldStyle { .allowsHitTesting(false) } .focused($focused) - .focusEffectDisabled() + .compatFocusEffectDisabled() .onHover { hovering = $0 } .opacity(isEnabled ? 1 : 0.45) } @@ -218,7 +218,7 @@ struct SettingsOptionToggleStyle: ToggleStyle { } .buttonStyle(PlainPressButtonStyle(staticFeedback: true)) .focused($focused) - .focusEffectDisabled() + .compatFocusEffectDisabled() .modifier(SettingsFocusRing(focused: focused)) .onHover { hovering = $0 } .opacity(isEnabled ? 1 : 0.45) @@ -261,16 +261,15 @@ struct SettingsSelect: View { } .buttonStyle(SettingsControlButtonStyle()) .focused($focused) - .focusEffectDisabled() + .compatFocusEffectDisabled() .modifier(SettingsFocusRing(focused: focused)) .background { GeometryReader { proxy in Color.clear.onAppear { width = proxy.size.width } - .onChange(of: proxy.size.width) { _, value in width = value } + .compatOnChange(of: proxy.size.width) { _, value in width = value } } } - .onKeyPress(.downArrow) { expanded = true; return .handled } - .onKeyPress(.upArrow) { expanded = true; return .handled } + .compatKeyCommands(up: { expanded = true }, down: { expanded = true }) .popover(isPresented: $expanded, arrowEdge: .bottom) { SettingsChoiceList(title: title, selection: selection, choices: choices, identifier: identifier) { selection = $0 @@ -280,7 +279,7 @@ struct SettingsSelect: View { } .frame(width: max(180, min(width, 420))) } - .onChange(of: expanded) { _, value in if !value { focused = true } } + .compatOnChange(of: expanded) { _, value in if !value { focused = true } } .disabled(choices.isEmpty) .accessibilityLabel(Text(title)) .accessibilityValue(Text(valueTitle)) @@ -338,8 +337,8 @@ struct SettingsChoiceList: View { } } .frame(height: min(max(CGFloat(choices.count) * (SettingsControlMetrics.height + Space.xxs) - Space.xxs, 0), 286)) - .scrollBounceBehavior(.basedOnSize) - .onChange(of: highlighted) { _, value in + .compatScrollBounceBasedOnSize() + .compatOnChange(of: highlighted) { _, value in if let value, value != footer?.id { reader.scrollTo(value) } } } @@ -353,19 +352,16 @@ struct SettingsChoiceList: View { .background(Theme.surface) .focusable() .focused($focused) - .focusEffectDisabled() + .compatFocusEffectDisabled() .onAppear { highlighted = enabledChoices.contains { $0.id == selection } ? selection : enabledChoices.first?.id focused = true } - .onChange(of: enabledChoices.map(\.id)) { _, ids in + .compatOnChange(of: enabledChoices.map(\.id)) { _, ids in if !ids.contains(where: { $0 == highlighted }) { highlighted = ids.first } if ids.isEmpty { dismiss() } } - .onKeyPress(.downArrow) { move(1); return .handled } - .onKeyPress(.upArrow) { move(-1); return .handled } - .onKeyPress(.return) { commit(); return .handled } - .onKeyPress(.space) { commit(); return .handled } + .compatKeyCommands(up: { move(-1) }, down: { move(1) }, commit: commit) .onExitCommand(perform: dismiss) .accessibilityElement(children: .contain) } @@ -460,7 +456,7 @@ struct SettingsChoiceStrip: View { } .buttonStyle(SettingsChoiceButtonStyle(selected: selection == choice.id)) .focused($focused, equals: choice.id) - .focusEffectDisabled() + .compatFocusEffectDisabled() .modifier(SettingsFocusRing(focused: focused == choice.id, radius: SettingsControlMetrics.radius - Space.xxs)) } @@ -472,8 +468,7 @@ struct SettingsChoiceStrip: View { .strokeBorder(Theme.strokeStrong, lineWidth: Stroke.hairline) .allowsHitTesting(false) } - .onKeyPress(.leftArrow) { move(-1); return .handled } - .onKeyPress(.rightArrow) { move(1); return .handled } + .compatKeyCommands(left: { move(-1) }, right: { move(1) }) .accessibilityRepresentation { Picker(title, selection: $selection) { ForEach(choices) { Text($0.title).tag($0.id) } diff --git a/macos/Sources/WeChatBridgeApp/Feedback/CollectionCoordinator.swift b/macos/Sources/WeChatBridgeApp/Feedback/CollectionCoordinator.swift index 6607eb6..3fd6b0e 100644 --- a/macos/Sources/WeChatBridgeApp/Feedback/CollectionCoordinator.swift +++ b/macos/Sources/WeChatBridgeApp/Feedback/CollectionCoordinator.swift @@ -272,18 +272,18 @@ private struct CollectionPanelView: View { } .padding(Space.l) } - .scrollBounceBehavior(.basedOnSize) + .compatScrollBounceBasedOnSize() .frame(width: coordinator.isDelivery ? 390 : 344) .frame(maxHeight: FloatingCapsule.visibleFrame.height - 2 * Metrics.screenMargin) .fixedSize(horizontal: false, vertical: true) .background(.regularMaterial) .clipShape(RoundedRectangle(cornerRadius: Radius.panel)) .overlay(RoundedRectangle(cornerRadius: Radius.panel).strokeBorder(Palette.hairline, lineWidth: Stroke.hairline)) - .onChange(of: coordinator.showAnchors) { _, _ in coordinatorLayout() } - .onChange(of: coordinator.anchorBatchID) { _, _ in coordinatorLayout() } - .onChange(of: coordinator.errorMessage) { _, _ in coordinatorLayout() } - .onChange(of: model.inboxFailure) { _, _ in coordinatorLayout() } - .onChange(of: model.recognizingConversations) { _, _ in coordinatorLayout() } + .compatOnChange(of: coordinator.showAnchors) { _, _ in coordinatorLayout() } + .compatOnChange(of: coordinator.anchorBatchID) { _, _ in coordinatorLayout() } + .compatOnChange(of: coordinator.errorMessage) { _, _ in coordinatorLayout() } + .compatOnChange(of: model.inboxFailure) { _, _ in coordinatorLayout() } + .compatOnChange(of: model.recognizingConversations) { _, _ in coordinatorLayout() } } private func coordinatorLayout() { @@ -369,7 +369,7 @@ private struct CollectionPanelView: View { ForEach(coordinator.scenes) { Text($0.name).tag($0.id) } } .disabled(coordinator.isFileDestination) - .onChange(of: coordinator.selection) { _, _ in + .compatOnChange(of: coordinator.selection) { _, _ in if coordinator.isFileDestination || !coordinator.scenes.contains(where: { $0.id == coordinator.sceneID }) { coordinator.sceneID = "" } } HStack { diff --git a/macos/Sources/WeChatBridgeApp/Feedback/ScenePickerPanel.swift b/macos/Sources/WeChatBridgeApp/Feedback/ScenePickerPanel.swift index 125941f..f373187 100644 --- a/macos/Sources/WeChatBridgeApp/Feedback/ScenePickerPanel.swift +++ b/macos/Sources/WeChatBridgeApp/Feedback/ScenePickerPanel.swift @@ -243,8 +243,8 @@ private struct ScenePickerView: View { } } } - .scrollBounceBehavior(.basedOnSize) - .onChange(of: state.highlighted) { _, highlighted in + .compatScrollBounceBasedOnSize() + .compatOnChange(of: state.highlighted) { _, highlighted in guard scenes.indices.contains(highlighted) else { return } proxy.scrollTo(scenes[highlighted].id, anchor: .center) } diff --git a/macos/Sources/WeChatBridgeApp/Feedback/TargetPickerPanel.swift b/macos/Sources/WeChatBridgeApp/Feedback/TargetPickerPanel.swift index 295d371..b7b4b6b 100644 --- a/macos/Sources/WeChatBridgeApp/Feedback/TargetPickerPanel.swift +++ b/macos/Sources/WeChatBridgeApp/Feedback/TargetPickerPanel.swift @@ -308,8 +308,8 @@ struct TargetPickerView: View { } } } - .scrollBounceBehavior(.basedOnSize) - .onChange(of: state.highlighted) { _, highlighted in + .compatScrollBounceBasedOnSize() + .compatOnChange(of: state.highlighted) { _, highlighted in guard targets.indices.contains(highlighted) else { return } proxy.scrollTo(targets[highlighted].id, anchor: .center) } diff --git a/macos/Sources/WeChatBridgeApp/Onboarding/OnboardingFlow.swift b/macos/Sources/WeChatBridgeApp/Onboarding/OnboardingFlow.swift index 5b2912e..5e610a9 100644 --- a/macos/Sources/WeChatBridgeApp/Onboarding/OnboardingFlow.swift +++ b/macos/Sources/WeChatBridgeApp/Onboarding/OnboardingFlow.swift @@ -59,7 +59,7 @@ struct OnboardingFlow: View { probe.refresh() preferences.onboardingStep = step.rawValue } - .onChange(of: step) { _, new in preferences.onboardingStep = new.rawValue } + .compatOnChange(of: step) { _, new in preferences.onboardingStep = new.rawValue } // The permission is granted, and the entries can be switched, in System // Settings — in another process, while this window waits. Both have to // be re-read the moment the user comes back. diff --git a/macos/Sources/WeChatBridgeApp/Views/Settings/AboutPane.swift b/macos/Sources/WeChatBridgeApp/Views/Settings/AboutPane.swift index 52a5444..722b209 100644 --- a/macos/Sources/WeChatBridgeApp/Views/Settings/AboutPane.swift +++ b/macos/Sources/WeChatBridgeApp/Views/Settings/AboutPane.swift @@ -271,7 +271,7 @@ private struct LicenseSheet: View { } .padding(.trailing, Space.s) } - .defaultScrollAnchor(.top) + .compatDefaultScrollAnchorTop() } } .padding(Space.xl) diff --git a/macos/Sources/WeChatBridgeApp/Views/Settings/CollectionHistoryCard.swift b/macos/Sources/WeChatBridgeApp/Views/Settings/CollectionHistoryCard.swift index ddb26ea..26b96f7 100644 --- a/macos/Sources/WeChatBridgeApp/Views/Settings/CollectionHistoryCard.swift +++ b/macos/Sources/WeChatBridgeApp/Views/Settings/CollectionHistoryCard.swift @@ -176,7 +176,7 @@ struct BatchConversationField: View { } .frame(maxWidth: .infinity, alignment: .leading) .onAppear { name = model.batchConversation(batchID) ?? "" } - .onChange(of: model.batchConversation(batchID)) { _, source in + .compatOnChange(of: model.batchConversation(batchID)) { _, source in if !editing, let source { name = source } } } diff --git a/macos/Sources/WeChatBridgeApp/Views/Settings/ForwardTargetList.swift b/macos/Sources/WeChatBridgeApp/Views/Settings/ForwardTargetList.swift index 9588af1..4cbe956 100644 --- a/macos/Sources/WeChatBridgeApp/Views/Settings/ForwardTargetList.swift +++ b/macos/Sources/WeChatBridgeApp/Views/Settings/ForwardTargetList.swift @@ -83,7 +83,7 @@ struct ForwardTargetList: View { } .listStyle(.plain) .scrollContentBackground(.hidden) - .scrollBounceBehavior(.basedOnSize) + .compatScrollBounceBasedOnSize() .frame(height: Self.rowHeight * CGFloat(min(targets.targets.count, Self.visibleRows))) .padding(Space.xs) } @@ -189,7 +189,7 @@ private struct AddForwardTargetButton: View { } .buttonStyle(SettingsActionButtonStyle()) .focused($focused) - .focusEffectDisabled() + .compatFocusEffectDisabled() .modifier(SettingsFocusRing(focused: focused)) .popover(isPresented: $expanded, arrowEdge: .bottom) { SettingsChoiceList( @@ -225,7 +225,7 @@ private struct AddForwardTargetButton: View { Task { @MainActor in chooseFromFinder() } } } - .onChange(of: expanded) { _, value in if !value { focused = true } } + .compatOnChange(of: expanded) { _, value in if !value { focused = true } } .accessibilityIdentifier("entries.add") } diff --git a/macos/Sources/WeChatBridgeApp/Views/Settings/HistoryPane.swift b/macos/Sources/WeChatBridgeApp/Views/Settings/HistoryPane.swift index b02a9ca..3b4a48f 100644 --- a/macos/Sources/WeChatBridgeApp/Views/Settings/HistoryPane.swift +++ b/macos/Sources/WeChatBridgeApp/Views/Settings/HistoryPane.swift @@ -342,7 +342,7 @@ private struct HistorySearchField: View { .allowsHitTesting(false) } .focused($focused) - .focusEffectDisabled() + .compatFocusEffectDisabled() } } @@ -359,7 +359,7 @@ private struct HistoryForwardButton: View { } .buttonStyle(SettingsActionButtonStyle(width: 72)) .focused($focused) - .focusEffectDisabled() + .compatFocusEffectDisabled() .modifier(SettingsFocusRing(focused: focused)) .fixedSize() .popover(isPresented: $expanded, arrowEdge: .bottom) { @@ -368,7 +368,7 @@ private struct HistoryForwardButton: View { } .frame(width: 220) } - .onChange(of: expanded) { _, value in + .compatOnChange(of: expanded) { _, value in if !value { focused = true } } .accessibilityLabel(Text(L10n.text("发给…"))) diff --git a/macos/Sources/WeChatBridgeApp/Views/Settings/SceneSettingsView.swift b/macos/Sources/WeChatBridgeApp/Views/Settings/SceneSettingsView.swift index 460452d..416adb4 100644 --- a/macos/Sources/WeChatBridgeApp/Views/Settings/SceneSettingsView.swift +++ b/macos/Sources/WeChatBridgeApp/Views/Settings/SceneSettingsView.swift @@ -77,16 +77,16 @@ struct SceneSettingsView: View { selectedSceneID = selectedSceneID ?? preferences.scenes.scenes.first?.id selectedGroupKey = selectedGroupKey ?? allGroupKeys.first } - .onChange(of: preferences.scenes.scenes.map(\.id)) { _, ids in + .compatOnChange(of: preferences.scenes.scenes.map(\.id)) { _, ids in if let selectedSceneID, ids.contains(selectedSceneID) { return } selectedSceneID = ids.first } - .onChange(of: preferences.groupMemory.keys.sorted()) { _, keys in + .compatOnChange(of: preferences.groupMemory.keys.sorted()) { _, keys in if let selectedGroupKey, keys.contains(selectedGroupKey) { return } selectedGroupKey = keys.first } // The skills pane's 用于 N 个场景 badge lands here. - .onChange(of: router.skillFocus) { _, skillID in + .compatOnChange(of: router.skillFocus) { _, skillID in guard let skillID else { return } router.skillFocus = nil page = .scenes @@ -189,7 +189,7 @@ struct SceneSettingsView: View { } } } - .scrollBounceBehavior(.basedOnSize) + .compatScrollBounceBasedOnSize() Spacer(minLength: Space.s) VStack(alignment: .leading, spacing: 6) { Button(L10n.text("导入 JSON")) { importing = true } @@ -257,7 +257,7 @@ struct SceneSettingsView: View { if !unboundGroupKeys.isEmpty { groupSection(title: L10n.text("尚未绑定"), keys: unboundGroupKeys) } } } - .scrollBounceBehavior(.basedOnSize) + .compatScrollBounceBasedOnSize() } .frame(maxHeight: .infinity, alignment: .top) .background(Theme.surface, in: RoundedRectangle(cornerRadius: Radius.card, style: .continuous)) diff --git a/macos/Sources/WeChatBridgeApp/Views/Settings/SettingsActionList.swift b/macos/Sources/WeChatBridgeApp/Views/Settings/SettingsActionList.swift index 3c3d93b..ddacaf8 100644 --- a/macos/Sources/WeChatBridgeApp/Views/Settings/SettingsActionList.swift +++ b/macos/Sources/WeChatBridgeApp/Views/Settings/SettingsActionList.swift @@ -52,8 +52,8 @@ struct SettingsActionList: View { } } .frame(height: min(contentHeight, Self.maxHeight)) - .scrollBounceBehavior(.basedOnSize) - .onChange(of: highlighted) { _, value in + .compatScrollBounceBasedOnSize() + .compatOnChange(of: highlighted) { _, value in if let value { reader.scrollTo(value) } } } @@ -61,16 +61,13 @@ struct SettingsActionList: View { .background(Theme.surface) .focusable() .focused($focused) - .focusEffectDisabled() + .compatFocusEffectDisabled() .onAppear { // No selection to return to, so the keyboard starts at the top. highlighted = items.first?.id focused = true } - .onKeyPress(.downArrow) { move(1); return .handled } - .onKeyPress(.upArrow) { move(-1); return .handled } - .onKeyPress(.return) { commit(); return .handled } - .onKeyPress(.space) { commit(); return .handled } + .compatKeyCommands(up: { move(-1) }, down: { move(1) }, commit: commit) .onExitCommand(perform: dismiss) .accessibilityElement(children: .contain) } @@ -153,7 +150,7 @@ struct SettingsMoreActionsButton: View { } .buttonStyle(IconButtonStyle(size: Self.side, staticFeedback: true)) .focused($focused) - .focusEffectDisabled() + .compatFocusEffectDisabled() .modifier(SettingsFocusRing(focused: focused, radius: Self.side / 2)) .fixedSize() // NSPopover brings its own arrival, which is the whole reason this is a @@ -165,7 +162,7 @@ struct SettingsMoreActionsButton: View { } // Focus stays on the trigger, so the next Tab carries on from here // rather than from the top of the pane. - .onChange(of: expanded) { _, value in if !value { focused = true } } + .compatOnChange(of: expanded) { _, value in if !value { focused = true } } .help(L10n.text("更多操作")) .accessibilityLabel(Text(L10n.text("更多操作"))) .accessibilityIdentifier(identifier) diff --git a/macos/Sources/WeChatBridgeApp/Views/Settings/SettingsView.swift b/macos/Sources/WeChatBridgeApp/Views/Settings/SettingsView.swift index 034a6de..374ad83 100644 --- a/macos/Sources/WeChatBridgeApp/Views/Settings/SettingsView.swift +++ b/macos/Sources/WeChatBridgeApp/Views/Settings/SettingsView.swift @@ -130,10 +130,10 @@ struct SettingsView: View { .padding(.vertical, Space.xl) .frame(maxWidth: .infinity, alignment: .leading) } - .scrollBounceBehavior(.basedOnSize) + .compatScrollBounceBasedOnSize() // Without this the pane opens scrolled to whichever control // AppKit made first responder, which hides the page title. - .defaultScrollAnchor(.top) + .compatDefaultScrollAnchorTop() .id(router.tab) } } @@ -218,7 +218,7 @@ private struct SettingsNavItem: View { } .buttonStyle(PlainPressButtonStyle(staticFeedback: true)) .focused($focused) - .focusEffectDisabled() + .compatFocusEffectDisabled() .modifier(SettingsFocusRing(focused: focused, radius: Radius.control)) .onHover { hovering = $0 } .accessibilityAddTraits(isSelected ? [.isSelected] : []) diff --git a/macos/Sources/WeChatBridgeApp/Views/Settings/SkillsPane.swift b/macos/Sources/WeChatBridgeApp/Views/Settings/SkillsPane.swift index 2cf562f..92878fc 100644 --- a/macos/Sources/WeChatBridgeApp/Views/Settings/SkillsPane.swift +++ b/macos/Sources/WeChatBridgeApp/Views/Settings/SkillsPane.swift @@ -277,7 +277,7 @@ private struct SkillSearchField: View { .font(SettingsControlMetrics.font) .foregroundStyle(Theme.ink) .focused($focused) - .focusEffectDisabled() + .compatFocusEffectDisabled() } .padding(.horizontal, SettingsControlMetrics.inset) .frame(height: SettingsControlMetrics.height)