Switch manager to use process_run for shell commands
process_run provides a nice wrapper for which, and shows the command an output in the debug log so provides easier debugging of issues invoking external commands.
This commit is contained in:
parent
b1350b825f
commit
3d89d73af1
|
|
@ -9,6 +9,7 @@ import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_svg/flutter_svg.dart';
|
import 'package:flutter_svg/flutter_svg.dart';
|
||||||
import 'package:gettext_i18n/gettext_i18n.dart';
|
import 'package:gettext_i18n/gettext_i18n.dart';
|
||||||
import 'package:path/path.dart' as path;
|
import 'package:path/path.dart' as path;
|
||||||
|
import 'package:process_run/shell.dart';
|
||||||
|
|
||||||
import '../globals.dart';
|
import '../globals.dart';
|
||||||
import '../mixins/preferences_mixin.dart';
|
import '../mixins/preferences_mixin.dart';
|
||||||
|
|
@ -78,10 +79,10 @@ class _ManagerState extends State<Manager> with PreferencesMixin {
|
||||||
|
|
||||||
void _getTerminalEmulator() async {
|
void _getTerminalEmulator() async {
|
||||||
// Find out which terminal emulator we have set as the default.
|
// Find out which terminal emulator we have set as the default.
|
||||||
ProcessResult result = await Process.run('which', ['x-terminal-emulator']);
|
String result = whichSync('x-terminal-emulator') ?? '';
|
||||||
if (result.exitCode == 0) {
|
if (result.isNotEmpty) {
|
||||||
String terminalEmulator =
|
String terminalEmulator =
|
||||||
await File(result.stdout.toString().trim()).resolveSymbolicLinks();
|
await File(result).resolveSymbolicLinks();
|
||||||
terminalEmulator = path.basenameWithoutExtension(terminalEmulator);
|
terminalEmulator = path.basenameWithoutExtension(terminalEmulator);
|
||||||
if (_supportedTerminalEmulators.contains(terminalEmulator)) {
|
if (_supportedTerminalEmulators.contains(terminalEmulator)) {
|
||||||
setState(() {
|
setState(() {
|
||||||
|
|
@ -92,9 +93,9 @@ class _ManagerState extends State<Manager> with PreferencesMixin {
|
||||||
}
|
}
|
||||||
|
|
||||||
void _detectSpice() async {
|
void _detectSpice() async {
|
||||||
ProcessResult result = await Process.run('which', ['spicy']);
|
var result = whichSync('spicy') ?? '';
|
||||||
setState(() {
|
setState(() {
|
||||||
_spicy = result.exitCode == 0;
|
_spicy = result.isNotEmpty ;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -272,11 +273,12 @@ class _ManagerState extends State<Manager> with PreferencesMixin {
|
||||||
? null
|
? null
|
||||||
: () async {
|
: () async {
|
||||||
Map<String, VmInfo> activeVms = _activeVms;
|
Map<String, VmInfo> activeVms = _activeVms;
|
||||||
List<String> args = ['--vm', currentVm + '.conf'];
|
List<String> command = ['quickemu', '--vm', '$currentVm.conf'];
|
||||||
if (_spicy) {
|
if (_spicy) {
|
||||||
args.addAll(['--display', 'spice']);
|
command.addAll(['--display', 'spice']);
|
||||||
}
|
}
|
||||||
await Process.start('quickemu', args);
|
var shell = Shell();
|
||||||
|
await shell.run(command.join(' '));
|
||||||
VmInfo info = _parseVmInfo(currentVm);
|
VmInfo info = _parseVmInfo(currentVm);
|
||||||
activeVms[currentVm] = info;
|
activeVms[currentVm] = info;
|
||||||
setState(() {
|
setState(() {
|
||||||
|
|
@ -313,7 +315,8 @@ class _ManagerState extends State<Manager> with PreferencesMixin {
|
||||||
).then((result) {
|
).then((result) {
|
||||||
result = result ?? false;
|
result = result ?? false;
|
||||||
if (result) {
|
if (result) {
|
||||||
Process.run('killall', [currentVm]);
|
var shell = Shell();
|
||||||
|
shell.run(['killall', currentVm].join(' '));
|
||||||
setState(() {
|
setState(() {
|
||||||
_activeVms.remove(currentVm);
|
_activeVms.remove(currentVm);
|
||||||
});
|
});
|
||||||
|
|
@ -352,12 +355,14 @@ class _ManagerState extends State<Manager> with PreferencesMixin {
|
||||||
).then((result) async {
|
).then((result) async {
|
||||||
result = result ?? 'cancel';
|
result = result ?? 'cancel';
|
||||||
if (result != 'cancel') {
|
if (result != 'cancel') {
|
||||||
List<String> args = [
|
List<String> command = [
|
||||||
|
'quickemu',
|
||||||
'--vm',
|
'--vm',
|
||||||
currentVm + '.conf',
|
'$currentVm.conf',
|
||||||
'--delete-' + result
|
'--delete-$result'
|
||||||
];
|
];
|
||||||
await Process.start('quickemu', args);
|
var shell = Shell();
|
||||||
|
await shell.run(command.join(' '));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
@ -380,7 +385,8 @@ class _ManagerState extends State<Manager> with PreferencesMixin {
|
||||||
onPressed: !_spicy
|
onPressed: !_spicy
|
||||||
? null
|
? null
|
||||||
: () {
|
: () {
|
||||||
Process.start('spicy', ['-p', vmInfo.spicePort!]);
|
var shell = Shell();
|
||||||
|
shell.run(['spicy', '-p', vmInfo.spicePort!].join(' '));
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
IconButton(
|
IconButton(
|
||||||
|
|
@ -455,7 +461,9 @@ class _ManagerState extends State<Manager> with PreferencesMixin {
|
||||||
sshArgs = ['-e', command];
|
sshArgs = ['-e', command];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Process.start(_terminalEmulator!, sshArgs);
|
sshArgs.insert(0, _terminalEmulator!);
|
||||||
|
var shell = Shell();
|
||||||
|
shell.run(sshArgs.join(' '));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ dependencies:
|
||||||
flutter_svg: ^2.0.10+1
|
flutter_svg: ^2.0.10+1
|
||||||
gettext_i18n: ^1.0.2
|
gettext_i18n: ^1.0.2
|
||||||
url_launcher: ^6.1.6
|
url_launcher: ^6.1.6
|
||||||
|
process_run: ^0.14.2
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue