feat: improve desktop path selection and USB connection recovery
This commit is contained in:
1 parent
5aa575f182
commit
6490665af8
28 files changed
+846
-51
No files matched your search
@@ -18,6 +18,7 @@ class AgentModel extends ChangeNotifier {
|
||||
ManagedAgent? get selected =>
|
||||
_agents.where((a) => a.id == selectedId).firstOrNull;
|
||||
bool localMode = false, busy = false, autoRefresh = true, followLogs = false;
|
||||
Future<void> Function(String, String)? savePath;
|
||||
String adminPath = '',
|
||||
enrollmentPath = '',
|
||||
enrollmentToken = '',
|
||||
|
||||
@@ -3,6 +3,7 @@ import 'package:material_ui/material_ui.dart';
|
||||
import '../data/agent_models.dart';
|
||||
|
||||
import 'agent_model.dart';
|
||||
import 'path_picker.dart';
|
||||
|
||||
class AgentView extends StatefulWidget {
|
||||
const AgentView({super.key, required this.model});
|
||||
@@ -42,6 +43,24 @@ class _AgentViewState extends State<AgentView> {
|
||||
: null,
|
||||
decoration: InputDecoration(
|
||||
labelText: label,
|
||||
suffixIcon: ['configPath', 'admin', 'enroll'].contains(key)
|
||||
? IconButton(
|
||||
tooltip: '选择文件并保存',
|
||||
icon: const Icon(Icons.folder_open),
|
||||
onPressed: m.busy
|
||||
? null
|
||||
: () => m.run(() async {
|
||||
final selected = await pickPath(controller.text);
|
||||
if (selected == null || !mounted) {
|
||||
return;
|
||||
}
|
||||
controller.text = selected;
|
||||
change(selected);
|
||||
await m.savePath?.call(key, selected);
|
||||
m.notice = '文件位置已保存';
|
||||
}),
|
||||
)
|
||||
: null,
|
||||
border: const OutlineInputBorder(),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -172,7 +172,13 @@ class ScreenPage extends StatelessWidget {
|
||||
const SizedBox(height: 12),
|
||||
Expanded(
|
||||
child: pid == null
|
||||
? const Center(child: Text('投屏已停止,请返回设备重新打开。'))
|
||||
? Center(
|
||||
child: Text(
|
||||
s?.screenWanted == true
|
||||
? '连接中断,正在恢复 USB 和投屏…'
|
||||
: '投屏已停止,请返回设备重新打开。',
|
||||
),
|
||||
)
|
||||
: s?.screenEmbedded == true
|
||||
? EmbeddedScreen(key: ValueKey(pid), pid: pid)
|
||||
: const Center(child: Text('投屏已在独立窗口运行,设备连接保持不变。')),
|
||||
|
||||
@@ -47,13 +47,28 @@ class ManagerModel extends ChangeNotifier {
|
||||
Future<void> init() async {
|
||||
await action(() async {
|
||||
await repository.init();
|
||||
agents.savePath = (key, value) async {
|
||||
repository.settings.agentPaths[key] = value;
|
||||
await repository.save();
|
||||
};
|
||||
await agents.initialize(
|
||||
adminFile: repository.root == null
|
||||
? p.join(p.dirname(Platform.resolvedExecutable), 'admin.env')
|
||||
: p.join(repository.root!.path, 'config', 'private', 'admin.env'),
|
||||
adminFile:
|
||||
repository.settings.agentPaths['admin'] ??
|
||||
(repository.root == null
|
||||
? p.join(p.dirname(Platform.resolvedExecutable), 'admin.env')
|
||||
: p.join(
|
||||
repository.root!.path,
|
||||
'config',
|
||||
'private',
|
||||
'admin.env',
|
||||
)),
|
||||
server: repository.settings.server,
|
||||
origin: repository.settings.origin,
|
||||
);
|
||||
agents.configPath =
|
||||
repository.settings.agentPaths['configPath'] ?? agents.configPath;
|
||||
agents.enrollmentPath =
|
||||
repository.settings.agentPaths['enroll'] ?? agents.enrollmentPath;
|
||||
notice = '准备就绪';
|
||||
});
|
||||
await refresh();
|
||||
|
||||
@@ -9,6 +9,7 @@ import '../data/manager_repository.dart';
|
||||
import 'manager_model.dart';
|
||||
import 'agent_view.dart';
|
||||
import 'embedded_screen.dart';
|
||||
import 'path_picker.dart';
|
||||
|
||||
class ManagerView extends StatefulWidget {
|
||||
final ManagerModel model;
|
||||
@@ -82,7 +83,13 @@ class _ManagerViewState extends State<ManagerView> {
|
||||
fontSize: 14,
|
||||
),
|
||||
),
|
||||
onTap: () => setState(() => page = i),
|
||||
onTap: () {
|
||||
for (final session
|
||||
in m.repository.sessions.values) {
|
||||
session.screenPageVisible = false;
|
||||
}
|
||||
setState(() => page = i);
|
||||
},
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
@@ -183,12 +190,18 @@ class _ManagerViewState extends State<ManagerView> {
|
||||
}
|
||||
}),
|
||||
session: m.repository.sessions[screenDevice],
|
||||
onBack: () => setState(() => page = 0),
|
||||
onBack: () {
|
||||
m
|
||||
.repository
|
||||
.sessions[screenDevice]
|
||||
?.screenPageVisible =
|
||||
false;
|
||||
setState(() => page = 0);
|
||||
},
|
||||
onStop: () => m.deviceAction(screenDevice!, () async {
|
||||
final s = m.repository.sessions[screenDevice];
|
||||
if (s != null) {
|
||||
await m.repository.stop(s.screen);
|
||||
s.screen = null;
|
||||
await m.repository.stopScreen(s);
|
||||
}
|
||||
}),
|
||||
),
|
||||
@@ -384,6 +397,7 @@ class _ManagerViewState extends State<ManagerView> {
|
||||
await m.repository.screen(s, embedded: true);
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
s.screenPageVisible = true;
|
||||
screenDevice = s.id;
|
||||
page = 6;
|
||||
});
|
||||
@@ -529,7 +543,13 @@ class _ManagerViewState extends State<ManagerView> {
|
||||
class SettingsView extends StatefulWidget {
|
||||
final ManagerModel model;
|
||||
final Future<bool> Function()? driverInstalled;
|
||||
const SettingsView({super.key, required this.model, this.driverInstalled});
|
||||
final Future<String?> Function(String, bool)? chooseFile;
|
||||
const SettingsView({
|
||||
super.key,
|
||||
required this.model,
|
||||
this.driverInstalled,
|
||||
this.chooseFile,
|
||||
});
|
||||
@override
|
||||
State<SettingsView> createState() => _SettingsViewState();
|
||||
}
|
||||
@@ -692,7 +712,33 @@ class _SettingsViewState extends State<SettingsView> {
|
||||
padding: const EdgeInsets.only(bottom: 18),
|
||||
child: TextField(
|
||||
controller: fields[key],
|
||||
decoration: InputDecoration(labelText: label),
|
||||
decoration: InputDecoration(
|
||||
labelText: label,
|
||||
suffixIcon: ['server', 'origin'].contains(key)
|
||||
? null
|
||||
: IconButton(
|
||||
tooltip: '选择文件并保存',
|
||||
icon: const Icon(Icons.folder_open),
|
||||
onPressed: () => widget.model.action(() async {
|
||||
final selected =
|
||||
await (widget.chooseFile?.call(
|
||||
fields[key]!.text,
|
||||
key != "credential",
|
||||
) ??
|
||||
pickPath(
|
||||
fields[key]!.text,
|
||||
executable: key != 'credential',
|
||||
));
|
||||
if (selected == null || !mounted) {
|
||||
return;
|
||||
}
|
||||
fields[key]!.text = selected;
|
||||
apply();
|
||||
await widget.model.repository.save();
|
||||
widget.model.notice = '文件位置已保存';
|
||||
}),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
SwitchListTile(
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:file_selector/file_selector.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
|
||||
Future<String?> pickPath(String value, {bool executable = false}) async {
|
||||
final directory = value.isEmpty ? null : p.dirname(value);
|
||||
final selected = await openFile(
|
||||
initialDirectory: directory != null && Directory(directory).existsSync()
|
||||
? directory
|
||||
: null,
|
||||
acceptedTypeGroups: executable
|
||||
? [
|
||||
const XTypeGroup(label: '可执行程序', extensions: ['exe']),
|
||||
]
|
||||
: [],
|
||||
);
|
||||
return selected?.path;
|
||||
}
|
||||
Reference in new issue
Block a user