Skip to content

Commit 79cf73e

Browse files
authored
fix: Open Terminal on Welcome Page crashed (Windows) (#1740)
Trying to open the Windows Terminal on the Welcome Page crashed with a `NullReferenceException`. The code for Windows after the fix is similar to the corresponding code for Linux.
1 parent 8a0c2f1 commit 79cf73e

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/Native/Windows.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -203,19 +203,23 @@ public void OpenBrowser(string url)
203203

204204
public void OpenTerminal(string workdir)
205205
{
206-
if (!File.Exists(OS.ShellOrTerminal))
206+
var home = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
207+
var cwd = string.IsNullOrEmpty(workdir) ? home : workdir;
208+
var terminal = OS.ShellOrTerminal;
209+
210+
if (!File.Exists(terminal))
207211
{
208212
App.RaiseException(workdir, "Terminal is not specified! Please confirm that the correct shell/terminal has been configured.");
209213
return;
210214
}
211215

212216
var startInfo = new ProcessStartInfo();
213-
startInfo.WorkingDirectory = workdir;
214-
startInfo.FileName = OS.ShellOrTerminal;
217+
startInfo.WorkingDirectory = cwd;
218+
startInfo.FileName = terminal;
215219

216220
// Directly launching `Windows Terminal` need to specify the `-d` parameter
217-
if (OS.ShellOrTerminal.EndsWith("wt.exe", StringComparison.OrdinalIgnoreCase))
218-
startInfo.Arguments = $"-d {workdir.Quoted()}";
221+
if (terminal.EndsWith("wt.exe", StringComparison.OrdinalIgnoreCase))
222+
startInfo.Arguments = $"-d {cwd.Quoted()}";
219223

220224
Process.Start(startInfo);
221225
}

0 commit comments

Comments
 (0)