Skip to content

PasteFerry (隔空贴): clipboard and file sync across macOS, Windows and Linux. Direct-first, end-to-end encrypted. Optional official access: no server to host. Independent self-hosting remains available.

build: declare local network access for the macOS background service

baiyuze07c3bfb5299c
diff --git a/scripts/build.sh b/scripts/build.sh
index c523fe5..67c3fa6 100755
--- a/scripts/build.sh
+++ b/scripts/build.sh
@@ -56,6 +56,7 @@ cat > "$APP/Contents/Info.plist" <<PLIST
<key>CFBundleExecutable</key> <string>copysyncd</string>
<key>CFBundleIdentifier</key> <string>com.copysync.daemon</string>
<key>CFBundleName</key> <string>CopySync Daemon</string>
+ <key>CFBundleDevelopmentRegion</key> <string>en</string>
<key>CFBundleIconFile</key> <string>AppIcon</string>
<key>CFBundlePackageType</key> <string>APPL</string>
<key>CFBundleShortVersionString</key> <string>$VERSION</string>
@@ -63,12 +64,26 @@ cat > "$APP/Contents/Info.plist" <<PLIST
<key>LSMinimumSystemVersion</key> <string>13.0</string>
<!-- 后台常驻:不出现在 Dock 与任务切换器里 -->
<key>LSUIElement</key> <true/>
+ <!-- macOS 15 起,后台服务连接局域网里的设备要经用户允许,系统弹窗里显示这段说明 -->
+ <key>NSLocalNetworkUsageDescription</key>
+ <string>CopySync finds your other computers on this network and syncs the clipboard with them directly.</string>
+ <key>NSBonjourServices</key>
+ <array><string>_copysync._udp</string></array>
</dict>
</plist>
PLIST
# 系统设置的「隐私与安全性」列表里会显示后台服务,给它同一个图标
mkdir -p "$APP/Contents/Resources"
cp assets/brand/AppIcon.icns "$APP/Contents/Resources/AppIcon.icns"
+# 本地网络权限弹窗里的说明,按系统语言显示
+localize() {
+ mkdir -p "$APP/Contents/Resources/$1.lproj"
+ printf '"NSLocalNetworkUsageDescription" = "%s";\n' "$2" \
+ > "$APP/Contents/Resources/$1.lproj/InfoPlist.strings"
+}
+localize en "CopySync finds your other computers on this network and syncs the clipboard with them directly."
+localize zh-Hans "CopySync 在局域网里查找你的其他电脑,直接与它们同步剪贴板。"
+localize ja "CopySync はこのネットワーク上のほかのコンピューターを見つけ、クリップボードを直接同期します。"
# ad-hoc 签名即可让 TCC 记住授权决定;正式分发应换成 Developer ID
codesign --force --sign - "$APP"
echo " ✓ $APP"
diff --git a/ui/lib/background_service.dart b/ui/lib/background_service.dart
index 2145273..37441df 100644
--- a/ui/lib/background_service.dart
+++ b/ui/lib/background_service.dart
@@ -64,6 +64,10 @@ class MacBackgroundService implements BackgroundService {
static const label = 'com.copysync.daemon';
+ /// 界面 App 的 bundle ID。写进登录项,系统才知道后台服务属于哪个 App:
+ /// macOS 15 的「本地网络」权限按它记账,登录项列表里也显示成 CopySync。
+ static const _appBundleId = 'com.copysync.app';
+
final String _executable;
final String _home;
@@ -93,7 +97,9 @@ class MacBackgroundService implements BackgroundService {
if (_runningFromTemporaryLocation) return ServiceState.mustMove;
final plist = File(plistPath);
if (!await plist.exists()) return ServiceState.notInstalled;
- if (!(await plist.readAsString()).contains(helperBinary)) return ServiceState.stale;
+ final content = await plist.readAsString();
+ // 1.4.0 之前写的登录项没有 AssociatedBundleIdentifiers,重新写一份
+ if (!content.contains(helperBinary) || !content.contains(_appBundleId)) return ServiceState.stale;
final r = await Process.run('launchctl', ['print', await _target()]);
if (r.exitCode != 0) return ServiceState.stopped;
return '${r.stdout}'.contains('state = running')
@@ -174,6 +180,10 @@ class MacBackgroundService implements BackgroundService {
<key>StandardOutPath</key> <string>${_xml(logPath)}</string>
<key>StandardErrorPath</key> <string>${_xml(logPath)}</string>
<key>ProcessType</key> <string>Interactive</string>
+ <key>AssociatedBundleIdentifiers</key>
+ <array>
+ <string>$_appBundleId</string>
+ </array>
</dict>
</plist>
''';