Skip to content

Commit 58b5043

Browse files
gave92gave92
authored andcommitted
Added settings under experimental
1 parent 9ac9c59 commit 58b5043

File tree

8 files changed

+64
-20
lines changed

8 files changed

+64
-20
lines changed

src/Files.App/Services/Settings/GeneralSettingsService.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ public bool ShowCopyPath
216216
get => Get(true);
217217
set => Set(value);
218218
}
219-
219+
220220
public bool ShowCreateFolderWithSelection
221221
{
222222
get => Get(true);
@@ -239,6 +239,12 @@ public bool LeaveAppRunning
239239
set => Set(value);
240240
}
241241

242+
public bool IsTerminalIntegrationEnabled
243+
{
244+
get => Get(false);
245+
set => Set(value);
246+
}
247+
242248
public FileNameConflictResolveOptionType ConflictsResolveOption
243249
{
244250
get => (FileNameConflictResolveOptionType)Get((long)FileNameConflictResolveOptionType.GenerateNewName);

src/Files.App/Services/Settings/IGeneralSettingsService.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,11 @@ public interface IGeneralSettingsService : IBaseSettingsService, INotifyProperty
194194
/// </summary>
195195
bool LeaveAppRunning { get; set; }
196196

197+
/// <summary>
198+
/// Gets or sets a value indicating whether to enable terminal integration.
199+
/// </summary>
200+
bool IsTerminalIntegrationEnabled { get; set; }
201+
197202
/// <summary>
198203
/// Gets or sets a value indicating the default option to resolve conflicts.
199204
/// </summary>

src/Files.App/Strings/en-US/Resources.resw

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3743,4 +3743,7 @@
37433743
<data name="AdaptiveLayoutDisabledNotification" xml:space="preserve">
37443744
<value>Adaptive layout is not available when preferences are synced, the default layout has been changed to Details.</value>
37453745
</data>
3746+
<data name="SettingsTerminalIntegration" xml:space="preserve">
3747+
<value>Enable Terminal integration</value>
3748+
</data>
37463749
</root>

src/Files.App/UserControls/StatusBar.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@
392392
x:Name="TerminalPanel"
393393
Grid.Column="3"
394394
VerticalAlignment="Center"
395-
x:Load="True"
395+
x:Load="{x:Bind MainPageViewModel.IsTerminalIntegrationEnabled, Mode=OneWay}"
396396
Orientation="Horizontal"
397397
Spacing="4">
398398

src/Files.App/UserControls/TerminalView.xaml.cs

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
using CommunityToolkit.WinUI;
2-
using CommunityToolkit.WinUI.Helpers;
32
using Files.App.Utils.Terminal;
43
using Files.App.Utils.Terminal.ConPTY;
54
using Microsoft.Extensions.Logging;
65
using Microsoft.UI.Xaml.Controls;
7-
using Microsoft.UI.Xaml.Media;
86
using Microsoft.Web.WebView2.Core;
97
using Newtonsoft.Json;
108
using Newtonsoft.Json.Serialization;
@@ -197,7 +195,7 @@ private Task<TerminalSize> CreateXtermViewAsync(TerminalOptions options, Termina
197195
var serializedKeyBindings = JsonConvert.SerializeObject(keyBindings, serializerSettings);
198196
return ExecuteScriptAsync(
199197
$"createTerminal('{serializedOptions}', '{serializedTheme}', '{serializedKeyBindings}')")
200-
.ContinueWith(t => JsonConvert.DeserializeObject<TerminalSize>(t.Result));
198+
.ContinueWith(t => JsonConvert.DeserializeObject<TerminalSize>(t.Result)!);
201199
}
202200

203201
private void WebViewControl_NavigationStarting(WebView2 sender, CoreWebView2NavigationStartingEventArgs args)
@@ -445,20 +443,6 @@ private async void TerminalView_ActualThemeChanged(Microsoft.UI.Xaml.FrameworkEl
445443
serializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
446444
var profile = _mainPageModel.TerminalSelectedProfile;
447445
var theme = new DefaultValueProvider().GetPreInstalledThemes().First(x => x.Id == profile.TerminalThemeId);
448-
var backgroundColor = ActualTheme switch
449-
{
450-
Microsoft.UI.Xaml.ElementTheme.Dark => "#000000",
451-
_ => "#FFFFFF"
452-
};
453-
var foregroundColor = ActualTheme switch
454-
{
455-
Microsoft.UI.Xaml.ElementTheme.Dark => "#FFFFFF",
456-
_ => "#000000"
457-
};
458-
theme.Colors.Background = backgroundColor;
459-
theme.Colors.Foreground = foregroundColor;
460-
theme.Colors.CursorAccent = backgroundColor;
461-
theme.Colors.Cursor = foregroundColor;
462446

463447
WebViewControl.CoreWebView2.Profile.PreferredColorScheme = (ActualTheme == Microsoft.UI.Xaml.ElementTheme.Dark) ? CoreWebView2PreferredColorScheme.Dark : CoreWebView2PreferredColorScheme.Light;
464448

src/Files.App/ViewModels/MainPageViewModel.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public sealed class MainPageViewModel : ObservableObject
2121
private INetworkDrivesService NetworkDrivesService { get; } = Ioc.Default.GetRequiredService<INetworkDrivesService>();
2222
private IUserSettingsService UserSettingsService { get; } = Ioc.Default.GetRequiredService<IUserSettingsService>();
2323
private IResourcesService ResourcesService { get; } = Ioc.Default.GetRequiredService<IResourcesService>();
24+
private IGeneralSettingsService GeneralSettingsService { get; } = Ioc.Default.GetRequiredService<IGeneralSettingsService>();
2425
private DrivesViewModel DrivesViewModel { get; } = Ioc.Default.GetRequiredService<DrivesViewModel>();
2526

2627
// Properties
@@ -82,6 +83,17 @@ public MainPageViewModel()
8283
SetTerminalFolder?.Invoke(currentFolder);
8384
});
8485
TerminalSelectedProfile = TerminalProfiles[0];
86+
GeneralSettingsService.PropertyChanged += GeneralSettingsService_PropertyChanged;
87+
}
88+
89+
private void GeneralSettingsService_PropertyChanged(object? sender, PropertyChangedEventArgs e)
90+
{
91+
if (e.PropertyName == nameof(IGeneralSettingsService.IsTerminalIntegrationEnabled))
92+
{
93+
OnPropertyChanged(nameof(IsTerminalIntegrationEnabled));
94+
if (!IsTerminalIntegrationEnabled)
95+
IsTerminalViewOpen = false;
96+
}
8597
}
8698

8799
// Methods
@@ -233,6 +245,8 @@ private void ExecuteNavigateToNumberedTabKeyboardAcceleratorCommand(KeyboardAcce
233245

234246
public List<ShellProfile> TerminalProfiles => new DefaultValueProvider().GetPreinstalledShellProfiles().ToList();
235247

248+
public bool IsTerminalIntegrationEnabled => GeneralSettingsService.IsTerminalIntegrationEnabled;
249+
236250
private bool _isTerminalViewOpen;
237251
public bool IsTerminalViewOpen
238252
{
@@ -244,7 +258,11 @@ public bool IsTerminalViewOpen
244258
public ShellProfile TerminalSelectedProfile
245259
{
246260
get => _terminalSelectedProfile;
247-
set => SetProperty(ref _terminalSelectedProfile, value);
261+
set
262+
{
263+
if (value is not null)
264+
SetProperty(ref _terminalSelectedProfile, value);
265+
}
248266
}
249267
}
250268
}

src/Files.App/ViewModels/Settings/AdvancedViewModel.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,20 @@ public bool LeaveAppRunning
324324
}
325325
}
326326

327+
public bool IsTerminalIntegrationEnabled
328+
{
329+
get => UserSettingsService.GeneralSettingsService.IsTerminalIntegrationEnabled;
330+
set
331+
{
332+
if (value != UserSettingsService.GeneralSettingsService.IsTerminalIntegrationEnabled)
333+
{
334+
UserSettingsService.GeneralSettingsService.IsTerminalIntegrationEnabled = value;
335+
336+
OnPropertyChanged();
337+
}
338+
}
339+
}
340+
327341
public async Task OpenFilesOnWindowsStartupAsync()
328342
{
329343
var stateMode = await ReadState();

src/Files.App/Views/Settings/AdvancedPage.xaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,20 @@
178178
</i:Interaction.Behaviors>
179179
</ToggleSwitch>
180180
</local:SettingsBlockControl>
181+
182+
<!-- Enable terminal integration -->
183+
<local:SettingsBlockControl
184+
x:Name="TerminalIntegrationSettingsBlockControl"
185+
Title="{helpers:ResourceString Name=SettingsTerminalIntegration}"
186+
HorizontalAlignment="Stretch">
187+
<local:SettingsBlockControl.Icon>
188+
<FontIcon Glyph="&#xE756;" />
189+
</local:SettingsBlockControl.Icon>
190+
<ToggleSwitch
191+
AutomationProperties.Name="{helpers:ResourceString Name=SettingsTerminalIntegration}"
192+
IsOn="{x:Bind ViewModel.IsTerminalIntegrationEnabled, Mode=TwoWay}"
193+
Style="{StaticResource RightAlignedToggleSwitchStyle}" />
194+
</local:SettingsBlockControl>
181195
</StackPanel>
182196
</Grid>
183197
</Page>

0 commit comments

Comments
 (0)