From a0b77a3e7aaf52104a3f938c851640f5c4ba54f3 Mon Sep 17 00:00:00 2001 From: tongtongstudio Date: Sat, 28 Nov 2026 02:50:41 +0800 Subject: [PATCH] =?UTF-8?q?feat(installer):=20=E5=A2=9E=E5=8A=A0=20Windows?= =?UTF-8?q?=20=E5=92=8C=20Linux=20=E5=AE=89=E8=A3=85=E5=8C=85=E8=84=9A?= =?UTF-8?q?=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 增加 Inno Setup 安装器及运行库安装支持 - 增加 deb、rpm、AppImage 打包与完整 Release 目录校验 - 修复 WSL 打包权限和安装路径,补充构建说明及换行规则 --- .gitattributes | 2 + README.md | 2 + installer/README.md | 59 +++++++++++++ installer/linux/package.sh | 124 +++++++++++++++++++++++++++ installer/linux/ttstdconnect.desktop | 9 ++ installer/package.sh | 8 +- installer/windows/setup.iss | 33 +++++++ installer/windows/setup.ps1 | 53 ++++++++++++ 8 files changed, 283 insertions(+), 7 deletions(-) create mode 100644 .gitattributes create mode 100644 installer/README.md create mode 100644 installer/linux/package.sh create mode 100644 installer/linux/ttstdconnect.desktop create mode 100644 installer/windows/setup.iss create mode 100644 installer/windows/setup.ps1 diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..0396fd0 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +*.sh text eol=lf +*.desktop text eol=lf diff --git a/README.md b/README.md index a57314c..bcc89f5 100644 --- a/README.md +++ b/README.md @@ -581,6 +581,8 @@ POST /mirror/request?token= 触发一次投屏确认(便 ## 9. 落地里程碑 +桌面安装包构建方法见 [installer/README.md](installer/README.md):Windows Inno Setup 安装程序,以及 Linux deb、rpm、AppImage。 + | 阶段 | 内容 | 产出 | | --- | --- | --- | | M1 | mDNS 发现 + Android MediaProjection→H264→UDP→Windows Flutter 收流渲染(单向投屏) | 同网段能看画面 | diff --git a/installer/README.md b/installer/README.md new file mode 100644 index 0000000..8255387 --- /dev/null +++ b/installer/README.md @@ -0,0 +1,59 @@ +# 桌面安装包 + +安装包输出写入仓库 `dist/`,不提交构建产物。Linux 暂存目录位于 `${TMPDIR:-/tmp}`, +避免 WSL 挂载盘的权限导致 dpkg 拒绝打包;脚本打印暂存路径,保留供检查和手动清理。版本默认取 +`flutter_sender/pubspec.yaml` 的前三段版本号,可通过参数覆盖。 + +## Windows x64 + +需要 Windows Flutter/Visual Studio C++、Rust MSVC、Go、Inno Setup 6。 +从 Microsoft/Visual Studio 获取官方 `vc_redist.x64.exe`,安装器会运行它安装运行库 +(运行库安装可能请求管理员权限)。安装程序默认按当前用户安装,含开始菜单、可选桌面快捷方式、卸载入口。 + +```powershell +./installer/windows/setup.ps1 -VCRedist 'C:/path/to/vc_redist.x64.exe' +# 指定 Inno Setup 或使用已有的完整 Release 便携目录,跳过应用编译 +./installer/windows/setup.ps1 -Bundle './dist/TTSTDConnect-Windows' -Iscc 'C:/Program Files (x86)/Inno Setup 6/ISCC.exe' -VCRedist 'C:/path/to/vc_redist.x64.exe' -Version 0.1.0 +``` + +输出 `dist/windows/TTSTDConnect-<版本>-windows-x64-setup.exe`。默认执行 Rust 离线检查、 +单元测试、Release 构建,Flutter pub get、分析、Debug/Release 构建及 Go 信令构建; +先准备 Cargo 缓存(`cargo fetch --locked`)。已有 `package.ps1` 仍提供便携包。 + +## Linux x86_64 / WSL Ubuntu + +需要 Linux Flutter SDK、Clang、CMake、Ninja、pkg-config、GTK 开发包、Rust、Go +(版本满足 `signaling_server/go.mod`)。不要使用 Windows Flutter SDK。 + +Ubuntu 构建依赖示例: + +```bash +sudo apt install clang cmake ninja-build pkg-config libgtk-3-dev file dpkg-dev rpm +# Rust 依赖只需首次联网准备 +(cd rust_core && cargo fetch --locked) +bash installer/linux/package.sh --format deb +bash installer/linux/package.sh --format rpm +# 自行安装官方 appimagetool,或通过 APPIMAGETOOL 指定其路径 +APPIMAGETOOL=/path/to/appimagetool bash installer/linux/package.sh --format appimage +bash installer/package.sh --format all +``` + +输出在 `dist/linux/`,支持 `--version 0.1.0`。脚本先检查选定格式工具,再编译 Rust、 +Flutter Release 和 Go。包安装到 `/opt/ttstdconnect`,命令为 `ttstdconnect`,含桌面菜单入口。 +Rust 库与信令服务放在可执行文件旁。 + +已有完整 **Linux Release** bundle 时,可跳过应用编译: + +```bash +bash installer/linux/package.sh --format deb --bundle /absolute/path/to/bundle +``` + +该目录必须包含 `ttstd_sender`、`libttstdconnect_core.so`、`signaling_server`、 +`lib/libflutter_linux_gtk.so`、`lib/libapp.so`、`data/flutter_assets`;不接受 Debug bundle。 +Windows 和 Linux 共用源码目录时,先运行各自的 `flutter pub get`,避免另一平台的 SDK 缓存路径导致分析失败。 + +AppImage 打包工具自身若依赖 FUSE,可按其说明设置 `APPIMAGE_EXTRACT_AND_RUN=1`。 +AppImage 包含应用私有库,系统 GTK/glibc 等仍由目标系统提供;建议在最老的目标发行版编译, +Ubuntu 24.04 产物不保证能在较老发行版运行。deb/rpm 声明构建宿主机的 glibc 下限。 +RPM 的 License 暂按 Proprietary 填写(仓库尚无 LICENSE);发布前确认授权和维护者信息。 +这些脚本不增加 Linux 视频/音频插件,打包成功不代表投屏功能已补齐。 diff --git a/installer/linux/package.sh b/installer/linux/package.sh new file mode 100644 index 0000000..dd53af8 --- /dev/null +++ b/installer/linux/package.sh @@ -0,0 +1,124 @@ +#!/usr/bin/env bash +set -euo pipefail +ROOT="$(cd "$(dirname "$0")/../.." && pwd)" +FORMAT=all +BUNDLE="" +VERSION="$(sed -nE 's/^version: ([0-9]+\.[0-9]+\.[0-9]+).*/\1/p' "$ROOT/flutter_sender/pubspec.yaml")" +usage() { echo "Usage: bash installer/linux/package.sh [--format all|deb|rpm|appimage] [--bundle RELEASE_BUNDLE] [--version X.Y.Z]"; } +while (($#)); do + case "$1" in + --format|--bundle|--version) + (($# >= 2)) || { usage; exit 2; } + case "$1" in --format) FORMAT="$2";; --bundle) BUNDLE="$2";; --version) VERSION="$2";; esac + shift 2;; + -h|--help) usage; exit 0;; + *) usage; exit 2;; + esac +done +[[ "$FORMAT" =~ ^(all|deb|rpm|appimage)$ ]] || { usage; exit 2; } +[[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || { echo 'Invalid version' >&2; exit 2; } +[[ "$(uname -s)" == Linux && "$(uname -m)" == x86_64 ]] || { echo 'Linux x86_64 required' >&2; exit 1; } +need() { command -v "$1" >/dev/null || { echo "Required tool missing: $1" >&2; exit 1; }; } +need file +if [[ "$FORMAT" == all || "$FORMAT" == deb ]]; then need dpkg-deb; fi +if [[ "$FORMAT" == all || "$FORMAT" == rpm ]]; then need rpmbuild; fi +APPIMAGETOOL="${APPIMAGETOOL:-appimagetool}" +if [[ "$FORMAT" == all || "$FORMAT" == appimage ]]; then need "$APPIMAGETOOL"; fi +mkdir -p "$ROOT/dist/linux" +WORK="$(mktemp -d "${TMPDIR:-/tmp}/ttstdconnect-package.XXXXXX")" +# Use the Linux filesystem: WSL /mnt drives may expose every directory as 0777, +# which dpkg-deb rejects even after chmod. Keep staging for inspection. +echo "Staging: $WORK" +if [[ -z "$BUNDLE" ]]; then + for tool in cargo flutter dart go cmake; do need "$tool"; done + export CARGO_TARGET_DIR="$ROOT/rust_core/target/linux-package" + (cd "$ROOT/rust_core" && cargo check --offline && cargo test --offline --lib && cargo build --release --offline) + (cd "$ROOT/flutter_sender" && flutter pub get && dart analyze lib && + flutter build linux --release --no-pub --config-only && + cmake -S linux -B build/linux/x64/release -G Ninja -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_INSTALL_PREFIX="$ROOT/flutter_sender/build/linux/x64/release/bundle" && + flutter build linux --release --no-pub) + BUNDLE="$WORK/bundle" + mkdir -p "$BUNDLE" + cp -a "$ROOT/flutter_sender/build/linux/x64/release/bundle/." "$BUNDLE/" + cp "$CARGO_TARGET_DIR/release/libttstdconnect_core.so" "$BUNDLE/" + (cd "$ROOT/signaling_server" && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o "$BUNDLE/signaling_server" .) +fi +BUNDLE="$(cd "$BUNDLE" && pwd)" +for item in ttstd_sender libttstdconnect_core.so signaling_server lib/libflutter_linux_gtk.so lib/libapp.so data/flutter_assets; do + [[ -e "$BUNDLE/$item" ]] || { echo "Incomplete Release bundle: $item" >&2; exit 1; } +done +for binary in ttstd_sender libttstdconnect_core.so signaling_server; do + file "$BUNDLE/$binary" | grep -q 'ELF 64-bit.*x86-64' || { echo "Not Linux x86_64: $binary" >&2; exit 1; } +done +APPDIR="$WORK/AppDir" +mkdir -p "$APPDIR/opt/ttstdconnect" "$APPDIR/usr/bin" "$APPDIR/usr/share/applications" "$APPDIR/usr/share/icons/hicolor/256x256/apps" +cp -a "$BUNDLE/." "$APPDIR/opt/ttstdconnect/" +chmod 755 "$APPDIR/opt/ttstdconnect/ttstd_sender" "$APPDIR/opt/ttstdconnect/signaling_server" +ln -s ../../opt/ttstdconnect/ttstd_sender "$APPDIR/usr/bin/ttstdconnect" +cp "$ROOT/installer/linux/ttstdconnect.desktop" "$APPDIR/usr/share/applications/" +cp "$ROOT/flutter_sender/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png" "$APPDIR/usr/share/icons/hicolor/256x256/apps/ttstdconnect.png" +find "$APPDIR" -type d -exec chmod 755 {} + +find "$APPDIR" -type f -exec chmod 644 {} + +chmod 755 "$APPDIR/opt/ttstdconnect/ttstd_sender" "$APPDIR/opt/ttstdconnect/signaling_server" +OUT="$ROOT/dist/linux" +GLIBC_VERSION="$(getconf GNU_LIBC_VERSION | awk '{print $2}')" +if [[ "$FORMAT" == all || "$FORMAT" == deb ]]; then + DEB="$WORK/deb" + mkdir -p "$DEB/DEBIAN" + chmod 755 "$DEB/DEBIAN" + cp -a "$APPDIR/." "$DEB/" + cat > "$DEB/DEBIAN/control" < +Depends: libgtk-3-0, libglib2.0-0, libstdc++6, libc6 (>= $GLIBC_VERSION), libgcc-s1 +Description: TTSTDConnect desktop sender + Flutter desktop client with Rust core and local signaling server. +EOF + dpkg-deb --build --root-owner-group "$DEB" "$OUT/ttstdconnect_${VERSION}_amd64.deb" +fi +if [[ "$FORMAT" == all || "$FORMAT" == rpm ]]; then + RPM="$WORK/rpm" + mkdir -p "$RPM"/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS} + cat > "$RPM/SPECS/ttstdconnect.spec" <= $GLIBC_VERSION +%description +Flutter desktop client with Rust core and local signaling server. +%prep +%build +%install +mkdir -p %{buildroot} +cp -a "$APPDIR/." %{buildroot}/ +%files +%defattr(-,root,root,-) +/opt/ttstdconnect +/usr/bin/ttstdconnect +/usr/share/applications/ttstdconnect.desktop +/usr/share/icons/hicolor/256x256/apps/ttstdconnect.png +EOF + rpmbuild -bb --define "_topdir $RPM" --define '_build_id_links none' --define 'debug_package %{nil}' "$RPM/SPECS/ttstdconnect.spec" + cp "$RPM/RPMS/x86_64/ttstdconnect-$VERSION-1.x86_64.rpm" "$OUT/" +fi +if [[ "$FORMAT" == all || "$FORMAT" == appimage ]]; then + cp "$ROOT/installer/linux/ttstdconnect.desktop" "$APPDIR/" + cp "$APPDIR/usr/share/icons/hicolor/256x256/apps/ttstdconnect.png" "$APPDIR/" + cat > "$APPDIR/AppRun" <<'EOF' +#!/bin/sh +APPDIR="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)" +export LD_LIBRARY_PATH="$APPDIR/opt/ttstdconnect/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" +exec "$APPDIR/opt/ttstdconnect/ttstd_sender" "$@" +EOF + chmod 755 "$APPDIR/AppRun" + ARCH=x86_64 "$APPIMAGETOOL" "$APPDIR" "$OUT/TTSTDConnect-$VERSION-x86_64.AppImage" +fi +echo "Packages: $OUT" diff --git a/installer/linux/ttstdconnect.desktop b/installer/linux/ttstdconnect.desktop new file mode 100644 index 0000000..99d331b --- /dev/null +++ b/installer/linux/ttstdconnect.desktop @@ -0,0 +1,9 @@ +[Desktop Entry] +Type=Application +Name=TTSTDConnect +Comment=Android remote desktop sender +Exec=ttstdconnect +Icon=ttstdconnect +Terminal=false +Categories=Network;RemoteAccess; +StartupNotify=true diff --git a/installer/package.sh b/installer/package.sh index 2ea89e9..a961b77 100644 --- a/installer/package.sh +++ b/installer/package.sh @@ -18,13 +18,7 @@ case "$PLATFORM" in (cd "$SIGNAL_DIR" && go build -o "$DIST/ttstd_sender.app/Contents/MacOS/signaling_server" .) ;; Linux) - DIST="$ROOT/dist/TTSTDConnect-Linux" - mkdir -p "$DIST" - echo "构建 Flutter Linux 应用..." - (cd "$FLUTTER_DIR" && flutter build linux --release) - cp -R "$FLUTTER_DIR/build/linux/x64/release/bundle/." "$DIST/" - echo "构建内置信令服务..." - (cd "$SIGNAL_DIR" && go build -o "$DIST/signaling_server" .) + exec bash "$ROOT/installer/linux/package.sh" "$@" ;; *) echo "不支持的平台:$PLATFORM,请使用 installer/windows/package.ps1" >&2 diff --git a/installer/windows/setup.iss b/installer/windows/setup.iss new file mode 100644 index 0000000..a8a2d59 --- /dev/null +++ b/installer/windows/setup.iss @@ -0,0 +1,33 @@ +#ifndef AppVersion + #error AppVersion is required +#endif +[Setup] +AppId={{68CC5D47-729F-4E7B-875F-BA091EC0BF9D} +AppName=TTSTDConnect +AppVersion={#AppVersion} +AppPublisher=TTSTD +DefaultDirName={localappdata}\Programs\TTSTDConnect +DefaultGroupName=TTSTDConnect +PrivilegesRequired=lowest +MinVersion=10.0 +ArchitecturesAllowed=x64compatible +ArchitecturesInstallIn64BitMode=x64compatible +OutputDir={#OutputDir} +OutputBaseFilename=TTSTDConnect-{#AppVersion}-windows-x64-setup +SetupIconFile=..\..\flutter_sender\windows\runner\resources\app_icon.ico +UninstallDisplayIcon={app}\ttstd_sender.exe +Compression=lzma2 +SolidCompression=yes +WizardStyle=modern +CloseApplications=yes +[Tasks] +Name: desktopicon; Description: "Create a desktop shortcut"; Flags: unchecked +[Files] +Source: "{#VCRedist}"; DestDir: "{tmp}"; DestName: "vc_redist.x64.exe"; Flags: deleteafterinstall +Source: "{#BundleDir}\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs +[Icons] +Name: "{group}\TTSTDConnect"; Filename: "{app}\ttstd_sender.exe" +Name: "{autodesktop}\TTSTDConnect"; Filename: "{app}\ttstd_sender.exe"; Tasks: desktopicon +[Run] +Filename: "{tmp}\vc_redist.x64.exe"; Parameters: "/install /passive /norestart"; StatusMsg: "Installing Microsoft Visual C++ Runtime"; Flags: waituntilterminated +Filename: "{app}\ttstd_sender.exe"; Description: "Launch TTSTDConnect"; Flags: nowait postinstall skipifsilent diff --git a/installer/windows/setup.ps1 b/installer/windows/setup.ps1 new file mode 100644 index 0000000..9b4cf0d --- /dev/null +++ b/installer/windows/setup.ps1 @@ -0,0 +1,53 @@ +param( + [string]$Bundle, + [string]$Iscc, + [string]$Version, + [Parameter(Mandatory = $true)][string]$VCRedist +) +$ErrorActionPreference = 'Stop' +$root = (Resolve-Path (Join-Path $PSScriptRoot '../..')).Path +if (-not $Version) { + $Version = ([regex]::Match((Get-Content "$root/flutter_sender/pubspec.yaml" -Raw), '(?m)^version:\s*(\d+\.\d+\.\d+)')).Groups[1].Value +} +if ($Version -notmatch '^\d+\.\d+\.\d+$') { throw 'Version must be major.minor.patch' } +if (-not $Iscc) { + $command = Get-Command ISCC.exe -ErrorAction SilentlyContinue + if ($command) { $Iscc = $command.Source } + else { + foreach ($base in @(${env:ProgramFiles(x86)}, $env:ProgramFiles)) { + if ($base -and (Test-Path "$base/Inno Setup 6/ISCC.exe")) { $Iscc = "$base/Inno Setup 6/ISCC.exe"; break } + } + } +} +if (-not $Iscc -or -not (Test-Path -LiteralPath $Iscc)) { throw 'Install Inno Setup 6 or supply -Iscc path/to/ISCC.exe' } +$VCRedist = (Resolve-Path -LiteralPath $VCRedist).Path +function Invoke-Step([string]$Directory, [string]$Command, [string[]]$Arguments) { + Push-Location $Directory + try { + & $Command @Arguments + if ($LASTEXITCODE -ne 0) { throw "$Command failed: $LASTEXITCODE" } + } finally { Pop-Location } +} +$output = "$root/dist/windows" +New-Item -ItemType Directory -Force -Path $output | Out-Null +if (-not $Bundle) { + Invoke-Step "$root/rust_core" cargo @('check', '--offline') + Invoke-Step "$root/rust_core" cargo @('test', '--offline', '--lib') + Invoke-Step "$root/rust_core" cargo @('build', '--release', '--offline', '--target', 'x86_64-pc-windows-msvc', '--target-dir', "$root/rust_core/target") + Invoke-Step "$root/flutter_sender" flutter @('pub', 'get') + Invoke-Step "$root/flutter_sender" dart @('analyze', 'lib') + Invoke-Step "$root/flutter_sender" flutter @('build', 'windows', '--debug') + Invoke-Step "$root/flutter_sender" flutter @('build', 'windows', '--release') + $Bundle = Join-Path $output ('stage-' + [guid]::NewGuid().ToString('N')) + New-Item -ItemType Directory -Path $Bundle | Out-Null + Copy-Item "$root/flutter_sender/build/windows/x64/runner/Release/*" $Bundle -Recurse + Copy-Item "$root/rust_core/target/x86_64-pc-windows-msvc/release/ttstdconnect_core.dll" $Bundle + Invoke-Step "$root/signaling_server" go @('build', '-o', "$Bundle/signaling_server.exe", '.') +} +$Bundle = (Resolve-Path -LiteralPath $Bundle).Path +foreach ($file in @('ttstd_sender.exe', 'flutter_windows.dll', 'ttstdconnect_core.dll', 'signaling_server.exe', 'data/app.so', 'data/flutter_assets')) { + if (-not (Test-Path -LiteralPath (Join-Path $Bundle $file))) { throw "Incomplete Release bundle: $file" } +} +& $Iscc "/DAppVersion=$Version" "/DBundleDir=$Bundle" "/DOutputDir=$output" "/DVCRedist=$VCRedist" "$PSScriptRoot/setup.iss" +if ($LASTEXITCODE -ne 0) { throw "Inno Setup failed: $LASTEXITCODE" } +Write-Host "Installer: $output/TTSTDConnect-$Version-windows-x64-setup.exe"