Skip to content

Commit 114bff3

Browse files
yaira2hishitetsu
andauthored
Feature: Added a setting to hide the System Tray icon (#15947)
Co-authored-by: hishitetsu <[email protected]>
1 parent bb33baa commit 114bff3

File tree

8 files changed

+68
-6
lines changed

8 files changed

+68
-6
lines changed

src/Files.App/App.xaml.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace Files.App
1818
/// </summary>
1919
public partial class App : Application
2020
{
21-
private static SystemTrayIcon? SystemTrayIcon { get; set; }
21+
public static SystemTrayIcon? SystemTrayIcon { get; private set; }
2222

2323
public static TaskCompletionSource? SplashScreenLoadingTCS { get; private set; }
2424
public static string? OutputPath { get; set; }
@@ -132,14 +132,18 @@ async Task ActivateAsync()
132132
SplashScreenLoadingTCS = null;
133133

134134
// Create a system tray icon
135-
SystemTrayIcon = new SystemTrayIcon().Show();
135+
SystemTrayIcon = new SystemTrayIcon();
136+
if (userSettingsService.GeneralSettingsService.ShowSystemTrayIcon)
137+
SystemTrayIcon.Show();
136138

137139
_ = MainWindow.Instance.InitializeApplicationAsync(appActivationArguments.Data);
138140
}
139141
else
140142
{
141143
// Create a system tray icon
142-
SystemTrayIcon = new SystemTrayIcon().Show();
144+
SystemTrayIcon = new SystemTrayIcon();
145+
if (userSettingsService.GeneralSettingsService.ShowSystemTrayIcon)
146+
SystemTrayIcon.Show();
143147

144148
// Sleep current instance
145149
Program.Pool = new(0, 1, $"Files-{AppLifecycleHelper.AppEnvironment}-Instance");

src/Files.App/Data/Contracts/IGeneralSettingsService.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,11 @@ public interface IGeneralSettingsService : IBaseSettingsService, INotifyProperty
234234
/// Gets or sets a value indicating whether or not to leave app running in the background.
235235
/// </summary>
236236
bool LeaveAppRunning { get; set; }
237+
238+
/// <summary>
239+
/// Gets or sets a value indicating whether or not to show Files in the system tray.
240+
/// </summary>
241+
bool ShowSystemTrayIcon { get; set; }
237242

238243
/// <summary>
239244
/// Gets or sets a value indicating the default option to resolve conflicts.

src/Files.App/Helpers/Application/AppLifecycleHelper.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ static Task OptionalTaskAsync(Task task, bool condition)
9393

9494
return Task.CompletedTask;
9595
}
96+
97+
generalSettingsService.PropertyChanged += GeneralSettingsService_PropertyChanged;
9698
}
9799

98100
/// <summary>
@@ -361,5 +363,22 @@ public static bool IsAutoHideTaskbarEnabled()
361363
// The least significant bit of the 9th byte controls the auto-hide setting
362364
return value != null && ((value[8] & 0x01) == 1);
363365
}
366+
367+
/// <summary>
368+
/// Updates the visibility of the system tray icon
369+
/// </summary>
370+
private static void GeneralSettingsService_PropertyChanged(object? sender, PropertyChangedEventArgs e)
371+
{
372+
if (sender is not IGeneralSettingsService generalSettingsService)
373+
return;
374+
375+
if (e.PropertyName == nameof(IGeneralSettingsService.ShowSystemTrayIcon))
376+
{
377+
if (generalSettingsService.ShowSystemTrayIcon)
378+
App.SystemTrayIcon?.Show();
379+
else
380+
App.SystemTrayIcon?.Hide();
381+
}
382+
}
364383
}
365384
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,12 @@ public bool LeaveAppRunning
291291
set => Set(value);
292292
}
293293

294+
public bool ShowSystemTrayIcon
295+
{
296+
get => Get(true);
297+
set => Set(value);
298+
}
299+
294300
public FileNameConflictResolveOptionType ConflictsResolveOption
295301
{
296302
get => (FileNameConflictResolveOptionType)Get((long)FileNameConflictResolveOptionType.GenerateNewName);

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3905,4 +3905,7 @@
39053905
<data name="Vertical" xml:space="preserve">
39063906
<value>Vertical</value>
39073907
</data>
3908+
<data name="ShowSystemTrayIcon" xml:space="preserve">
3909+
<value>Show Files icon in the System Tray</value>
3910+
</data>
39083911
</root>

src/Files.App/Utils/Taskbar/SystemTrayIcon.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
// Copyright (c) 2024 Files Community
22
// Licensed under the MIT License. See the LICENSE.
33

4-
using System.Runtime.InteropServices;
54
using System.Drawing;
5+
using System.Runtime.InteropServices;
6+
using Windows.ApplicationModel;
67
using Windows.Foundation;
8+
using Windows.System;
79
using Windows.Win32;
810
using Windows.Win32.Foundation;
911
using Windows.Win32.UI.Shell;
1012
using Windows.Win32.UI.WindowsAndMessaging;
11-
using Windows.ApplicationModel;
12-
using Windows.System;
1313

1414
namespace Files.App.Utils.Taskbar
1515
{

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,20 @@ public bool LeaveAppRunning
333333
}
334334
}
335335
}
336+
337+
public bool ShowSystemTrayIcon
338+
{
339+
get => UserSettingsService.GeneralSettingsService.ShowSystemTrayIcon;
340+
set
341+
{
342+
if (value != UserSettingsService.GeneralSettingsService.ShowSystemTrayIcon)
343+
{
344+
UserSettingsService.GeneralSettingsService.ShowSystemTrayIcon = value;
345+
346+
OnPropertyChanged();
347+
}
348+
}
349+
}
336350

337351
public async Task OpenFilesOnWindowsStartupAsync()
338352
{

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,17 @@
129129
Style="{StaticResource RightAlignedToggleSwitchStyle}" />
130130
</local:SettingsBlockControl>
131131

132+
<!-- System Tray Icon -->
133+
<local:SettingsBlockControl Title="{helpers:ResourceString Name=ShowSystemTrayIcon}" HorizontalAlignment="Stretch">
134+
<local:SettingsBlockControl.Icon>
135+
<FontIcon Glyph="&#xE75B;" />
136+
</local:SettingsBlockControl.Icon>
137+
<ToggleSwitch
138+
AutomationProperties.Name="{helpers:ResourceString Name=ShowSystemTrayIcon}"
139+
IsOn="{x:Bind ViewModel.ShowSystemTrayIcon, Mode=TwoWay}"
140+
Style="{StaticResource RightAlignedToggleSwitchStyle}" />
141+
</local:SettingsBlockControl>
142+
132143
<!-- Experimental Settings -->
133144
<TextBlock
134145
Padding="0,16,0,4"

0 commit comments

Comments
 (0)