#!/bin/zsh set -euo pipefail ROOT_DIR="$(cd "$(dirname "$0")/.." && pwd)" APP_DIR="$ROOT_DIR/dist/boss-agent.app" CONTENTS_DIR="$APP_DIR/Contents" MACOS_DIR="$CONTENTS_DIR/MacOS" RESOURCES_DIR="$CONTENTS_DIR/Resources" SOURCE_FILE="$ROOT_DIR/apps/boss-agent-mac/Sources/BossAgentApp.swift" BINARY_PATH="$MACOS_DIR/boss-agent" ICONSET_DIR="$RESOURCES_DIR/BossAgent.iconset" ICON_PATH="$RESOURCES_DIR/BossAgent.icns" SIGNING_IDENTITY="${BOSS_AGENT_CODESIGN_IDENTITY:-}" if ! command -v swiftc >/dev/null 2>&1; then echo "swiftc not found. Install Xcode Command Line Tools first." >&2 exit 1 fi if ! command -v iconutil >/dev/null 2>&1; then echo "iconutil not found. Install Xcode Command Line Tools first." >&2 exit 1 fi if [[ -z "$SIGNING_IDENTITY" ]] && command -v security >/dev/null 2>&1; then SIGNING_IDENTITY="$( security find-identity -v -p codesigning 2>/dev/null \ | awk -F'"' '/"Apple Development:|Developer ID Application:|Mac Developer:|Boss Agent/ { print $2; exit }' )" fi if [[ -z "$SIGNING_IDENTITY" ]]; then SIGNING_IDENTITY="-" echo "boss-agent: no stable code signing identity found; falling back to ad-hoc signing." >&2 else echo "boss-agent: signing with identity: $SIGNING_IDENTITY" >&2 fi rm -rf "$APP_DIR" mkdir -p "$MACOS_DIR" "$RESOURCES_DIR" swiftc "$SOURCE_FILE" \ -o "$BINARY_PATH" \ -framework Cocoa \ -framework WebKit \ -framework ApplicationServices \ -framework AVFoundation \ -framework IOKit \ -framework Network \ -framework UserNotifications chmod +x "$BINARY_PATH" python3 - "$ICONSET_DIR" <<'PY' import os import struct import sys import zlib iconset_dir = sys.argv[1] os.makedirs(iconset_dir, exist_ok=True) targets = { "icon_16x16.png": 16, "icon_16x16@2x.png": 32, "icon_32x32.png": 32, "icon_32x32@2x.png": 64, "icon_128x128.png": 128, "icon_128x128@2x.png": 256, "icon_256x256.png": 256, "icon_256x256@2x.png": 512, "icon_512x512.png": 512, "icon_512x512@2x.png": 1024, } def rounded_rect(px, py, x0, y0, x1, y1, radius): cx = min(max(px, x0 + radius), x1 - radius) cy = min(max(py, y0 + radius), y1 - radius) return (px - cx) * (px - cx) + (py - cy) * (py - cy) <= radius * radius def rgba_at(px, py): if rounded_rect(px, py, 82, 82, 942, 942, 210): white = ( rounded_rect(px, py, 278, 245, 406, 779, 64) or rounded_rect(px, py, 350, 245, 745, 518, 132) or rounded_rect(px, py, 350, 506, 745, 779, 132) ) cutout = ( rounded_rect(px, py, 462, 332, 619, 438, 54) or rounded_rect(px, py, 462, 592, 635, 698, 54) ) if white and not cutout: return (255, 255, 255, 255) return (7, 193, 96, 255) if rounded_rect(px, py - 18, 82, 82, 942, 942, 210): return (7, 24, 16, 28) return (0, 0, 0, 0) def write_png(path, size): rows = [] for y in range(size): row = bytearray([0]) for x in range(size): px = (x + 0.5) * 1024 / size py = (y + 0.5) * 1024 / size row.extend(rgba_at(px, py)) rows.append(bytes(row)) raw = b"".join(rows) def chunk(kind, data): return ( struct.pack(">I", len(data)) + kind + data + struct.pack(">I", zlib.crc32(kind + data) & 0xFFFFFFFF) ) with open(path, "wb") as fp: fp.write(b"\x89PNG\r\n\x1a\n") fp.write(chunk(b"IHDR", struct.pack(">IIBBBBB", size, size, 8, 6, 0, 0, 0))) fp.write(chunk(b"IDAT", zlib.compress(raw, 9))) fp.write(chunk(b"IEND", b"")) for name, size in targets.items(): write_png(os.path.join(iconset_dir, name), size) PY iconutil -c icns "$ICONSET_DIR" -o "$ICON_PATH" rm -rf "$ICONSET_DIR" cat > "$CONTENTS_DIR/Info.plist" <<'PLIST' CFBundleDevelopmentRegion zh_CN CFBundleExecutable boss-agent CFBundleIdentifier com.hyzq.boss.agent CFBundleInfoDictionaryVersion 6.0 CFBundleName boss-agent CFBundleDisplayName boss-agent CFBundleIconFile BossAgent.icns CFBundleURLTypes CFBundleURLName com.hyzq.boss.agent CFBundleURLSchemes boss-agent CFBundlePackageType APPL CFBundleShortVersionString 0.1.0 CFBundleVersion 1 LSMinimumSystemVersion 13.0 NSHighResolutionCapable NSAppleEventsUsageDescription boss-agent 需要通过自动化控制 Finder、浏览器和授权的企业应用,以完成远程桌面级任务。 NSScreenCaptureUsageDescription boss-agent 需要读取屏幕画面,用于识别桌面状态、系统弹窗和远程控制结果。 NSInputMonitoringUsageDescription boss-agent 需要输入监控权限,用于低层热键、复杂输入和部分不可访问控件兜底。 NSMicrophoneUsageDescription boss-agent 需要麦克风权限,用于语音协作和远程指令输入。 NSCameraUsageDescription boss-agent 需要摄像头权限,用于视觉协作和现场画面确认。 NSLocalNetworkUsageDescription boss-agent 需要访问本地网络,用于发现和连接局域网设备、开发板和企业内网服务。 NSBonjourServices _http._tcp _boss-agent._tcp PLIST plutil -lint "$CONTENTS_DIR/Info.plist" >/dev/null codesign --force --deep --timestamp=none --sign "$SIGNING_IDENTITY" "$APP_DIR" >/dev/null echo "$APP_DIR"