181 lines
5.5 KiB
Bash
181 lines
5.5 KiB
Bash
#!/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"
|
||
|
||
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
|
||
|
||
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'
|
||
<?xml version="1.0" encoding="UTF-8"?>
|
||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||
<plist version="1.0">
|
||
<dict>
|
||
<key>CFBundleDevelopmentRegion</key>
|
||
<string>zh_CN</string>
|
||
<key>CFBundleExecutable</key>
|
||
<string>boss-agent</string>
|
||
<key>CFBundleIdentifier</key>
|
||
<string>com.hyzq.boss.agent</string>
|
||
<key>CFBundleInfoDictionaryVersion</key>
|
||
<string>6.0</string>
|
||
<key>CFBundleName</key>
|
||
<string>boss-agent</string>
|
||
<key>CFBundleDisplayName</key>
|
||
<string>boss-agent</string>
|
||
<key>CFBundleIconFile</key>
|
||
<string>BossAgent.icns</string>
|
||
<key>CFBundleURLTypes</key>
|
||
<array>
|
||
<dict>
|
||
<key>CFBundleURLName</key>
|
||
<string>com.hyzq.boss.agent</string>
|
||
<key>CFBundleURLSchemes</key>
|
||
<array>
|
||
<string>boss-agent</string>
|
||
</array>
|
||
</dict>
|
||
</array>
|
||
<key>CFBundlePackageType</key>
|
||
<string>APPL</string>
|
||
<key>CFBundleShortVersionString</key>
|
||
<string>0.1.0</string>
|
||
<key>CFBundleVersion</key>
|
||
<string>1</string>
|
||
<key>LSMinimumSystemVersion</key>
|
||
<string>13.0</string>
|
||
<key>NSHighResolutionCapable</key>
|
||
<true/>
|
||
<key>NSAppleEventsUsageDescription</key>
|
||
<string>boss-agent 需要通过自动化控制 Finder、浏览器和授权的企业应用,以完成远程桌面级任务。</string>
|
||
<key>NSScreenCaptureUsageDescription</key>
|
||
<string>boss-agent 需要读取屏幕画面,用于识别桌面状态、系统弹窗和远程控制结果。</string>
|
||
<key>NSInputMonitoringUsageDescription</key>
|
||
<string>boss-agent 需要输入监控权限,用于低层热键、复杂输入和部分不可访问控件兜底。</string>
|
||
<key>NSMicrophoneUsageDescription</key>
|
||
<string>boss-agent 需要麦克风权限,用于语音协作和远程指令输入。</string>
|
||
<key>NSCameraUsageDescription</key>
|
||
<string>boss-agent 需要摄像头权限,用于视觉协作和现场画面确认。</string>
|
||
<key>NSLocalNetworkUsageDescription</key>
|
||
<string>boss-agent 需要访问本地网络,用于发现和连接局域网设备、开发板和企业内网服务。</string>
|
||
<key>NSBonjourServices</key>
|
||
<array>
|
||
<string>_http._tcp</string>
|
||
<string>_boss-agent._tcp</string>
|
||
</array>
|
||
</dict>
|
||
</plist>
|
||
PLIST
|
||
|
||
plutil -lint "$CONTENTS_DIR/Info.plist" >/dev/null
|
||
codesign --force --deep --sign - "$APP_DIR" >/dev/null
|
||
echo "$APP_DIR"
|