Fix relocated desktop tool paths and package release 0.2.2
This commit is contained in:
1 parent
efaf16de18
commit
e366eb5bec
14 files changed
+250
-33
No files matched your search
@@ -137,3 +137,5 @@ USB ADB 连续 3 轮监控缺失(约 9 秒)、USB 后端退出或 scrcpy 以
|
||||
桌面日志界面提供“打开日志文件夹”。Avalonia 与 Flutter 均按天保存日志,单文件达到 5 MiB 后滚动,每日最多 5 份,保留最近 14 天。设备列表显示所属电脑及 Agent。Windows 安装包默认安装到 `%LOCALAPPDATA%/Programs/TongTongStudio/ADS-{Edition}`;用户配置和日志位置保持兼容。升级保持原 AppId,安装目录不再自动沿用旧的 TTSTD 路径。
|
||||
|
||||
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 路径;缺少工具先提示重新安装或选择文件,尚未分配连接端口。用户配置与凭据位置不随安装目录变化。
|
||||
@@ -6,6 +6,7 @@ import 'package:path/path.dart' as p;
|
||||
|
||||
import 'windows_usb.dart';
|
||||
import 'usb_recovery.dart';
|
||||
import 'tool_paths.dart';
|
||||
|
||||
class Settings {
|
||||
String server = 'wss://ttstd.com/ads';
|
||||
@@ -95,7 +96,8 @@ class ManagerRepository {
|
||||
String token = '';
|
||||
Directory? root;
|
||||
late Directory storage;
|
||||
ManagerRepository(this.log);
|
||||
final ToolPaths? paths;
|
||||
ManagerRepository(this.log, {this.paths});
|
||||
|
||||
Future<void> init() async {
|
||||
storage = Directory(
|
||||
@@ -138,29 +140,30 @@ class ManagerRepository {
|
||||
jsonDecode(await saved.readAsString()) as Map<String, dynamic>,
|
||||
);
|
||||
}
|
||||
await repairToolPaths();
|
||||
token = Platform.environment['ADS_CLIENT_TOKEN'] ?? '';
|
||||
if (token.isEmpty && await File(settings.credential).exists()) {
|
||||
await importCredential();
|
||||
}
|
||||
}
|
||||
|
||||
String findTool(String name) {
|
||||
final exe = Platform.isWindows ? '$name.exe' : name;
|
||||
final base = p.dirname(Platform.resolvedExecutable);
|
||||
final candidates = [
|
||||
p.join(base, exe),
|
||||
p.join(base, 'tools', 'scrcpy', exe),
|
||||
if (root != null) p.join(root!.path, 'bin', exe),
|
||||
if (root != null) p.join(root!.path, 'bin', 'tools', 'scrcpy', exe),
|
||||
for (final dir in (Platform.environment['PATH'] ?? '').split(
|
||||
Platform.isWindows ? ';' : ':',
|
||||
))
|
||||
p.join(dir, exe),
|
||||
];
|
||||
return candidates.firstWhere(
|
||||
(v) => File(v).existsSync(),
|
||||
orElse: () => exe,
|
||||
);
|
||||
ToolPaths get toolPaths => paths ?? ToolPaths(projectRoot: root?.path);
|
||||
String findTool(String name) => toolPaths.resolve(name);
|
||||
Future<void> repairToolPaths() async {
|
||||
var changed = false;
|
||||
void repair(String name, String value, void Function(String) assign) {
|
||||
final resolved = toolPaths.resolve(name, configured: value);
|
||||
if (resolved != value) {
|
||||
assign(resolved);
|
||||
changed = true;
|
||||
log('已更新 $name 工具位置:$resolved');
|
||||
}
|
||||
}
|
||||
|
||||
repair('ads-client', settings.client, (v) => settings.client = v);
|
||||
repair('adb', settings.adb, (v) => settings.adb = v);
|
||||
repair('scrcpy', settings.scrcpy, (v) => settings.scrcpy = v);
|
||||
if (changed) await save();
|
||||
}
|
||||
|
||||
Future<void> save() =>
|
||||
@@ -292,6 +295,12 @@ class ManagerRepository {
|
||||
..['NO_COLOR'] = '1';
|
||||
|
||||
Future<String> run(String exe, List<String> args) async {
|
||||
final name = p
|
||||
.basename(exe)
|
||||
.replaceFirst(RegExp(r'\.exe$', caseSensitive: false), '');
|
||||
if (['ads-client', 'ads-usb', 'adsctl', 'adb', 'scrcpy'].contains(name)) {
|
||||
exe = toolPaths.resolve(name, configured: exe, required: true);
|
||||
}
|
||||
final proc = await Process.start(
|
||||
exe,
|
||||
args,
|
||||
@@ -334,6 +343,17 @@ class ManagerRepository {
|
||||
if (token.length < 32) {
|
||||
throw const FormatException('请先导入凭据');
|
||||
}
|
||||
await repairToolPaths();
|
||||
settings.client = toolPaths.resolve(
|
||||
'ads-client',
|
||||
configured: settings.client,
|
||||
required: true,
|
||||
);
|
||||
settings.adb = toolPaths.resolve(
|
||||
'adb',
|
||||
configured: settings.adb,
|
||||
required: true,
|
||||
);
|
||||
final usbMode = settings.usbMode;
|
||||
final usbip = settings.usbip;
|
||||
if (usbMode) {
|
||||
@@ -343,7 +363,7 @@ class ManagerRepository {
|
||||
if (!await File(usbip).exists()) {
|
||||
throw StateError('找不到 usbip.exe,请检查配置路径');
|
||||
}
|
||||
await run(findTool('ads-usb'), ['--version']);
|
||||
await run(toolPaths.resolve('ads-usb', required: true), ['--version']);
|
||||
}
|
||||
final port = await allocatePort(15555, 18000);
|
||||
int? usbPort;
|
||||
@@ -655,8 +675,18 @@ class ManagerRepository {
|
||||
String id, {
|
||||
bool embedded = false,
|
||||
}) {
|
||||
final scrcpy = toolPaths.resolve(
|
||||
'scrcpy',
|
||||
configured: settings.scrcpy,
|
||||
required: true,
|
||||
);
|
||||
final selectedAdb = toolPaths.resolve(
|
||||
'adb',
|
||||
configured: adb,
|
||||
required: true,
|
||||
);
|
||||
return Process.start(
|
||||
settings.scrcpy,
|
||||
scrcpy,
|
||||
[
|
||||
'--serial',
|
||||
endpoint,
|
||||
@@ -675,8 +705,8 @@ class ManagerRepository {
|
||||
'60',
|
||||
'--no-audio',
|
||||
],
|
||||
workingDirectory: p.dirname(p.absolute(settings.scrcpy)),
|
||||
environment: environment()..['ADB'] = adb,
|
||||
workingDirectory: p.dirname(scrcpy),
|
||||
environment: environment()..['ADB'] = selectedAdb,
|
||||
includeParentEnvironment: false,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:path/path.dart' as p;
|
||||
|
||||
/// Resolves relocated bundled tools while preserving valid custom executables.
|
||||
class ToolPaths {
|
||||
ToolPaths({String? base, this.projectRoot, String? searchPath})
|
||||
: base = base ?? p.dirname(Platform.resolvedExecutable),
|
||||
searchPath = searchPath ?? Platform.environment['PATH'] ?? '';
|
||||
final String base, searchPath;
|
||||
final String? projectRoot;
|
||||
|
||||
static bool managed(String value) =>
|
||||
RegExp(r'/programs/(?:ttstd|tongtongstudio)/ads-(?:flutter|avalonia)/')
|
||||
.hasMatch(value.replaceAll(r'\', '/').toLowerCase());
|
||||
|
||||
String resolve(String name, {String configured = '', bool required = false}) {
|
||||
final exe = Platform.isWindows ? '$name.exe' : name;
|
||||
final selected = configured.trim().replaceAll(RegExp(r'^"|"$'), '');
|
||||
if (selected.isNotEmpty &&
|
||||
!managed(selected) &&
|
||||
File(selected).existsSync()) {
|
||||
return p.absolute(selected);
|
||||
}
|
||||
final candidates = [
|
||||
p.join(base, exe),
|
||||
p.join(base, 'tools', 'scrcpy', exe),
|
||||
if (projectRoot != null) p.join(projectRoot!, 'bin', exe),
|
||||
if (projectRoot != null)
|
||||
p.join(projectRoot!, 'bin', 'tools', 'scrcpy', exe),
|
||||
for (final folder in searchPath.split(Platform.isWindows ? ';' : ':'))
|
||||
if (folder.trim().isNotEmpty)
|
||||
p.join(folder.trim().replaceAll('"', ''), exe),
|
||||
];
|
||||
for (final candidate in candidates) {
|
||||
if (File(candidate).existsSync()) return p.absolute(candidate);
|
||||
}
|
||||
if (required) {
|
||||
throw FileSystemException(
|
||||
'找不到 $exe。请重新安装完整安装包,或在连接配置中选择有效的工具文件。当前程序目录:$base',
|
||||
selected.isEmpty ? exe : selected,
|
||||
);
|
||||
}
|
||||
return selected.isNotEmpty ? selected : exe;
|
||||
}
|
||||
}
|
||||
@@ -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.1+2
|
||||
version: 0.2.2+3
|
||||
|
||||
environment:
|
||||
sdk: ^3.14.0
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
import 'package:ads_manager/data/tool_paths.dart';
|
||||
import 'package:ads_manager/data/manager_repository.dart';
|
||||
|
||||
void main() {
|
||||
group('relocated tool paths', () {
|
||||
late Directory temp;
|
||||
late String bundle;
|
||||
late ToolPaths paths;
|
||||
String exe(String name) => Platform.isWindows ? '$name.exe' : name;
|
||||
String create(String path) {
|
||||
final file = File(path);
|
||||
file.parent.createSync(recursive: true);
|
||||
file.writeAsStringSync('fixture');
|
||||
return file.path;
|
||||
}
|
||||
|
||||
setUp(() {
|
||||
temp = Directory.systemTemp.createTempSync('ads-relocate');
|
||||
bundle = p.join(temp.path, 'Programs', 'TongTongStudio', 'ADS-Flutter');
|
||||
paths = ToolPaths(base: bundle, searchPath: '');
|
||||
});
|
||||
tearDown(() => temp.deleteSync(recursive: true));
|
||||
for (final oldExists in [false, true]) {
|
||||
test('migrates old install, old file exists=$oldExists', () {
|
||||
final old = p.join(
|
||||
temp.path,
|
||||
'Programs',
|
||||
'TTSTD',
|
||||
'ADS-Flutter',
|
||||
exe('ads-client'),
|
||||
);
|
||||
if (oldExists) create(old);
|
||||
final current = create(p.join(bundle, exe('ads-client')));
|
||||
expect(
|
||||
paths.resolve('ads-client', configured: old, required: true),
|
||||
current,
|
||||
);
|
||||
});
|
||||
}
|
||||
test('preserves a valid custom executable', () {
|
||||
create(p.join(bundle, exe('adb')));
|
||||
final custom = create(p.join(temp.path, 'SDK', exe('adb')));
|
||||
expect(paths.resolve('adb', configured: custom), custom);
|
||||
});
|
||||
test('migration persists tools and preserves other settings', () async {
|
||||
final repository = ManagerRepository((_) {}, paths: paths)
|
||||
..storage = temp;
|
||||
repository.settings.credential = 'private-client.env';
|
||||
repository.settings.usbMode = true;
|
||||
repository.settings.client = p.join(
|
||||
temp.path,
|
||||
'Programs',
|
||||
'TTSTD',
|
||||
'ADS-Flutter',
|
||||
exe('ads-client'),
|
||||
);
|
||||
create(p.join(bundle, exe('ads-client')));
|
||||
create(p.join(bundle, 'tools', 'scrcpy', exe('adb')));
|
||||
create(p.join(bundle, 'tools', 'scrcpy', exe('scrcpy')));
|
||||
await repository.repairToolPaths();
|
||||
final saved = jsonDecode(
|
||||
File(p.join(temp.path, 'settings.json')).readAsStringSync(),
|
||||
);
|
||||
expect(saved['client'], p.join(bundle, exe('ads-client')));
|
||||
expect(saved['adb'], p.join(bundle, 'tools', 'scrcpy', exe('adb')));
|
||||
expect(saved['credential'], 'private-client.env');
|
||||
expect(saved['usbMode'], true);
|
||||
});
|
||||
test(
|
||||
'missing tool fails before allocating ports or creating sessions',
|
||||
() async {
|
||||
final repository = ManagerRepository((_) {}, paths: paths)
|
||||
..storage = temp
|
||||
..token = 'a' * 32;
|
||||
await expectLater(
|
||||
repository.connect('phone'),
|
||||
throwsA(
|
||||
isA<FileSystemException>().having(
|
||||
(e) => e.message,
|
||||
'message',
|
||||
contains('重新安装'),
|
||||
),
|
||||
),
|
||||
);
|
||||
expect(repository.reservedPorts, isEmpty);
|
||||
expect(repository.sessions, isEmpty);
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user