feat: add Flutter USB mirroring and single-instance desktop clients

This commit is contained in:
tongtong committed 2026-11-12 23:16:56 +08:00
1 parent 3a7bb071f0
commit a339465392
30 files changed
+1688 -104

No files matched your search

+82
View File
@@ -0,0 +1,82 @@
param([switch]$SkipChecks)
$ErrorActionPreference = 'Stop'
$projectRoot = Split-Path $PSScriptRoot -Parent
Push-Location $PSScriptRoot
try {
if (-not $SkipChecks) {
flutter analyze
if ($LASTEXITCODE -ne 0) { throw 'Flutter analysis failed' }
flutter test
if ($LASTEXITCODE -ne 0) { throw 'Flutter tests failed' }
}
# Always select the production entry, even after running native smoke tests.
flutter build windows --release -t lib/main.dart
if ($LASTEXITCODE -ne 0) { throw 'Flutter Windows build failed' }
$stamp = [TimeZoneInfo]::ConvertTimeBySystemTimeZoneId([DateTimeOffset]::UtcNow, 'China Standard Time').ToString('yyyyMMdd-HHmmss')
$packageName = "flutter-win-x64-$stamp"
$packageDir = Join-Path $projectRoot "bin/$packageName"
if (Test-Path -LiteralPath $packageDir) { throw "Package already exists: $packageDir" }
New-Item -ItemType Directory -Path $packageDir | Out-Null
Copy-Item -Path (Join-Path $PSScriptRoot 'build/windows/x64/runner/Release/*') -Destination $packageDir -Recurse
foreach ($name in @('ads-client','ads-agent','adsctl','ads-usb')) {
$source = Join-Path $projectRoot "bin/$name.exe"
if (-not (Test-Path -LiteralPath $source)) { throw "Missing bundled tool: $name" }
Copy-Item -LiteralPath $source -Destination $packageDir
}
$scrcpy = Join-Path $projectRoot 'bin/tools/scrcpy'
foreach ($name in @('scrcpy.exe','scrcpy-server','adb.exe','SDL3.dll','LICENSE.txt')) {
if (-not (Test-Path -LiteralPath (Join-Path $scrcpy $name))) { throw "Missing scrcpy asset: $name" }
}
$tools = Join-Path $packageDir 'tools/scrcpy'
New-Item -ItemType Directory -Path $tools -Force | Out-Null
Copy-Item -Path (Join-Path $scrcpy '*') -Destination $tools -Recurse
& (Join-Path $projectRoot 'scripts/copy-windows-usb-driver.ps1') -Destination $packageDir
# Use the latest installed desktop x64 CRT, never the onecore/ARM variant.
$vswhere = Join-Path ${env:ProgramFiles(x86)} 'Microsoft Visual Studio/Installer/vswhere.exe'
$vsRoot = & $vswhere -latest -products '*' -property installationPath
if ($LASTEXITCODE -ne 0 -or -not $vsRoot) { throw 'Visual Studio installation not found' }
$crt = Get-ChildItem -Path (Join-Path $vsRoot 'VC/Redist/MSVC/*/x64/Microsoft.VC*.CRT') -Directory |
Sort-Object { [version]$_.Parent.Parent.Name } -Descending | Select-Object -First 1
if (-not $crt) { throw 'Visual C++ x64 redistributable libraries not found' }
Copy-Item -Path (Join-Path $crt.FullName '*.dll') -Destination $packageDir
foreach ($name in @('ads_manager.exe','flutter_windows.dll','vcruntime140.dll','msvcp140.dll','data/app.so','data/icudtl.dat','data/flutter_assets/assets/tray.ico')) {
if (-not (Test-Path -LiteralPath (Join-Path $packageDir $name))) { throw "Package missing: $name" }
}
$forbidden = Get-ChildItem -LiteralPath $packageDir -Recurse -File |
Where-Object { $_.Extension -in @('.env','.pem','.key','.pfx') -or $_.Name -in @('settings.json','admin.env','client.env','agent.env') }
if ($forbidden) { throw 'Private configuration detected in package' }
@(
'ADS Flutter Windows x64',
'Extract the entire ZIP and launch ads_manager.exe. Do not copy only the EXE.',
'Includes Flutter runtime, Microsoft Visual C++ x64 CRT, ads-client, ads-agent, adsctl, ads-usb, scrcpy and the optional signed USBip installer.',
'No Flutter SDK, Rust toolchain or .NET runtime is required on the target PC.',
'Import your own client.env in connection settings; Agent administration uses your own admin.env.',
'Credentials are not included. Existing non-secret settings remain in %LOCALAPPDATA%/TTSTD/ADS-Flutter.',
'Connect a device, then select the embedded screen button for Windows scrcpy mirroring.',
'Closing the main window keeps the app in the tray. Use the tray menu to exit.',
'Embedded mirroring currently uses software decoding/rendering. Mixed-monitor DPI and IME require further validation.'
) | Set-Content -LiteralPath (Join-Path $packageDir 'README-Windows.txt') -Encoding utf8
$revision = git -C $projectRoot rev-parse HEAD
$dirty = [bool](git -C $projectRoot status --porcelain)
$files = @(Get-ChildItem -LiteralPath $packageDir -File -Recurse | ForEach-Object {
[ordered]@{ path = [IO.Path]::GetRelativePath($packageDir, $_.FullName).Replace('\','/'); bytes = $_.Length; sha256 = (Get-FileHash -LiteralPath $_.FullName -Algorithm SHA256).Hash }
})
[ordered]@{
builtAt = $stamp; target = 'windows-x64'; entrypoint = 'lib/main.dart';
sourceRevision = $revision; sourceHasLocalChanges = $dirty;
backendSource = 'Existing project bin executables'; crtVersion = $crt.Parent.Parent.Name;
files = $files
} | ConvertTo-Json -Depth 5 | Set-Content -LiteralPath (Join-Path $packageDir 'manifest.json') -Encoding utf8
$zip = "$packageDir.zip"
Compress-Archive -LiteralPath $packageDir -DestinationPath $zip -CompressionLevel Optimal
$hash = (Get-FileHash -LiteralPath $zip -Algorithm SHA256).Hash
"$hash $packageName.zip" | Set-Content -LiteralPath "$zip.sha256" -Encoding ascii
Write-Host "PACKAGE=$packageDir"
Write-Host "ZIP=$zip"
Write-Host "SHA256=$hash"
} finally { Pop-Location }