diff --git a/AGENTS.md b/AGENTS.md
index 2a8e707..158c0c0 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -24,7 +24,7 @@
| `crates/` | Rust 工作区共享库容器 | Rust、TOML |
| `crates/ads-management/` | Agent 配置及管理协议、Windows 命名管道/Unix socket、私有文件与系统服务操作;源码在 `src/` | Rust、TOML |
| `crates/ads-core/` | 共用网络与协议代码,包括 WSS、WebRTC P2P、节点回退、ADB smart socket 和流式转发;源码在 `src/` | Rust、TOML |
-| `flutter_manager/` | 独立 Flutter Windows 管理中心,使用 Cupertino UI,提供电脑分组设备、Agent 管理、按天滚动日志、多设备连接、虚拟 USB、托盘与内嵌投屏 | Dart、C++、CMake、YAML、ICO |
+| `flutter_manager/` | Flutter Windows/Linux 管理中心,使用 Cupertino UI,提供电脑分组设备、Agent 管理、滚动日志、多设备连接与投屏;Windows 支持内嵌投屏和可选 USB,Linux 使用独立投屏 | Dart、C++、CMake、YAML、ICO、PNG |
| `desktop/` | 跨平台桌面客户端及其测试项目、.NET SDK 配置与使用说明 | C#、Avalonia XAML(AXAML)、JSON、Markdown |
| `desktop/Ads.Desktop/` | Avalonia 多设备工作台,管理独立连接、自动端口分配、USB 模拟、多个 scrcpy 窗口、电脑名、按天滚动日志及托盘;`Assets/` 保存图标资源 | C#、AXAML、XML(csproj)、PNG |
| `desktop/Ads.Desktop.Tests/` | 桌面客户端单元测试 | C#、XML(csproj) |
@@ -48,7 +48,7 @@
## 可选 USB 模拟功能(Windows 已开始实现)
-用户于 2026-11-12 授权新增可选 USB 模拟,先实现 Windows。当前采用独立 Rust USB/IP 虚拟 ADB 设备 + 已签名的 USBip UDE 控制器,复用现有网络隧道,包含桌面开关、驱动检测和安装脚本;详见 docs/windows-usb.md。Linux 已按 2026-11-13 新授权完成原生 USB/IP CLI 验证,见 docs/linux-usb.md;Avalonia Linux GUI 已接入 pkexec 挂载;Flutter Linux GUI 尚未接入。macOS 仍仅记录方案。以下跨平台内容保留为设计依据。
+用户于 2026-11-12 授权新增可选 USB 模拟,先实现 Windows。当前采用独立 Rust USB/IP 虚拟 ADB 设备 + 已签名的 USBip UDE 控制器,复用现有网络隧道,包含桌面开关、驱动检测和安装脚本;详见 docs/windows-usb.md。Linux 已按 2026-11-13 新授权完成原生 USB/IP CLI 验证,见 docs/linux-usb.md;Avalonia Linux GUI 已接入 pkexec 挂载;Flutter Linux GUI 已支持网络 ADB 和独立投屏,USB 挂载界面尚未接入。macOS 仍仅记录方案。以下跨平台内容保留为设计依据。
### 目标与范围
diff --git a/Cargo.lock b/Cargo.lock
index 3cde02a..3387196 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -4,7 +4,7 @@ version = 4
[[package]]
name = "ads-agent"
-version = "0.2.4"
+version = "0.2.5"
dependencies = [
"ads-core",
"ads-management",
@@ -21,7 +21,7 @@ dependencies = [
[[package]]
name = "ads-client"
-version = "0.2.4"
+version = "0.2.5"
dependencies = [
"ads-core",
"anyhow",
@@ -32,7 +32,7 @@ dependencies = [
[[package]]
name = "ads-core"
-version = "0.2.4"
+version = "0.2.5"
dependencies = [
"anyhow",
"bytes",
@@ -51,7 +51,7 @@ dependencies = [
[[package]]
name = "ads-management"
-version = "0.2.4"
+version = "0.2.5"
dependencies = [
"ads-core",
"anyhow",
@@ -67,7 +67,7 @@ dependencies = [
[[package]]
name = "ads-usb"
-version = "0.2.4"
+version = "0.2.5"
dependencies = [
"anyhow",
"clap",
@@ -78,7 +78,7 @@ dependencies = [
[[package]]
name = "adsctl"
-version = "0.2.4"
+version = "0.2.5"
dependencies = [
"ads-core",
"ads-management",
diff --git a/Cargo.toml b/Cargo.toml
index 8ee10a8..76988ac 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -3,7 +3,7 @@ members = ["crates/ads-core", "agent", "client", "usb", "crates/ads-management",
resolver = "2"
[workspace.package]
-version = "0.2.4"
+version = "0.2.5"
edition = "2021"
license = "MIT"
diff --git a/README.md b/README.md
index 853fa8f..1080ce7 100644
--- a/README.md
+++ b/README.md
@@ -33,7 +33,7 @@ Windows 现支持可选的 [USB ADB 模拟](docs/windows-usb.md),默认网络
| `crates/` | Rust 工作区共享库容器 | Rust、TOML |
| `crates/ads-management/` | Agent 配置及管理协议、Windows 命名管道/Unix socket、私有文件与系统服务操作;源码在 `src/` | Rust、TOML |
| `crates/ads-core/` | 共用网络与协议代码,包括 WSS、WebRTC P2P、节点回退、ADB smart socket 和流式转发;源码在 `src/` | Rust、TOML |
-| `flutter_manager/` | 独立 Flutter Windows 管理中心,使用 Cupertino UI,提供电脑分组设备、Agent 管理、按天滚动日志、多设备连接、虚拟 USB、托盘与内嵌投屏 | Dart、C++、CMake、YAML、ICO |
+| `flutter_manager/` | Flutter Windows/Linux 管理中心,使用 Cupertino UI,提供电脑分组设备、Agent 管理、滚动日志、多设备连接与投屏;Windows 支持内嵌投屏和可选 USB,Linux 使用独立投屏 | Dart、C++、CMake、YAML、ICO、PNG |
| `desktop/` | 跨平台桌面客户端及其测试项目、.NET SDK 配置与使用说明 | C#、Avalonia XAML(AXAML)、JSON、Markdown |
| `desktop/Ads.Desktop/` | Avalonia 多设备工作台,管理独立连接、自动端口分配、USB 模拟、多个 scrcpy 窗口及托盘;`Assets/` 保存图标资源 | C#、AXAML、XML(csproj)、PNG |
| `desktop/Ads.Desktop.Tests/` | 桌面客户端单元测试 | C#、XML(csproj) |
@@ -230,7 +230,7 @@ Agent 管理发行入口:`scripts/build-desktop.ps1` 生成 `bin/desktop-win-x
Linux 安装包:`bash scripts/build-linux-packages.sh`,提供 `.deb` 安装包,详见 [Linux 打包](docs/linux-packaging.md)。
-Linux 原生虚拟 USB 已在 Ubuntu 实机通过 CLI 验证,部署和权限说明见 [Linux USB](docs/linux-usb.md)。Avalonia Linux GUI 已接入 pkexec 挂载,Flutter Linux 尚未接入。
+Linux 原生虚拟 USB 已在 Ubuntu 实机通过 CLI 验证,部署和权限说明见 [Linux USB](docs/linux-usb.md)。Avalonia Linux GUI 已接入 pkexec 挂载;Flutter Linux 支持网络 ADB 和独立投屏,USB 界面尚未接入。
Flutter 管理中心已迁移 Cupertino UI,设备按电脑归属分组,支持按电脑名搜索;运行日志按天保存并按大小滚动,路径及策略见 [Flutter 使用说明](flutter_manager/README.md)。
diff --git a/desktop/Ads.Desktop/Ads.Desktop.csproj b/desktop/Ads.Desktop/Ads.Desktop.csproj
index 67013f8..20b0fa2 100644
--- a/desktop/Ads.Desktop/Ads.Desktop.csproj
+++ b/desktop/Ads.Desktop/Ads.Desktop.csproj
@@ -1,4 +1,4 @@
- 0.2.4WinExenet8.0enableenable
+ 0.2.5WinExenet8.0enableenable
diff --git a/docs/linux-packaging.md b/docs/linux-packaging.md
index 00d8cfe..0a65081 100644
--- a/docs/linux-packaging.md
+++ b/docs/linux-packaging.md
@@ -11,9 +11,9 @@ bash scripts/build-linux-packages.sh agent
输出 `bin/installers/linux/` 中的 `.deb` 与 SHA256SUMS。Deb 安装路径 `/opt/ttstd/ads-*`,桌面端添加应用菜单,命令入口 `/usr/bin/ads-*`。通过 `sudo apt install ./包名.deb` 安装并解析依赖,同名包覆盖升级,通过 `sudo apt remove ads-avalonia` 等卸载。不会自动注册或启动 Agent 服务;用 adsctl 初始化并显式安装 systemd 服务,详见 agent-management.md。私有配置不放入包中,卸载不删除用户数据。
-可用 ADS_LINUX_BIN 指定 ads-agent/ads-client/adsctl 所在目录,ADS_SERVER_BIN 指定服务端产物目录,ADS_AVALONIA_BUNDLE 指定已构建的原生 Avalonia 目录并跳过 publish。包会检查 ELF 格式及机器架构,拒绝 Windows EXE 和私有配置。Linux 虚拟 USB 已有原生 CLI 实机验证,需另部署 ads-usb 和系统 usbip/vhci_hcd,见 linux-usb.md;Avalonia 桌面开关已接入,Flutter Linux 尚未接入。
+可用 ADS_LINUX_BIN 指定 ads-agent/ads-client/adsctl 所在目录,ADS_SERVER_BIN 指定服务端产物目录,ADS_AVALONIA_BUNDLE 指定已构建的原生 Avalonia 目录并跳过 publish。包会检查 ELF 格式及机器架构,拒绝 Windows EXE 和私有配置。Linux 虚拟 USB 已有原生 CLI 实机验证,需另部署 ads-usb 和系统 usbip/vhci_hcd,见 linux-usb.md;Avalonia 桌面开关已接入,Flutter Linux 尚未接入 USB 界面,网络 ADB 和独立投屏已支持。
-Flutter 当前仓库没有 Linux 原生宿主,不能直接从 Windows bundle 生成 Linux 应用。打包入口 `ADS_FLUTTER_BUNDLE=/path/to/linux/bundle bash scripts/build-linux-packages.sh flutter` 仅用于后续完成 Linux 宿主与工具路径适配后的原生产物,当前不宣称 Flutter Linux 已可用。
+Flutter 已加入 Linux GTK 原生宿主。`bash scripts/build-linux-packages.sh flutter` 可原生构建并生成 deb;`ADS_FLUTTER_BUNDLE=/path/to/linux/bundle` 可使用预先构建的同版本 Linux bundle。设置 `ADS_SCRCPY_BUNDLE` 可携带已校验的 Linux adb/scrcpy 完整发行目录,程序及插件会检查 ELF 架构,运行库仍由 apt 解析。Linux 使用独立投屏窗口,Windows 内嵌投屏及 USB 驱动界面不在 Linux 提供。详见 flutter_manager/README.md。
本次已生成并检查 amd64 三类包的元数据与归档,Agent 包解压后的 adsctl 可执行;Avalonia 使用 Windows .NET SDK 发布原生 linux-x64 产物。Linux 桌面图形会话启动、实际 apt 安装/卸载与 arm64 尚未实机验证。校验文件需在输出目录执行 `sha256sum -c SHA256SUMS`。
@@ -36,3 +36,11 @@ ads-usb --help
`deploy/deb-cli-links.sh`(Shell)生成 deb 的 postinst/prerm/postrm 脚本;文件触发器处理旧版 Agent 直接拥有 `/usr/bin/adsctl`、`ads-agent` 时的升级与卸载。不会自动初始化、启动或重启 Agent,不删除用户配置或凭据。
维护脚本回归:Linux 中以 root 执行 `python3 tests/deb_cli_test.py`。测试在临时 dpkg 根目录安装、升级、移除测试包,守卫拒绝没有 `--root` 的 alternatives 调用,不改宿主 `/usr/bin`。设置 `ADS_DEB_PACKAGE_DIR` 为正式包目录,可额外验证实际 deb 及 CLI 版本(仅隔离测试允许忽略运行库依赖;正常安装请使用 apt)。
+
+## Flutter 0.2.5 amd64
+
+已在 Ubuntu 24.04 原生编译并验证 GTK 窗口和插件启动,Linux/Windows 各 35 项 Flutter 测试通过。`ads-flutter_0.2.5_amd64.deb` 自带 ADB、scrcpy 5.0.1、Rust 四个 CLI、Flutter 引擎和插件,安装时由 apt 解析 GTK/AppIndicator 等系统运行库,运行不需要 Flutter SDK。通过 `sudo apt install ./ads-flutter_0.2.5_amd64.deb` 安装,菜单或 `ads-flutter` 启动。
+
+Linux 配置和日志使用 XDG config/state 目录;关闭窗口时退出并释放本客户端连接。Linux 投屏采用独立 scrcpy 窗口;Windows 专属内嵌和 USB 驱动 UI 不在此版本 Linux 桌面提供。arm64 构建入口保留,但本次仅交付并验证 amd64。
+
+使用正式 Flutter 包进行隔离测试时,测试宿主需满足 deb 声明的最低 glibc 版本;force-depends 仅跳过临时根空 dpkg 数据库中的依赖登记,不能绕过执行时的 ABI 要求。
diff --git a/docs/verification.md b/docs/verification.md
index b31667f..b036088 100644
--- a/docs/verification.md
+++ b/docs/verification.md
@@ -91,3 +91,13 @@ Port cleanup follow-up:
- 优先级为 Agent 80、Avalonia 60、Flutter 50;保留手动 alternatives 选择及既有同名普通文件。prerm/postrm 撤销当前包,剩余包自动回退,最后一个提供者移除后清理公共及 alternatives 链接。
- 文件触发器处理 0.2.3 旧 Agent 包直接拥有两个 /usr/bin 命令的过渡:升级或移除旧包后,剩余桌面提供者重新注册。不会自动启动/重启 Agent 或删除用户配置。
- 6 项隔离 dpkg 生命周期测试通过,覆盖共存、重装、手动选择、桌面切换、旧 Agent 升级/移除、普通文件保护和正式 0.2.4 deb。真实包安装后四个原生工具的 --version 均为 0.2.4,移除 Agent 后均回退桌面路径。测试使用临时根和 alternatives 守卫,不修改宿主 /usr/bin;GUI 依赖在临时根用 force-depends 跳过,真实系统仍应使用 apt 正常解析依赖。
+
+### 0.2.5:Flutter Linux 原生 deb
+
+- 新增 Linux GTK 宿主、Linux 原生构建脚本及 deb 入口。SDK 为 Flutter 3.50.0 / Dart 3.14.0,Linux SDK 归档按官方发布清单 SHA256 校验;Ubuntu 24.04 原生编译,未使用 Windows bundle 冒充 Linux 程序。
+- Linux 配置使用 XDG_CONFIG_HOME/ads-flutter,日志使用 XDG_STATE_HOME/ads-flutter/logs,缺省分别为 ~/.config 与 ~/.local/state;Windows 原有设置位置保留。托盘使用 PNG,Linux 文件选择不过滤为 .exe。
+- Linux 投屏使用独立窗口,Windows 内嵌及 USB 驱动 UI 禁用;运行时模型也防止错误开启。Linux 正常关闭窗口退出,避免没有托盘扩展时程序隐藏后无法恢复;已规避旧窗口插件销毁 Linux implicit view 的退出警告。
+- Linux 和 Windows 各 35 项 Flutter 测试通过,双平台静态分析无问题;真实 Ubuntu 桌面临时单元执行 --package-check 输出 ADS_FLUTTER_PACKAGE_OK,状态 0,不读取真实配置、凭据或建立设备连接。
+- Linux 包携带已验证的原生 ADB / scrcpy 5.0.1 完整发行资源及 LICENSE、Rust 四个 CLI 和应用菜单,检查 ELF 架构和动态库。六项隔离 dpkg 生命周期测试包含正式 Flutter deb、命令链接、CLI 版本和卸载回退。GUI 依赖由 apt 解析,完整 apt 仓库解析及 arm64 未在本轮实机验证。
+
+最终正式包验证在 Ubuntu 24.04 的临时 dpkg 根完成:6 项全部通过,包含随包 ADB/scrcpy 执行和 CLI 版本;正式 deb 解包后以 TT 普通用户在桌面会话启动 --package-check,输出 ADS_FLUTTER_PACKAGE_OK,退出 0。包声明 glibc >=2.35;本地旧 WSL 的 glibc 低于要求,因此随包 scrcpy 的执行验证转到目标 Ubuntu 完成,未放宽测试断言。
diff --git a/flutter_manager/.metadata b/flutter_manager/.metadata
index 38b73aa..d83b17f 100644
--- a/flutter_manager/.metadata
+++ b/flutter_manager/.metadata
@@ -18,6 +18,9 @@ migration:
- platform: windows
create_revision: ab2912035e160d9cad6306df307576da6128ebdb
base_revision: ab2912035e160d9cad6306df307576da6128ebdb
+ - platform: linux
+ create_revision: ab2912035e160d9cad6306df307576da6128ebdb
+ base_revision: ab2912035e160d9cad6306df307576da6128ebdb
# User provided section
diff --git a/flutter_manager/README.md b/flutter_manager/README.md
index 2375f33..4e0549d 100644
--- a/flutter_manager/README.md
+++ b/flutter_manager/README.md
@@ -1,4 +1,4 @@
-# ADS Flutter 管理中心(Windows)
+# ADS Flutter 管理中心(Windows / Linux)
独立 Flutter 工程,复用现有控制中心 API 与 ads-client 子进程,不修改原有 Avalonia、Rust 或 Go 实现。
@@ -22,7 +22,7 @@ flutter build windows --release
- 中继节点:显示控制中心 /v2/nodes 的健康与通道使用情况;旧服务器无该接口时为空。
- 本机 ADB:启动本地 ADB Server、读取 devices -l,包括本机 USB 及网络设备。
- 投屏:Windows 下点击“内嵌投屏”,将官方 scrcpy 窗口嵌入管理端,鼠标键盘直接控制;返回设备页后隐藏画面,点击“查看投屏”恢复。可停止投屏而保留设备连接。使用 --force-adb-forward,最大边长 1920、60 FPS、关闭音频。
-- 托盘:关闭主窗口后保留连接,托盘打开窗口、断开全部、退出。完全退出会停止本应用启动的进程并断开所属 ADB 地址。
+- 托盘:Windows 关闭主窗口后保留连接;Linux 关闭主窗口时正常退出。托盘可打开窗口、断开全部、退出。完全退出会停止本应用启动的进程并断开所属 ADB 地址。
- 配置:保存非敏感设置、导入 client.env、检查三个可执行程序;凭据不写入设置,子进程通过环境变量接收令牌。
- 自动每 12 秒同步控制中心,每 3 秒检查 ADB 状态,连接重试由 ads-client 负责。
@@ -37,10 +37,13 @@ flutter build windows --release
| lib/ | 应用入口及分层业务源码 | Dart |
| lib/data/ | 配置、HTTP API、工具发现、ADB 与子进程生命周期 | Dart |
| lib/ui/ | ChangeNotifier 状态与管理界面 | Dart |
-| assets/ | 托盘图标资源 | ICO,无业务源码 |
+| assets/ | 托盘图标资源 | ICO、PNG,无业务源码 |
| windows/ | Flutter Windows 原生宿主、scrcpy 子窗口承载与插件注册 | C++、CMake、资源文件;部分自动生成 |
+| linux/ | Flutter Linux GTK 原生宿主及构建入口 | C++、CMake |
+| linux/runner/ | GTK 应用、窗口与 Dart 入口参数传递 | C++、CMake |
+| linux/flutter/ | Flutter SDK 桥接、生成的插件注册和临时缓存;ephemeral/ 为自动生成产物 | C++、CMake;部分自动生成,无手写业务逻辑 |
| test/ | 凭据、URL 与不同窗口宽度的界面验证 | Dart |
-| build/ | Flutter 生成的 Windows 发行与缓存(忽略) | 构建产物,无业务源码 |
+| build/ | Flutter 生成的 Windows/Linux 发行与缓存(忽略) | 构建产物,无业务源码 |
| .dart_tool/ | Dart/Flutter 生成缓存(忽略) | JSON 等,无业务源码 |
## 检查
@@ -139,3 +142,21 @@ USB ADB 连续 3 轮监控缺失(约 9 秒)、USB 后端退出或 scrcpy 以
Windows 宿主、Flutter C++ 包装库和源码插件统一使用静态 MSVC CRT,保留 Flutter 引擎及插件 DLL。安装打包使用 `scripts/check-windows-crt.py`(Python 标准库 PE 导入及延迟导入检查),只附带实际需要的 MSVC 运行库及其传递依赖,缺失则拒绝发布;Rust 工具仍需的运行库不会被误删。
工具位置由 `lib/data/tool_paths.dart`(Dart)统一解析:识别 TTSTD/TongTongStudio 旧安装路径,优先使用当前应用附带工具;有效自定义工具保持不变,失效路径可回退当前安装或 PATH。启动和每次连接时迁移并保存 client/adb/scrcpy 路径;缺少工具先提示重新安装或选择文件,尚未分配连接端口。用户配置与凭据位置不随安装目录变化。
+
+## Linux 原生构建与 deb
+
+需要 Linux Flutter 3.50 / Dart 3.14、clang、cmake、ninja、pkg-config、GTK 3 开发库和 libayatana-appindicator3-dev。Windows bundle 不能转换为 Linux 应用,必须在 Linux 原生编译。
+
+```sh
+bash scripts/build-flutter-linux.sh
+# 一次新发布,自动递增补丁版本、构建 Rust 工具和 Flutter 并打 deb
+bash scripts/build-linux-packages.sh flutter
+```
+
+上面的脚本从仓库根目录运行。可设置 `FLUTTER_BIN` 指定 SDK,`ADS_SCRCPY_BUNDLE` 指定已校验的原生 Linux scrcpy 完整目录(包含 adb、scrcpy、scrcpy-server 和 LICENSE);脚本检查 ELF 架构。当前 amd64 发行包自带 scrcpy 5.0.1/ADB 工具,避免系统旧 scrcpy 不支持 `--no-audio`。若不提供工具 bundle,deb 依赖系统 adb 和 scrcpy >=2.0。
+
+Linux 配置位于 `${XDG_CONFIG_HOME:-$HOME/.config}/ads-flutter/settings.json`,日志位于 `${XDG_STATE_HOME:-$HOME/.local/state}/ads-flutter/logs/`,按天滚动。Windows 继续使用现有 LOCALAPPDATA 位置。凭据通过界面导入,不包含在发布包中。
+
+Linux 使用独立 scrcpy 窗口,网络 ADB、多设备和 Agent 管理复用现有后端;Windows 专属内嵌投屏和 USB 驱动入口在 Linux 禁用,Linux USB 可使用独立 ads-usb CLI。安装 deb 后自动提供 /usr/bin 的四个 CLI 链接及应用菜单,支持共存和卸载回退。
+
+`ads-flutter --package-check` 可在有桌面会话的 Linux 中验证原生窗口与插件:使用临时日志,跳过真实配置、凭据和设备初始化,随后自行退出。CLI 本身可在无 GUI 的机器运行。
diff --git a/flutter_manager/analysis_options.yaml b/flutter_manager/analysis_options.yaml
index 1694f65..bbe0145 100644
--- a/flutter_manager/analysis_options.yaml
+++ b/flutter_manager/analysis_options.yaml
@@ -3,6 +3,7 @@ analyzer:
exclude:
- build/**
- windows/**
+ - linux/**
language:
strict-casts: true
strict-inference: true
diff --git a/flutter_manager/assets/tray.png b/flutter_manager/assets/tray.png
new file mode 100644
index 0000000..3d1f7be
Binary files /dev/null and b/flutter_manager/assets/tray.png differ
diff --git a/flutter_manager/lib/data/app_paths.dart b/flutter_manager/lib/data/app_paths.dart
new file mode 100644
index 0000000..30ccf6b
--- /dev/null
+++ b/flutter_manager/lib/data/app_paths.dart
@@ -0,0 +1,37 @@
+import 'dart:io';
+
+import 'package:path/path.dart' as p;
+
+/// Stable per-user locations, independent of the installed bundle and cwd.
+class AppPaths {
+ static String configuration({
+ Map? environment,
+ bool? windows,
+ }) {
+ final env = environment ?? Platform.environment;
+ final isWindows = windows ?? Platform.isWindows;
+ final paths = p.Context(style: isWindows ? p.Style.windows : p.Style.posix);
+ final home = env['HOME'] ?? env['USERPROFILE'] ?? Directory.systemTemp.path;
+ return isWindows
+ ? paths.join(env['LOCALAPPDATA'] ?? home, 'TTSTD', 'ADS-Flutter')
+ : paths.join(
+ env['XDG_CONFIG_HOME'] ?? paths.join(home, '.config'),
+ 'ads-flutter',
+ );
+ }
+
+ static String logs({Map? environment, bool? windows}) {
+ final env = environment ?? Platform.environment;
+ final isWindows = windows ?? Platform.isWindows;
+ if (isWindows) {
+ return p.Context(style: p.Style.windows)
+ .join(configuration(environment: env, windows: true), 'logs');
+ }
+ final home = env['HOME'] ?? Directory.systemTemp.path;
+ return p.posix.join(
+ env['XDG_STATE_HOME'] ?? p.posix.join(home, '.local', 'state'),
+ 'ads-flutter',
+ 'logs',
+ );
+ }
+}
diff --git a/flutter_manager/lib/data/manager_repository.dart b/flutter_manager/lib/data/manager_repository.dart
index 2f22787..733b868 100644
--- a/flutter_manager/lib/data/manager_repository.dart
+++ b/flutter_manager/lib/data/manager_repository.dart
@@ -7,6 +7,7 @@ import 'package:path/path.dart' as p;
import 'windows_usb.dart';
import 'usb_recovery.dart';
import 'tool_paths.dart';
+import 'app_paths.dart';
class Settings {
String server = 'wss://ttstd.com/ads';
@@ -100,13 +101,7 @@ class ManagerRepository {
ManagerRepository(this.log, {this.paths});
Future init() async {
- storage = Directory(
- p.join(
- Platform.environment['LOCALAPPDATA'] ?? Directory.systemTemp.path,
- 'TTSTD',
- 'ADS-Flutter',
- ),
- );
+ storage = Directory(AppPaths.configuration());
await storage.create(recursive: true);
for (final start in [
Directory.current.path,
@@ -140,6 +135,7 @@ class ManagerRepository {
jsonDecode(await saved.readAsString()) as Map,
);
}
+ if (!Platform.isWindows) settings.usbMode = false;
await repairToolPaths();
token = Platform.environment['ADS_CLIENT_TOKEN'] ?? '';
if (token.isEmpty && await File(settings.credential).exists()) {
@@ -354,6 +350,9 @@ class ManagerRepository {
configured: settings.adb,
required: true,
);
+ if (settings.usbMode && !Platform.isWindows) {
+ throw UnsupportedError("Linux 桌面端请使用网络 ADB;USB 模拟可使用 ads-usb CLI。");
+ }
final usbMode = settings.usbMode;
final usbip = settings.usbip;
if (usbMode) {
@@ -626,6 +625,7 @@ class ManagerRepository {
}
Future screen(Session s, {bool embedded = false}) async {
+ embedded = embedded && Platform.isWindows;
if (s.stopping) {
return;
}
diff --git a/flutter_manager/lib/main.dart b/flutter_manager/lib/main.dart
index 041ab49..6255bd1 100644
--- a/flutter_manager/lib/main.dart
+++ b/flutter_manager/lib/main.dart
@@ -10,13 +10,33 @@ import 'package:tray_manager/tray_manager.dart';
import 'package:window_manager/window_manager.dart';
import 'ui/manager_model.dart';
+import 'data/daily_log.dart';
import 'ui/manager_view.dart';
-Future main() async {
+Future _closeWindowForExit() async {
+ // Older window_manager Linux backends try to remove Flutter's implicit view.
+ // Flush application state, hide the GTK window, then let process exit own cleanup.
+ if (Platform.isLinux) {
+ await windowManager.hide();
+ } else {
+ await windowManager.destroy();
+ }
+}
+
+Future main(List args) async {
WidgetsFlutterBinding.ensureInitialized();
await windowManager.ensureInitialized();
- final model = ManagerModel();
+ final packageCheck = args.contains('--package-check');
+ final temporary = packageCheck
+ ? Directory.systemTemp.createTempSync('ads-flutter-package-')
+ : null;
+ final model = ManagerModel(
+ logWriter: temporary == null ? null : DailyLog(temporary),
+ );
+ if (temporary != null) model.repository.storage = temporary;
+ var failed = false;
FlutterError.onError = (details) {
+ failed = true;
FlutterError.presentError(details);
scheduleMicrotask(
() => model.log(
@@ -25,6 +45,7 @@ Future main() async {
);
};
PlatformDispatcher.instance.onError = (error, stack) {
+ failed = true;
scheduleMicrotask(() => model.log('[Unhandled] $error\n$stack'));
return true;
};
@@ -41,6 +62,18 @@ Future main() async {
await windowManager.focus();
},
);
+ if (packageCheck) {
+ await Future.delayed(const Duration(seconds: 3));
+ await model.shutdown();
+ if (temporary != null) await temporary.delete(recursive: true);
+ stdout.writeln(
+ failed ? 'ADS_FLUTTER_PACKAGE_FAILED' : 'ADS_FLUTTER_PACKAGE_OK',
+ );
+ await stdout.flush();
+ await trayManager.destroy();
+ await _closeWindowForExit();
+ exit(failed ? 1 : 0);
+ }
unawaited(model.init());
}
@@ -64,7 +97,9 @@ class _ManagerAppState extends State
Future initTray() async {
try {
- await trayManager.setIcon('assets/tray.ico');
+ await trayManager.setIcon(
+ Platform.isWindows ? 'assets/tray.ico' : 'assets/tray.png',
+ );
await trayManager.setToolTip('ADS Flutter 设备管理');
await trayManager.setContextMenu(
Menu(
@@ -91,13 +126,13 @@ class _ManagerAppState extends State
quitting = true;
await widget.model.shutdown();
await trayManager.destroy();
- await windowManager.destroy();
+ await _closeWindowForExit();
exit(0);
}
@override
void onWindowClose() {
- if (trayReady) {
+ if (trayReady && Platform.isWindows) {
widget.model.repository.allowEmbeddedResume = false;
unawaited(windowManager.hide());
} else {
diff --git a/flutter_manager/lib/ui/manager_model.dart b/flutter_manager/lib/ui/manager_model.dart
index 4a99597..c058bde 100644
--- a/flutter_manager/lib/ui/manager_model.dart
+++ b/flutter_manager/lib/ui/manager_model.dart
@@ -5,6 +5,7 @@ import 'package:flutter/foundation.dart';
import '../data/manager_repository.dart';
import '../data/agent_repository.dart';
import '../data/daily_log.dart';
+import '../data/app_paths.dart';
import '../data/agent_service.dart';
import 'agent_model.dart';
@@ -12,21 +13,7 @@ import 'dart:io';
import 'package:path/path.dart' as p;
-DailyLog defaultLog() => DailyLog(
- Directory(
- p.join(
- Platform.environment['LOCALAPPDATA'] ??
- p.join(
- Platform.environment['HOME'] ?? Directory.systemTemp.path,
- '.local',
- 'share',
- ),
- 'TTSTD',
- 'ADS-Flutter',
- 'logs',
- ),
- ),
-);
+DailyLog defaultLog() => DailyLog(Directory(AppPaths.logs()));
class ManagerModel extends ChangeNotifier {
late final ManagerRepository repository;
diff --git a/flutter_manager/lib/ui/manager_view.dart b/flutter_manager/lib/ui/manager_view.dart
index 08339d7..701c718 100644
--- a/flutter_manager/lib/ui/manager_view.dart
+++ b/flutter_manager/lib/ui/manager_view.dart
@@ -434,8 +434,11 @@ class _ManagerViewState extends State {
onPressed: pending || !s.ready
? null
: () => m.deviceAction(d.id, () async {
- await m.repository.screen(s, embedded: true);
- if (mounted) {
+ await m.repository.screen(
+ s,
+ embedded: Platform.isWindows,
+ );
+ if (mounted && Platform.isWindows) {
setState(() {
s.screenPageVisible = true;
screenDevice = s.id;
@@ -444,7 +447,11 @@ class _ManagerViewState extends State {
}
}),
icon: const Icon(Icons.open_in_new, size: 16),
- label: Text(s.screen == null ? '内嵌投屏' : '查看投屏'),
+ label: Text(
+ Platform.isWindows
+ ? (s.screen == null ? '内嵌投屏' : '查看投屏')
+ : '独立窗口投屏',
+ ),
),
OutlinedButton(
onPressed: pending ? null : () => m.disconnect(d.id),
@@ -717,7 +724,7 @@ class _SettingsViewState extends State {
s.adb = fields['adb']!.text.trim();
s.scrcpy = fields['scrcpy']!.text.trim();
s.relayOnly = relayOnly;
- s.usbMode = usbMode;
+ s.usbMode = Platform.isWindows && usbMode;
s.usbip = fields['usbip']!.text.trim();
}
@@ -752,10 +759,10 @@ class _SettingsViewState extends State {
('server', '控制中心 WSS 地址'),
('origin', '直连服务器(可留空)'),
('credential', '客户端凭据文件 client.env'),
- ('client', 'ads-client.exe 路径'),
- ('adb', 'adb.exe 路径'),
- ('scrcpy', 'scrcpy.exe 路径(需保留完整发行目录)'),
- ('usbip', 'usbip.exe 路径'),
+ ('client', 'ads-client 路径'),
+ ('adb', 'adb 路径'),
+ ('scrcpy', 'scrcpy 路径(需保留完整发行目录)'),
+ if (Platform.isWindows) ('usbip', 'usbip.exe 路径'),
])
Padding(
padding: const EdgeInsets.only(bottom: 18),
@@ -794,20 +801,28 @@ class _SettingsViewState extends State {
contentPadding: EdgeInsets.zero,
value: usbMode,
title: const Text('挂载为 USB 设备 · Windows'),
- subtitle: Text('仅模拟 ADB;修改在下次连接生效。$usbStatus'),
- onChanged: installingUsb ? null : changeUsb,
+ subtitle: Text(
+ Platform.isWindows
+ ? '仅模拟 ADB;修改在下次连接生效。$usbStatus'
+ : 'Linux 当前使用网络 ADB;USB 模拟可在终端使用 ads-usb。',
+ ),
+ onChanged: installingUsb || !Platform.isWindows
+ ? null
+ : changeUsb,
),
Wrap(
spacing: 12,
children: [
OutlinedButton(
- onPressed: installingUsb
+ onPressed: installingUsb || !Platform.isWindows
? null
: () => changeUsb(usbMode, detectOnly: true),
child: const Text('检测 USB 组件'),
),
TextButton(
- onPressed: installingUsb ? null : installUsb,
+ onPressed: installingUsb || !Platform.isWindows
+ ? null
+ : installUsb,
child: Text(installingUsb ? '等待驱动安装完成…' : '安装 USBip 驱动'),
),
],
diff --git a/flutter_manager/lib/ui/path_picker.dart b/flutter_manager/lib/ui/path_picker.dart
index 25fce0b..eebe405 100644
--- a/flutter_manager/lib/ui/path_picker.dart
+++ b/flutter_manager/lib/ui/path_picker.dart
@@ -9,7 +9,7 @@ Future pickPath(String value, {bool executable = false}) async {
initialDirectory: directory != null && Directory(directory).existsSync()
? directory
: null,
- acceptedTypeGroups: executable
+ acceptedTypeGroups: executable && Platform.isWindows
? [
const XTypeGroup(label: '可执行程序', extensions: ['exe']),
]
diff --git a/flutter_manager/linux/.gitignore b/flutter_manager/linux/.gitignore
new file mode 100644
index 0000000..d3896c9
--- /dev/null
+++ b/flutter_manager/linux/.gitignore
@@ -0,0 +1 @@
+flutter/ephemeral
diff --git a/flutter_manager/linux/CMakeLists.txt b/flutter_manager/linux/CMakeLists.txt
new file mode 100644
index 0000000..0beb1f4
--- /dev/null
+++ b/flutter_manager/linux/CMakeLists.txt
@@ -0,0 +1,128 @@
+# Project-level configuration.
+cmake_minimum_required(VERSION 3.13)
+project(runner LANGUAGES CXX)
+
+# The name of the executable created for the application. Change this to change
+# the on-disk name of your application.
+set(BINARY_NAME "ads_manager")
+# The unique GTK application identifier for this application. See:
+# https://wiki.gnome.org/HowDoI/ChooseApplicationID
+set(APPLICATION_ID "com.ttstd.ads.ads_manager")
+
+# Explicitly opt in to modern CMake behaviors to avoid warnings with recent
+# versions of CMake.
+cmake_policy(SET CMP0063 NEW)
+
+# Load bundled libraries from the lib/ directory relative to the binary.
+set(CMAKE_INSTALL_RPATH "$ORIGIN/lib")
+
+# Root filesystem for cross-building.
+if(FLUTTER_TARGET_PLATFORM_SYSROOT)
+ set(CMAKE_SYSROOT ${FLUTTER_TARGET_PLATFORM_SYSROOT})
+ set(CMAKE_FIND_ROOT_PATH ${CMAKE_SYSROOT})
+ set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
+ set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
+ set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
+ set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
+endif()
+
+# Define build configuration options.
+if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
+ set(CMAKE_BUILD_TYPE "Debug" CACHE
+ STRING "Flutter build mode" FORCE)
+ set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
+ "Debug" "Profile" "Release")
+endif()
+
+# Compilation settings that should be applied to most targets.
+#
+# Be cautious about adding new options here, as plugins use this function by
+# default. In most cases, you should add new options to specific targets instead
+# of modifying this function.
+function(APPLY_STANDARD_SETTINGS TARGET)
+ target_compile_features(${TARGET} PUBLIC cxx_std_14)
+ target_compile_options(${TARGET} PRIVATE -Wall -Werror)
+ target_compile_options(${TARGET} PRIVATE "$<$>:-O3>")
+ target_compile_definitions(${TARGET} PRIVATE "$<$>:NDEBUG>")
+endfunction()
+
+# Flutter library and tool build rules.
+set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter")
+add_subdirectory(${FLUTTER_MANAGED_DIR})
+
+# System-level dependencies.
+find_package(PkgConfig REQUIRED)
+pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0)
+
+# Application build; see runner/CMakeLists.txt.
+add_subdirectory("runner")
+
+# Run the Flutter tool portions of the build. This must not be removed.
+add_dependencies(${BINARY_NAME} flutter_assemble)
+
+# Only the install-generated bundle's copy of the executable will launch
+# correctly, since the resources must in the right relative locations. To avoid
+# people trying to run the unbundled copy, put it in a subdirectory instead of
+# the default top-level location.
+set_target_properties(${BINARY_NAME}
+ PROPERTIES
+ RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run"
+)
+
+
+# Generated plugin build rules, which manage building the plugins and adding
+# them to the application.
+include(flutter/generated_plugins.cmake)
+
+
+# === Installation ===
+# By default, "installing" just makes a relocatable bundle in the build
+# directory.
+set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle")
+if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
+ set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE)
+endif()
+
+# Start with a clean build bundle directory every time.
+install(CODE "
+ file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\")
+ " COMPONENT Runtime)
+
+set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data")
+set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib")
+
+install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}"
+ COMPONENT Runtime)
+
+install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}"
+ COMPONENT Runtime)
+
+install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
+ COMPONENT Runtime)
+
+foreach(bundled_library ${PLUGIN_BUNDLED_LIBRARIES})
+ install(FILES "${bundled_library}"
+ DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
+ COMPONENT Runtime)
+endforeach(bundled_library)
+
+# Copy the native assets provided by the hook/build.dart from all packages.
+set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/linux/")
+install(DIRECTORY "${NATIVE_ASSETS_DIR}"
+ DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
+ COMPONENT Runtime)
+
+# Fully re-copy the assets directory on each build to avoid having stale files
+# from a previous install.
+set(FLUTTER_ASSET_DIR_NAME "flutter_assets")
+install(CODE "
+ file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\")
+ " COMPONENT Runtime)
+install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}"
+ DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime)
+
+# Install the AOT library on non-Debug builds only.
+if(NOT CMAKE_BUILD_TYPE MATCHES "Debug")
+ install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
+ COMPONENT Runtime)
+endif()
diff --git a/flutter_manager/linux/flutter/CMakeLists.txt b/flutter_manager/linux/flutter/CMakeLists.txt
new file mode 100644
index 0000000..d5bd016
--- /dev/null
+++ b/flutter_manager/linux/flutter/CMakeLists.txt
@@ -0,0 +1,88 @@
+# This file controls Flutter-level build steps. It should not be edited.
+cmake_minimum_required(VERSION 3.10)
+
+set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral")
+
+# Configuration provided via flutter tool.
+include(${EPHEMERAL_DIR}/generated_config.cmake)
+
+# TODO: Move the rest of this into files in ephemeral. See
+# https://github.com/flutter/flutter/issues/57146.
+
+# Serves the same purpose as list(TRANSFORM ... PREPEND ...),
+# which isn't available in 3.10.
+function(list_prepend LIST_NAME PREFIX)
+ set(NEW_LIST "")
+ foreach(element ${${LIST_NAME}})
+ list(APPEND NEW_LIST "${PREFIX}${element}")
+ endforeach(element)
+ set(${LIST_NAME} "${NEW_LIST}" PARENT_SCOPE)
+endfunction()
+
+# === Flutter Library ===
+# System-level dependencies.
+find_package(PkgConfig REQUIRED)
+pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0)
+pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET glib-2.0)
+pkg_check_modules(GIO REQUIRED IMPORTED_TARGET gio-2.0)
+
+set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/libflutter_linux_gtk.so")
+
+# Published to parent scope for install step.
+set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE)
+set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE)
+set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE)
+set(AOT_LIBRARY "${PROJECT_DIR}/build/lib/libapp.so" PARENT_SCOPE)
+
+list(APPEND FLUTTER_LIBRARY_HEADERS
+ "fl_basic_message_channel.h"
+ "fl_binary_codec.h"
+ "fl_binary_messenger.h"
+ "fl_dart_project.h"
+ "fl_engine.h"
+ "fl_json_message_codec.h"
+ "fl_json_method_codec.h"
+ "fl_message_codec.h"
+ "fl_method_call.h"
+ "fl_method_channel.h"
+ "fl_method_codec.h"
+ "fl_method_response.h"
+ "fl_plugin_registrar.h"
+ "fl_plugin_registry.h"
+ "fl_standard_message_codec.h"
+ "fl_standard_method_codec.h"
+ "fl_string_codec.h"
+ "fl_value.h"
+ "fl_view.h"
+ "flutter_linux.h"
+)
+list_prepend(FLUTTER_LIBRARY_HEADERS "${EPHEMERAL_DIR}/flutter_linux/")
+add_library(flutter INTERFACE)
+target_include_directories(flutter INTERFACE
+ "${EPHEMERAL_DIR}"
+)
+target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}")
+target_link_libraries(flutter INTERFACE
+ PkgConfig::GTK
+ PkgConfig::GLIB
+ PkgConfig::GIO
+)
+add_dependencies(flutter flutter_assemble)
+
+# === Flutter tool backend ===
+# _phony_ is a non-existent file to force this command to run every time,
+# since currently there's no way to get a full input/output list from the
+# flutter tool.
+add_custom_command(
+ OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS}
+ ${CMAKE_CURRENT_BINARY_DIR}/_phony_
+ COMMAND ${CMAKE_COMMAND} -E env
+ ${FLUTTER_TOOL_ENVIRONMENT}
+ "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.sh"
+ ${FLUTTER_TARGET_PLATFORM} ${CMAKE_BUILD_TYPE}
+ VERBATIM
+)
+add_custom_target(flutter_assemble DEPENDS
+ "${FLUTTER_LIBRARY}"
+ ${FLUTTER_LIBRARY_HEADERS}
+)
diff --git a/flutter_manager/linux/flutter/generated_plugin_registrant.cc b/flutter_manager/linux/flutter/generated_plugin_registrant.cc
new file mode 100644
index 0000000..f398f58
--- /dev/null
+++ b/flutter_manager/linux/flutter/generated_plugin_registrant.cc
@@ -0,0 +1,27 @@
+//
+// Generated file. Do not edit.
+//
+
+// clang-format off
+
+#include "generated_plugin_registrant.h"
+
+#include
+#include
+#include
+#include
+
+void fl_register_plugins(FlPluginRegistry* registry) {
+ g_autoptr(FlPluginRegistrar) file_selector_linux_registrar =
+ fl_plugin_registry_get_registrar_for_plugin(registry, "FileSelectorPlugin");
+ file_selector_plugin_register_with_registrar(file_selector_linux_registrar);
+ g_autoptr(FlPluginRegistrar) screen_retriever_linux_registrar =
+ fl_plugin_registry_get_registrar_for_plugin(registry, "ScreenRetrieverLinuxPlugin");
+ screen_retriever_linux_plugin_register_with_registrar(screen_retriever_linux_registrar);
+ g_autoptr(FlPluginRegistrar) tray_manager_registrar =
+ fl_plugin_registry_get_registrar_for_plugin(registry, "TrayManagerPlugin");
+ tray_manager_plugin_register_with_registrar(tray_manager_registrar);
+ g_autoptr(FlPluginRegistrar) window_manager_registrar =
+ fl_plugin_registry_get_registrar_for_plugin(registry, "WindowManagerPlugin");
+ window_manager_plugin_register_with_registrar(window_manager_registrar);
+}
diff --git a/flutter_manager/linux/flutter/generated_plugin_registrant.h b/flutter_manager/linux/flutter/generated_plugin_registrant.h
new file mode 100644
index 0000000..e0f0a47
--- /dev/null
+++ b/flutter_manager/linux/flutter/generated_plugin_registrant.h
@@ -0,0 +1,15 @@
+//
+// Generated file. Do not edit.
+//
+
+// clang-format off
+
+#ifndef GENERATED_PLUGIN_REGISTRANT_
+#define GENERATED_PLUGIN_REGISTRANT_
+
+#include
+
+// Registers Flutter plugins.
+void fl_register_plugins(FlPluginRegistry* registry);
+
+#endif // GENERATED_PLUGIN_REGISTRANT_
diff --git a/flutter_manager/linux/flutter/generated_plugins.cmake b/flutter_manager/linux/flutter/generated_plugins.cmake
new file mode 100644
index 0000000..b44f33f
--- /dev/null
+++ b/flutter_manager/linux/flutter/generated_plugins.cmake
@@ -0,0 +1,27 @@
+#
+# Generated file, do not edit.
+#
+
+list(APPEND FLUTTER_PLUGIN_LIST
+ file_selector_linux
+ screen_retriever_linux
+ tray_manager
+ window_manager
+)
+
+list(APPEND FLUTTER_FFI_PLUGIN_LIST
+)
+
+set(PLUGIN_BUNDLED_LIBRARIES)
+
+foreach(plugin ${FLUTTER_PLUGIN_LIST})
+ add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/linux plugins/${plugin})
+ target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin)
+ list(APPEND PLUGIN_BUNDLED_LIBRARIES $)
+ list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries})
+endforeach(plugin)
+
+foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST})
+ add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/linux plugins/${ffi_plugin})
+ list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries})
+endforeach(ffi_plugin)
diff --git a/flutter_manager/linux/runner/CMakeLists.txt b/flutter_manager/linux/runner/CMakeLists.txt
new file mode 100644
index 0000000..e97dabc
--- /dev/null
+++ b/flutter_manager/linux/runner/CMakeLists.txt
@@ -0,0 +1,26 @@
+cmake_minimum_required(VERSION 3.13)
+project(runner LANGUAGES CXX)
+
+# Define the application target. To change its name, change BINARY_NAME in the
+# top-level CMakeLists.txt, not the value here, or `flutter run` will no longer
+# work.
+#
+# Any new source files that you add to the application should be added here.
+add_executable(${BINARY_NAME}
+ "main.cc"
+ "my_application.cc"
+ "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc"
+)
+
+# Apply the standard set of build settings. This can be removed for applications
+# that need different build settings.
+apply_standard_settings(${BINARY_NAME})
+
+# Add preprocessor definitions for the application ID.
+add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}")
+
+# Add dependency libraries. Add any application-specific dependencies here.
+target_link_libraries(${BINARY_NAME} PRIVATE flutter)
+target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK)
+
+target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}")
diff --git a/flutter_manager/linux/runner/main.cc b/flutter_manager/linux/runner/main.cc
new file mode 100644
index 0000000..e7c5c54
--- /dev/null
+++ b/flutter_manager/linux/runner/main.cc
@@ -0,0 +1,6 @@
+#include "my_application.h"
+
+int main(int argc, char** argv) {
+ g_autoptr(MyApplication) app = my_application_new();
+ return g_application_run(G_APPLICATION(app), argc, argv);
+}
diff --git a/flutter_manager/linux/runner/my_application.cc b/flutter_manager/linux/runner/my_application.cc
new file mode 100644
index 0000000..e6c6ac8
--- /dev/null
+++ b/flutter_manager/linux/runner/my_application.cc
@@ -0,0 +1,129 @@
+#include "my_application.h"
+
+#include
+
+#include "flutter/generated_plugin_registrant.h"
+
+struct _MyApplication {
+ GtkApplication parent_instance;
+ char** dart_entrypoint_arguments;
+};
+
+G_DEFINE_TYPE(MyApplication, my_application, GTK_TYPE_APPLICATION)
+
+// Called when first Flutter frame received.
+static void first_frame_cb(MyApplication* self, FlView* view) {
+ gtk_widget_show(gtk_widget_get_toplevel(GTK_WIDGET(view)));
+}
+
+// Implements GApplication::activate.
+static void my_application_activate(GApplication* application) {
+ MyApplication* self = MY_APPLICATION(application);
+
+ GtkWindow* window =
+ GTK_WINDOW(gtk_application_window_new(GTK_APPLICATION(application)));
+ gtk_window_set_default_size(window, 1280, 720);
+
+ // If you want to use a header bar, uncomment the following lines.
+ // Header bars are commonly used in GNOME based desktop environments and
+ // allow additional widgets to be added to the title bar.
+ // See https://docs.gtk.org/gtk3/class.HeaderBar.html
+ // GtkHeaderBar* header_bar = GTK_HEADER_BAR(gtk_header_bar_new());
+ // gtk_widget_show(GTK_WIDGET(header_bar));
+ // gtk_header_bar_set_show_close_button(header_bar, TRUE);
+ // gtk_window_set_titlebar(window, GTK_WIDGET(header_bar));
+
+ gtk_window_set_title(window, "ads_manager");
+
+ g_autoptr(FlDartProject) project = fl_dart_project_new();
+ fl_dart_project_set_dart_entrypoint_arguments(
+ project, self->dart_entrypoint_arguments);
+
+ FlView* view = fl_view_new(project);
+ GdkRGBA background_color;
+ // Background defaults to black, override it here if necessary, e.g. #00000000
+ // for transparent.
+ gdk_rgba_parse(&background_color, "#000000");
+ fl_view_set_background_color(view, &background_color);
+ gtk_widget_show(GTK_WIDGET(view));
+ gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(view));
+
+ // Show the window when Flutter renders.
+ // Requires the view to be realized so we can start rendering.
+ g_signal_connect_swapped(view, "first-frame", G_CALLBACK(first_frame_cb),
+ self);
+ gtk_widget_realize(GTK_WIDGET(view));
+
+ fl_register_plugins(FL_PLUGIN_REGISTRY(view));
+
+ gtk_widget_grab_focus(GTK_WIDGET(view));
+}
+
+// Implements GApplication::local_command_line.
+static gboolean my_application_local_command_line(GApplication* application,
+ gchar*** arguments,
+ int* exit_status) {
+ MyApplication* self = MY_APPLICATION(application);
+ // Strip out the first argument as it is the binary name.
+ self->dart_entrypoint_arguments = g_strdupv(*arguments + 1);
+
+ g_autoptr(GError) error = nullptr;
+ if (!g_application_register(application, nullptr, &error)) {
+ g_warning("Failed to register: %s", error->message);
+ *exit_status = 1;
+ return TRUE;
+ }
+
+ g_application_activate(application);
+ *exit_status = 0;
+
+ return TRUE;
+}
+
+// Implements GApplication::startup.
+static void my_application_startup(GApplication* application) {
+ // MyApplication* self = MY_APPLICATION(object);
+
+ // Perform any actions required at application startup.
+
+ G_APPLICATION_CLASS(my_application_parent_class)->startup(application);
+}
+
+// Implements GApplication::shutdown.
+static void my_application_shutdown(GApplication* application) {
+ // MyApplication* self = MY_APPLICATION(object);
+
+ // Perform any actions required at application shutdown.
+
+ G_APPLICATION_CLASS(my_application_parent_class)->shutdown(application);
+}
+
+// Implements GObject::dispose.
+static void my_application_dispose(GObject* object) {
+ MyApplication* self = MY_APPLICATION(object);
+ g_clear_pointer(&self->dart_entrypoint_arguments, g_strfreev);
+ G_OBJECT_CLASS(my_application_parent_class)->dispose(object);
+}
+
+static void my_application_class_init(MyApplicationClass* klass) {
+ G_APPLICATION_CLASS(klass)->activate = my_application_activate;
+ G_APPLICATION_CLASS(klass)->local_command_line =
+ my_application_local_command_line;
+ G_APPLICATION_CLASS(klass)->startup = my_application_startup;
+ G_APPLICATION_CLASS(klass)->shutdown = my_application_shutdown;
+ G_OBJECT_CLASS(klass)->dispose = my_application_dispose;
+}
+
+static void my_application_init(MyApplication* self) {}
+
+MyApplication* my_application_new() {
+ // Set the program name to the application ID, which helps various systems
+ // like GTK and desktop environments map this running application to its
+ // corresponding .desktop file. This ensures better integration by allowing
+ // the application to be recognized beyond its binary name.
+ g_set_prgname(APPLICATION_ID);
+
+ return MY_APPLICATION(g_object_new(my_application_get_type(),
+ "application-id", APPLICATION_ID, "flags",
+ G_APPLICATION_NON_UNIQUE, nullptr));
+}
diff --git a/flutter_manager/linux/runner/my_application.h b/flutter_manager/linux/runner/my_application.h
new file mode 100644
index 0000000..db16367
--- /dev/null
+++ b/flutter_manager/linux/runner/my_application.h
@@ -0,0 +1,21 @@
+#ifndef FLUTTER_MY_APPLICATION_H_
+#define FLUTTER_MY_APPLICATION_H_
+
+#include
+
+G_DECLARE_FINAL_TYPE(MyApplication,
+ my_application,
+ MY,
+ APPLICATION,
+ GtkApplication)
+
+/**
+ * my_application_new:
+ *
+ * Creates a new Flutter-based application.
+ *
+ * Returns: a new #MyApplication.
+ */
+MyApplication* my_application_new();
+
+#endif // FLUTTER_MY_APPLICATION_H_
diff --git a/flutter_manager/pubspec.yaml b/flutter_manager/pubspec.yaml
index fea84c0..37e303e 100644
--- a/flutter_manager/pubspec.yaml
+++ b/flutter_manager/pubspec.yaml
@@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix.
-version: 0.2.4+5
+version: 0.2.5+6
environment:
sdk: ^3.14.0
@@ -100,3 +100,4 @@ flutter:
assets:
- assets/tray.ico
+ - assets/tray.png
diff --git a/flutter_manager/test/app_paths_test.dart b/flutter_manager/test/app_paths_test.dart
new file mode 100644
index 0000000..7f1a8a4
--- /dev/null
+++ b/flutter_manager/test/app_paths_test.dart
@@ -0,0 +1,42 @@
+import 'package:flutter_test/flutter_test.dart';
+import 'package:ads_manager/data/app_paths.dart';
+
+void main() {
+ test('Linux config and logs respect separate XDG directories', () {
+ const env = {
+ 'HOME': '/home/tt',
+ 'XDG_CONFIG_HOME': '/config',
+ 'XDG_STATE_HOME': '/state',
+ };
+ expect(
+ AppPaths.configuration(environment: env, windows: false),
+ '/config/ads-flutter',
+ );
+ expect(
+ AppPaths.logs(environment: env, windows: false),
+ '/state/ads-flutter/logs',
+ );
+ });
+ test('Linux default locations persist outside temporary directories', () {
+ const env = {'HOME': '/home/tt'};
+ expect(
+ AppPaths.configuration(environment: env, windows: false),
+ '/home/tt/.config/ads-flutter',
+ );
+ expect(
+ AppPaths.logs(environment: env, windows: false),
+ '/home/tt/.local/state/ads-flutter/logs',
+ );
+ });
+ test('Windows keeps existing settings and log paths', () {
+ const env = {'LOCALAPPDATA': r'C:\Users\TT\AppData\Local'};
+ expect(
+ AppPaths.configuration(environment: env, windows: true),
+ r'C:\Users\TT\AppData\Local\TTSTD\ADS-Flutter',
+ );
+ expect(
+ AppPaths.logs(environment: env, windows: true),
+ r'C:\Users\TT\AppData\Local\TTSTD\ADS-Flutter\logs',
+ );
+ });
+}
diff --git a/flutter_manager/test/path_picker_test.dart b/flutter_manager/test/path_picker_test.dart
index baf582b..a7da181 100644
--- a/flutter_manager/test/path_picker_test.dart
+++ b/flutter_manager/test/path_picker_test.dart
@@ -33,7 +33,7 @@ void main() {
),
);
final buttons = find.byTooltip('选择文件并保存');
- expect(buttons, findsNWidgets(5));
+ expect(buttons, findsNWidgets(Platform.isWindows ? 5 : 4));
await tester.ensureVisible(buttons.at(2));
await tester.runAsync(() async {
await tester.tap(buttons.at(2));
diff --git a/flutter_manager/test/usb_recovery_test.dart b/flutter_manager/test/usb_recovery_test.dart
index a1f482e..2021e3f 100644
--- a/flutter_manager/test/usb_recovery_test.dart
+++ b/flutter_manager/test/usb_recovery_test.dart
@@ -127,7 +127,7 @@ void main() {
repo.listing = '${session.endpoint}\tdevice\n';
await repo.monitor();
expect(repo.screens, 1);
- expect(repo.resumedEmbedded, true);
+ expect(repo.resumedEmbedded, Platform.isWindows);
expect(session.screenWanted, true);
await repo.stopScreen(session);
await repo.monitor();
diff --git a/flutter_manager/test/windows_usb_test.dart b/flutter_manager/test/windows_usb_test.dart
index 739c36f..d0ec30f 100644
--- a/flutter_manager/test/windows_usb_test.dart
+++ b/flutter_manager/test/windows_usb_test.dart
@@ -30,6 +30,13 @@ void main() {
ads.SwitchListTile,
'挂载为 USB 设备 · Windows',
);
+ if (!Platform.isWindows) {
+ expect(tester.widget(toggle).onChanged, isNull);
+ expect(find.textContaining('Linux 当前使用网络 ADB'), findsOneWidget);
+ await tester.pumpWidget(const SizedBox());
+ model.dispose();
+ return;
+ }
await tester.ensureVisible(toggle);
await tester.tap(toggle);
await tester.pumpAndSettle();
diff --git a/scripts/build-flutter-linux.sh b/scripts/build-flutter-linux.sh
new file mode 100644
index 0000000..e545a84
--- /dev/null
+++ b/scripts/build-flutter-linux.sh
@@ -0,0 +1,31 @@
+#!/usr/bin/env bash
+set -euo pipefail
+root=$(cd -- "$(dirname -- "$0")/.." && pwd -P)
+case "$(uname -m)" in x86_64) rid=linux-x64;; aarch64) rid=linux-arm64;; *) echo 'Unsupported architecture' >&2; exit 1;; esac
+flutter=${FLUTTER_BIN:-flutter}
+(cd "$root/flutter_manager" && "$flutter" pub get --enforce-lockfile && "$flutter" build linux --release --no-pub -t lib/main.dart)
+source="$root/flutter_manager/build/linux/$(uname -m | sed 's/x86_64/x64/;s/aarch64/arm64/')/release/bundle"
+test -x "$source/ads_manager"
+mkdir -p "$root/bin"
+stage=$(mktemp -d "$root/bin/flutter-stage.XXXXXX")
+trap 'rm -rf -- "$stage"' EXIT
+cp -a "$source/." "$stage/"
+if [[ -n "${ADS_SCRCPY_BUNDLE:-}" ]]; then
+ python3 - "$ADS_SCRCPY_BUNDLE" <<'PY'
+import platform,struct,sys
+from pathlib import Path
+for name in ('adb','scrcpy'):
+ header=(Path(sys.argv[1])/name).read_bytes()[:20]
+ assert header[:4]==b'\x7fELF' and struct.unpack('&2; exit 1; }
+ if find "$output" -type f -name '*.env' | grep -q .; then echo 'Private env file in release output' >&2; exit 1; fi
+ rm -rf -- "$output"
+fi
+mv -- "$stage" "$output"
+echo "Flutter Linux bundle: $output"
diff --git a/scripts/build-linux-packages.sh b/scripts/build-linux-packages.sh
index 653bb52..7b0b522 100644
--- a/scripts/build-linux-packages.sh
+++ b/scripts/build-linux-packages.sh
@@ -36,6 +36,9 @@ package() {
for tool in ads-agent ads-client adsctl ads-usb ads-server ads-relay; do
if [[ -f "$payload/$tool" ]]; then check_elf "$payload/$tool"; chmod 755 "$payload/$tool"; fi
done
+ for tool in adb scrcpy; do
+ if [[ -f "$payload/tools/scrcpy/$tool" ]]; then check_elf "$payload/tools/scrcpy/$tool"; chmod 755 "$payload/tools/scrcpy/$tool"; fi
+ done
if [[ "$kind" != agent ]]; then
printf '#!/bin/sh\nexec /opt/ttstd/%s/%s "$@"\n' "$name" "$exe" > "$tree/usr/bin/$name"
chmod 755 "$tree/usr/bin/$name"
@@ -55,7 +58,9 @@ package() {
if [[ "$kind" == avalonia || "$kind" == flutter ]]; then
mkdir -p "$tree/usr/share/applications" "$tree/usr/share/icons/hicolor/256x256/apps"
cp "$root/desktop/Ads.Desktop/Assets/app.png" "$tree/usr/share/icons/hicolor/256x256/apps/$name.png"
- printf '[Desktop Entry]\nType=Application\nName=ADS %s\nExec=%s\nIcon=%s\nTerminal=false\nCategories=Development;Utility;\n' "$kind" "$name" "$name" > "$tree/usr/share/applications/$name.desktop"
+ desktop_name="$name"
+ if [[ "$kind" == flutter ]]; then desktop_name=com.ttstd.ads.ads_manager; fi
+ printf '[Desktop Entry]\nType=Application\nName=ADS %s\nExec=%s\nIcon=%s\nTerminal=false\nCategories=Development;Utility;\n' "$kind" "$name" "$name" > "$tree/usr/share/applications/$desktop_name.desktop"
fi
printf 'Package: %s\nVersion: %s\nArchitecture: %s\nMaintainer: TongTong Studio\nDepends: %s\nDescription: ADS %s remote Android management\n' "$name" "$version" "$arch" "$deps" "$kind" > "$tree/DEBIAN/control"
chmod 755 "$tree/DEBIAN"; chmod 644 "$tree/DEBIAN/control"
@@ -81,10 +86,19 @@ if [[ "$mode" == all || "$mode" == avalonia ]]; then
package avalonia Ads.Desktop "$stage/avalonia-source" 'libc6 (>= 2.31), libgcc-s1, libstdc++6, libx11-6, libice6, libsm6, libfontconfig1, libfreetype6, libicu76 | libicu74 | libicu72 | libicu70, libssl3t64 | libssl3, zlib1g, adb, scrcpy'
fi
if [[ "$mode" == flutter ]]; then
- : "${ADS_FLUTTER_BUNDLE:?Provide a native Linux Flutter release bundle}"
- mkdir -p "$stage/flutter-source"; cp -a "$ADS_FLUTTER_BUNDLE/." "$stage/flutter-source/"
+ if [[ -z "${ADS_FLUTTER_BUNDLE:-}" ]]; then
+ bash "$root/scripts/build-flutter-linux.sh"
+ fi
+ source=${ADS_FLUTTER_BUNDLE:-$root/bin/flutter-$rid}
+ mkdir -p "$stage/flutter-source"; cp -a "$source/." "$stage/flutter-source/"
for tool in ads-agent adsctl ads-client ads-usb; do cp "$backend/$tool" "$stage/flutter-source/"; done
- package flutter ads_manager "$stage/flutter-source" 'libc6 (>= 2.31), libstdc++6, libgtk-3-0, libayatana-appindicator3-1, adb, scrcpy'
+ deps='libc6 (>= 2.35), libgcc-s1, libstdc++6, libgtk-3-0t64 | libgtk-3-0, libayatana-appindicator3-1, xdg-utils'
+ if [[ -f "$stage/flutter-source/tools/scrcpy/adb" && -f "$stage/flutter-source/tools/scrcpy/scrcpy" ]]; then
+ deps+=', libudev1, libcap2'
+ else
+ deps+=', adb, scrcpy (>= 2.0)'
+ fi
+ package flutter ads_manager "$stage/flutter-source" "$deps"
fi
(cd "$output" && sha256sum ./*.deb > SHA256SUMS)
echo "Linux packages: $output"
diff --git a/tests/deb_cli_test.py b/tests/deb_cli_test.py
index c62db62..3a26399 100644
--- a/tests/deb_cli_test.py
+++ b/tests/deb_cli_test.py
@@ -127,15 +127,23 @@ class DebCliTests(unittest.TestCase):
def test_real_release_packages(self):
folder=Path(os.environ['ADS_DEB_PACKAGE_DIR'])
version=os.environ.get('ADS_DEB_VERSION','0.2.4')
- self.dpkg('--force-depends','-i',folder/f'ads-avalonia_{version}_amd64.deb')
+ kind=os.environ.get('ADS_DEB_DESKTOP_KIND','avalonia')
+ self.dpkg('--force-depends','-i',folder/f'ads-{kind}_{version}_amd64.deb')
for tool in TOOLS:
- self.assert_provider(tool,'avalonia')
+ self.assert_provider(tool,kind)
self.assertIn(version,self.run_command([str(self.target(tool)),'--version']))
+ if kind=='flutter':
+ payload=self.root/'opt/ttstd/ads-flutter'
+ self.assertTrue((self.root/'usr/share/applications/com.ttstd.ads.ads_manager.desktop').is_file())
+ tools=payload/'tools/scrcpy'
+ if tools.is_dir():
+ self.assertIn('Android Debug Bridge',self.run_command([str(tools/'adb'),'version']))
+ self.assertIn('scrcpy',self.run_command([str(tools/'scrcpy'),'--version']))
self.dpkg('--force-depends','-i',folder/f'ads-agent_{version}_amd64.deb')
self.assert_provider('adsctl','agent')
self.dpkg('-r','ads-agent')
- for tool in TOOLS: self.assert_provider(tool,'avalonia')
- self.dpkg('--purge','ads-avalonia')
+ for tool in TOOLS: self.assert_provider(tool,kind)
+ self.dpkg('--purge','ads-'+kind)
for tool in TOOLS: self.assert_no_entry(tool)
def test_existing_real_local_command_is_not_overwritten(self):