diff --git a/build/pkg-scripts/postinstall b/build/pkg-scripts/postinstall
index c37baa8..83e3afd 100644
--- a/build/pkg-scripts/postinstall
+++ b/build/pkg-scripts/postinstall
@@ -74,7 +74,9 @@ cat << EOF > "$LAUNCH_DAEMON"
Label
party.mihomo.helper
AssociatedBundleIdentifiers
- party.mihomo.app
+
+ party.mihomo.app
+
KeepAlive
Program
@@ -91,18 +93,62 @@ chown root:wheel "$LAUNCH_DAEMON"
chmod 644 "$LAUNCH_DAEMON"
log "LaunchDaemon configured"
-# 加载并启动服务
-log "Loading and starting service..."
-launchctl unload "$LAUNCH_DAEMON" 2>/dev/null || true
-if ! launchctl load "$LAUNCH_DAEMON"; then
- log "Error: Failed to load helper service"
+# 验证关键文件
+log "Verifying installation..."
+if [ ! -x "$HELPER_PATH" ]; then
+ log "Error: Helper tool is not executable: $HELPER_PATH"
exit 1
fi
-if ! launchctl start party.mihomo.helper; then
- log "Error: Failed to start helper service"
+# 检查二进制文件有效性
+if ! file "$HELPER_PATH" | grep -q "Mach-O"; then
+ log "Error: Helper tool is not a valid Mach-O binary"
exit 1
fi
+# 验证 plist 格式
+if ! plutil -lint "$LAUNCH_DAEMON" >/dev/null 2>&1; then
+ log "Error: Invalid plist format"
+ exit 1
+fi
+
+# 获取 macOS 版本
+macos_version=$(sw_vers -productVersion)
+macos_major=$(echo "$macos_version" | cut -d. -f1)
+log "macOS version: $macos_version"
+
+# 清理现有服务
+log "Cleaning up existing services..."
+launchctl bootout system "$LAUNCH_DAEMON" 2>/dev/null || true
+launchctl unload "$LAUNCH_DAEMON" 2>/dev/null || true
+
+# 加载服务
+log "Loading service..."
+if [ "$macos_major" -ge 11 ]; then
+ # macOS Big Sur 及更新版本使用 bootstrap
+ if ! launchctl bootstrap system "$LAUNCH_DAEMON"; then
+ log "Bootstrap failed, trying legacy load..."
+ if ! launchctl load "$LAUNCH_DAEMON"; then
+ log "Error: Failed to load service with both methods"
+ exit 1
+ fi
+ fi
+else
+ # 旧版本使用 load
+ if ! launchctl load "$LAUNCH_DAEMON"; then
+ log "Error: Failed to load service"
+ exit 1
+ fi
+fi
+
+# 验证服务状态
+log "Verifying service status..."
+sleep 2
+if launchctl list | grep -q "party.mihomo.helper"; then
+ log "Service loaded successfully"
+else
+ log "Warning: Service may not be running properly"
+fi
+
log "Installation completed successfully"
exit 0