#!/bin/bash set -e APP_NAME="crossdesk" APP_NAME_UPPER="CrossDesk" EXECUTABLE_PATH="build/macosx/x86_64/release/crossdesk" PLATFORM="macos" ARCH="x64" IDENTIFIER="cn.crossdesk.app" ICON_PATH="icons/macos/crossdesk.icns" MACOS_MIN_VERSION="10.12" normalize_app_version() { local input="$1" local prefix="" local body="$input" if [[ "$body" == v* ]]; then prefix="v" body="${body#v}" fi if [[ "$body" =~ ^([0-9]+(\.[0-9]+){1,3})-([0-9]{8})-([0-9]+)$ ]]; then echo "${prefix}${BASH_REMATCH[1]}-${BASH_REMATCH[4]}-${BASH_REMATCH[3]}" else echo "$input" fi } APP_VERSION="$(normalize_app_version "$1")" APP_BUNDLE="${APP_NAME_UPPER}.app" CONTENTS_DIR="${APP_BUNDLE}/Contents" MACOS_DIR="${CONTENTS_DIR}/MacOS" RESOURCES_DIR="${CONTENTS_DIR}/Resources" INSTALLER_TITLE="${APP_NAME_UPPER} ${APP_VERSION}" PKG_NAME="${APP_NAME}-${PLATFORM}-${ARCH}-${APP_VERSION}.pkg" DMG_NAME="${APP_NAME}-${PLATFORM}-${ARCH}-${APP_VERSION}.dmg" VOL_NAME="Install ${APP_NAME_UPPER}" echo "delete old files" rm -rf "${APP_BUNDLE}" "${PKG_NAME}" "${DMG_NAME}" build_pkg_temp CrossDesk_dmg_temp mkdir -p build_pkg_temp mkdir -p "${MACOS_DIR}" "${RESOURCES_DIR}" cp "${EXECUTABLE_PATH}" "${MACOS_DIR}/${APP_NAME_UPPER}" chmod +x "${MACOS_DIR}/${APP_NAME_UPPER}" if [ -f "${ICON_PATH}" ]; then cp "${ICON_PATH}" "${RESOURCES_DIR}/crossedesk.icns" ICON_KEY="CFBundleIconFilecrossedesk.icns" else ICON_KEY="" fi echo "generate Info.plist" cat > "${CONTENTS_DIR}/Info.plist" < CFBundleName ${APP_NAME_UPPER} CFBundleDisplayName ${APP_NAME_UPPER} CFBundleIdentifier ${IDENTIFIER} CFBundleVersion ${APP_VERSION} CFBundleShortVersionString ${APP_VERSION} CFBundleExecutable ${APP_NAME_UPPER} CFBundlePackageType APPL ${ICON_KEY} LSMinimumSystemVersion ${MACOS_MIN_VERSION} NSHighResolutionCapable NSCameraUsageDescription 应用需要访问摄像头 NSMicrophoneUsageDescription 应用需要访问麦克风 NSAppleEventsUsageDescription 应用需要发送 Apple 事件 NSScreenCaptureUsageDescription 应用需要录屏权限以捕获屏幕内容 EOF xattr -cr "${APP_BUNDLE}" 2>/dev/null || true find "${APP_BUNDLE}" -name '._*' -delete echo ".app created successfully." mkdir -p build_pkg_scripts cp scripts/macosx/tcc_postinstall.sh build_pkg_scripts/postinstall chmod +x build_pkg_scripts/postinstall mkdir -p build_pkg_resources cat > build_pkg_resources/welcome.html <

欢迎安装 ${INSTALLER_TITLE}

CrossDesk 将安装到“应用程序”文件夹。

首次启动时,CrossDesk 会引导你在系统设置中授予必要权限,包括辅助功能、录屏与系统录音等。

为避免旧版本授权残留造成状态误判,安装后可能需要重新授权。

安装完成后,请从“应用程序”文件夹启动 CrossDesk。

EOF echo "building pkg..." pkgbuild \ --identifier "${IDENTIFIER}" \ --version "${APP_VERSION}" \ --install-location "/Applications" \ --component "${APP_BUNDLE}" \ --scripts build_pkg_scripts \ build_pkg_temp/${APP_NAME}-component.pkg cat > build_pkg_temp/Distribution < ${INSTALLER_TITLE} crossdesk-component.pkg EOF productbuild \ --distribution build_pkg_temp/Distribution \ --package-path build_pkg_temp \ --resources build_pkg_resources \ "${PKG_NAME}" echo "PKG package created: ${PKG_NAME}" # Set custom icon for PKG file if [ -f "${ICON_PATH}" ]; then echo "Setting custom icon for PKG file..." # Create a temporary iconset from icns TEMP_ICON_DIR=$(mktemp -d) cp "${ICON_PATH}" "${TEMP_ICON_DIR}/icon.icns" # Use sips to create a png from icns for the icon sips -s format png "${TEMP_ICON_DIR}/icon.icns" --out "${TEMP_ICON_DIR}/icon.png" 2>/dev/null || true # Method: Use osascript to set file icon (works on macOS) osascript <