Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Launch with Terminal: Add fallback to PowerShell on exception #253

Merged
merged 2 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions lib/api/wsl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import 'package:wsl2distromanager/api/safe_paths.dart';
import 'package:wsl2distromanager/components/constants.dart';
import 'package:wsl2distromanager/components/helpers.dart';
import 'package:wsl2distromanager/components/logging.dart';
import 'package:wsl2distromanager/components/notify.dart';

/// Used to store the instances of WSL in a list.
class Instances {
Expand Down Expand Up @@ -200,11 +201,19 @@ class WSLApi {
mode: ProcessStartMode.normal, runInShell: true);
}

/// Start Windows Terminal
/// Start Windows Terminal\
/// *(falls back to PowerShell on exception)*
void startWindowsTerminal(String distribution) async {
List<String> args = ['wt', 'wsl', '-d', distribution, '--cd', '~'];
Process.start('start', args,
mode: ProcessStartMode.normal, runInShell: true);
List<String> launchWslHome = ['wsl', '-d', distribution, '--cd', '~'];
try {
await Process.start('wt', launchWslHome);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had to remove runInShell otherwise exception is not provided to our process. I don't know if this has other unwanted side effects, but it does launch wt correctly if it is installed. Please confirm.

} catch (_) {
// Windows Terminal not installed
Notify.message('openwithwt-not-found-error'.i18n());

var args = ['powershell', '-noexit', '-command', launchWslHome.join(' ')];
await Process.run('start', args, runInShell: true);
}
}

/// Copy a WSL distro by name
Expand Down
1 change: 1 addition & 0 deletions lib/i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"started-text": "gestartet",
"openwithexplorer-text": "Mit Datei-Explorer öffnen",
"openwithwt-text": "Mit Windows-Terminal öffnen",
"openwithwt-not-found-error": "Windows Terminal nicht gefunden. Wird im PowerShell geöffnet.",
"openwithvscode-text": "Mit VS-Code öffnen",
"copy-text": "Kopieren",
"rename-text": "Umbenennen",
Expand Down
1 change: 1 addition & 0 deletions lib/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"started-text": "started",
"openwithexplorer-text": "Open with File Explorer",
"openwithwt-text": "Open with Windows Terminal",
"openwithwt-not-found-error": "Windows Terminal not found. Launching in PowerShell instead.",
"openwithvscode-text": "Open with VS Code",
"copy-text": "Copy",
"rename-text": "Rename",
Expand Down
Loading