From f6e3289698fd773e4dc7962b828e37f43e63f979 Mon Sep 17 00:00:00 2001 From: Fodor Benedek Date: Mon, 24 Jun 2024 14:39:14 +0200 Subject: [PATCH 1/2] launch with terminal: add fallback to powershell on exception --- lib/api/wsl.dart | 17 +++++++++++++---- lib/i18n/en.json | 1 + 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/api/wsl.dart b/lib/api/wsl.dart index c0ba528..a2ebb02 100644 --- a/lib/api/wsl.dart +++ b/lib/api/wsl.dart @@ -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 { @@ -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 args = ['wt', 'wsl', '-d', distribution, '--cd', '~']; - Process.start('start', args, - mode: ProcessStartMode.normal, runInShell: true); + List launchWslHome = ['wsl', '-d', distribution, '--cd', '~']; + try { + await Process.start('wt', launchWslHome); + } 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 diff --git a/lib/i18n/en.json b/lib/i18n/en.json index 8ee759b..5c04cd8 100644 --- a/lib/i18n/en.json +++ b/lib/i18n/en.json @@ -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", From 33368a10bcff1fa0e94778e29548b8a16eccdcc6 Mon Sep 17 00:00:00 2001 From: Fodor Benedek Date: Mon, 24 Jun 2024 14:39:47 +0200 Subject: [PATCH 2/2] powershell fallback error 'de' i18n needs further translation to other langs! --- lib/i18n/de.json | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/i18n/de.json b/lib/i18n/de.json index 53a1831..29e38d8 100644 --- a/lib/i18n/de.json +++ b/lib/i18n/de.json @@ -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",