From 0c2c15481a7b8c824f6719ce5ee5d82176f6c97b Mon Sep 17 00:00:00 2001 From: Mark Johnson Date: Wed, 15 Dec 2021 21:37:58 +0000 Subject: [PATCH] Support more terminal emulators --- lib/src/pages/manager.dart | 64 ++++++++++++++++++++++++++++++++++---- 1 file changed, 58 insertions(+), 6 deletions(-) diff --git a/lib/src/pages/manager.dart b/lib/src/pages/manager.dart index 2c3afd5..95f4ebb 100644 --- a/lib/src/pages/manager.dart +++ b/lib/src/pages/manager.dart @@ -57,12 +57,13 @@ class _ManagerState extends State with PreferencesMixin { } void _getTerminalEmulator() async { - ProcessResult result = Process.runSync('x-terminal-emulator', ['-h']); - RegExp pattern = RegExp(r"usage:\s+([^\s]+)", multiLine: true, caseSensitive: false); - RegExpMatch? match = pattern.firstMatch(result.stdout); - if (match != null) { + // Find out which terminal emulator we have set as the default. + ProcessResult result = await Process.run('which', ['x-terminal-emulator']); + if (result.exitCode == 0) { + String terminalEmulator = await File(result.stdout.toString().trim()).resolveSymbolicLinks(); + stdout.writeln(terminalEmulator); setState(() { - _terminalEmulator = match.group(1); + _terminalEmulator = path.basename(terminalEmulator); }); } } @@ -278,6 +279,46 @@ class _ManagerState extends State with PreferencesMixin { }); }, ), + IconButton( + icon: Icon( + Icons.delete, + color: active ? null : buttonColor, + semanticLabel: 'Delete' + ), + onPressed: active ? null : () { + showDialog( + context: context, + builder: (BuildContext context) => AlertDialog( + title: Text('Delete ' + currentVm), + content: Text( + 'You are about to delete ' + currentVm + '. This cannot be undone. ' + + 'Would you like to delete the disk image but keep the ' + + 'configuration, or delete the whole VM?' + ), + actions: [ + TextButton( + child: Text('Cancel'), + onPressed: () => Navigator.pop(context, 'cancel'), + ), + TextButton( + child: Text('Delete disk image'), + onPressed: () => Navigator.pop(context, 'disk'), + ), + TextButton( + child: Text('Delete whole VM'), + onPressed: () => Navigator.pop(context, 'vm'), + ) // set up the AlertDialog + ], + ), + ).then((result) async { + result = result ?? 'cancel'; + if (result != 'cancel') { + List args = ['--vm', currentVm + '.conf', '--delete-' + result]; + await Process.start('quickemu', args); + } + }); + }, + ), ], )), if (connectInfo.isNotEmpty) @@ -327,13 +368,24 @@ class _ManagerState extends State with PreferencesMixin { result = result ?? false; if (result) { List sshArgs = ['ssh', '-p', vmInfo.sshPort!, _usernameController.text + '@localhost']; - switch (_terminalEmulator) { + // Set the arguments to execute the ssh command in the default terminal. + // Strip the extension as x-terminal-emulator may point to a .wrapper + switch (path.basenameWithoutExtension(_terminalEmulator!)) { case 'gnome-terminal': case 'mate-terminal': sshArgs.insert(0, '--'); break; case 'xterm': + case 'lxterm': + case 'uxterm': case 'konsole': + case 'uxrvt': + case 'xrvt': + case 'sakura': + case 'cool-retro-term': + case 'pterm': + case 'lxterminal': + case 'tilix': sshArgs.insert(0, '-e'); break; case 'terminator':