Skip to content

Commit 1c60f0c

Browse files
authored
Set WorkingDirectory for terminal (#1136)
1 parent 5c59258 commit 1c60f0c

File tree

5 files changed

+21
-13
lines changed

5 files changed

+21
-13
lines changed

Files.Launcher/Program.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Files.Common;
2+
using NLog;
23
using System;
34
using System.Collections.Generic;
45
using System.ComponentModel;
@@ -272,17 +273,19 @@ private static async void Connection_RequestReceived(AppServiceConnection sender
272273

273274
private static void HandleApplicationLaunch(AppServiceRequestReceivedEventArgs args)
274275
{
275-
var arguments = args.Request.Message.Get<string, string, object>("Arguments");
276+
var arguments = args.Request.Message.Get("Arguments", "");
277+
var workingDirectory = args.Request.Message.Get("WorkingDirectory", "");
276278

277279
try
278280
{
279281
var executable = (string)args.Request.Message["Application"];
280282
Process process = new Process();
281283
process.StartInfo.UseShellExecute = false;
282284
process.StartInfo.FileName = executable;
283-
// Show window if arguments (opening terminal)
284-
process.StartInfo.CreateNoWindow = string.IsNullOrEmpty(arguments);
285+
// Show window if workingDirectory (opening terminal)
286+
process.StartInfo.CreateNoWindow = string.IsNullOrEmpty(workingDirectory);
285287
process.StartInfo.Arguments = arguments;
288+
process.StartInfo.WorkingDirectory = workingDirectory;
286289
process.Start();
287290
}
288291
catch (Win32Exception)
@@ -294,6 +297,7 @@ private static void HandleApplicationLaunch(AppServiceRequestReceivedEventArgs a
294297
process.StartInfo.FileName = executable;
295298
process.StartInfo.CreateNoWindow = true;
296299
process.StartInfo.Arguments = arguments;
300+
process.StartInfo.WorkingDirectory = workingDirectory;
297301
try
298302
{
299303
process.Start();

Files/Assets/terminal/terminal.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@
55
{
66
"name": "CMD",
77
"path": "cmd.exe",
8-
"arguments": "/k \"cd /d {0} && title Command Prompt\"",
8+
"arguments": "",
99
"icon": ""
1010
}
1111
/*
1212
{
1313
"name": "PowerShell Core 6",
1414
"path": "pwsh.exe",
15-
"arguments": "-WorkingDirectory \"{0}\"",
15+
"arguments": "",
1616
"icon": ""
1717
},
1818
{
1919
"name": "Windows Terminal",
2020
"path": "wt.exe",
21-
"arguments": "-d \"{0}\"",
21+
"arguments": "-d .",
2222
"icon": ""
2323
}
2424
*/

Files/Interacts/Interaction.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,13 @@ public async void OpenDirectoryInTerminal(object sender, RoutedEventArgs e)
138138

139139
if (App.Connection != null)
140140
{
141-
var value = new ValueSet();
142-
value.Add("Application", terminal.Path);
143-
value.Add("Arguments", string.Format(terminal.Arguments, CurrentInstance.ViewModel.WorkingDirectory));
141+
var value = new ValueSet
142+
{
143+
{ "WorkingDirectory", CurrentInstance.ViewModel.WorkingDirectory },
144+
{ "Application", terminal.Path },
145+
{ "Arguments", string.Format(terminal.Arguments,
146+
InstanceTabsView.NormalizePath(CurrentInstance.ViewModel.WorkingDirectory)) }
147+
};
144148
await App.Connection.SendMessageAsync(value);
145149
}
146150
}

Files/View Models/SettingsViewModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,15 +248,15 @@ private async void LoadTerminalApps()
248248
{
249249
Name = "Windows Terminal",
250250
Path = "wt.exe",
251-
Arguments = "-d \"{0}\"",
251+
Arguments = "-d .",
252252
Icon = ""
253253
};
254254

255255
var fluentTerminal = new TerminalModel()
256256
{
257257
Name = "Fluent Terminal",
258258
Path = "flute.exe",
259-
Arguments = "new \"{0}\"",
259+
Arguments = "",
260260
Icon = ""
261261
};
262262

Files/Views/SettingsPages/Appearance.xaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public Appearance()
2525
ThemeChooser.SelectedIndex = (int)Enum.Parse(typeof(ElementTheme), ThemeHelper.RootTheme.ToString());
2626
ThemeChooser.Loaded += (s, e) =>
2727
{
28-
ThemeChooser.SelectionChanged += async (s1, e1) =>
28+
ThemeChooser.SelectionChanged += (s1, e1) =>
2929
{
3030
var themeComboBox = s1 as ComboBox;
3131

@@ -56,7 +56,7 @@ public Appearance()
5656
DateFormatChooser.SelectedIndex = (int)Enum.Parse(typeof(TimeStyle), _selectedFormat.ToString());
5757
DateFormatChooser.Loaded += (s, e) =>
5858
{
59-
DateFormatChooser.SelectionChanged += async (s1, e1) =>
59+
DateFormatChooser.SelectionChanged += (s1, e1) =>
6060
{
6161
var timeStyleComboBox = s1 as ComboBox;
6262

0 commit comments

Comments
 (0)