Skip to content

Commit 411604b

Browse files
authored
Feature: Added setting to change the background color (#10850)
1 parent 31721fe commit 411604b

39 files changed

+147
-1485
lines changed

src/Files.App/App.xaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public partial class App : Application
6666
public static WSLDistroManager WSLDistroManager { get; private set; }
6767
public static LibraryManager LibraryManager { get; private set; }
6868
public static FileTagsManager FileTagsManager { get; private set; }
69-
public static ExternalResourcesHelper ExternalResourcesHelper { get; private set; }
69+
public static AppThemeResourcesHelper AppThemeResourcesHelper { get; private set; }
7070

7171
public static ILogger Logger { get; private set; }
7272
private static readonly UniversalLogWriter logWriter = new UniversalLogWriter();
@@ -146,7 +146,7 @@ private IServiceProvider ConfigureServices()
146146
private static void EnsureSettingsAndConfigurationAreBootstrapped()
147147
{
148148
AppSettings ??= new SettingsViewModel();
149-
ExternalResourcesHelper ??= new ExternalResourcesHelper();
149+
AppThemeResourcesHelper ??= new AppThemeResourcesHelper();
150150
JumpList ??= new JumpListManager();
151151
RecentItemsManager ??= new RecentItems();
152152
AppModel ??= new AppModel();
-293 KB
Binary file not shown.
-269 KB
Binary file not shown.

src/Files.App/Files.App.csproj

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,6 @@
5353
<Content Include="Resources\PropertiesInformation.json">
5454
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
5555
</Content>
56-
<Content Include="Themes\*.xaml">
57-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
58-
<Generator>MSBuild:Compile</Generator>
59-
<SubType>Designer</SubType>
60-
</Content>
6156
<Content Update="Assets\FilesOpenDialog\SetFilesAsDefault.reg">
6257
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
6358
</Content>
@@ -69,13 +64,6 @@
6964
</Content>
7065
<Content Remove="Assets\FilesHome.png" />
7166
</ItemGroup>
72-
<ItemGroup>
73-
<None Remove="Themes\Fake Mica" />
74-
<None Remove="Themes\Fake Mica.xaml" />
75-
</ItemGroup>
76-
<ItemGroup>
77-
<Page Remove="Themes\Fake Mica.xaml" />
78-
</ItemGroup>
7967
<ItemGroup>
8068
<PackageReference Include="ByteSize" Version="2.1.1" />
8169
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.0.0" />
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using Microsoft.UI.Xaml;
2+
using Microsoft.UI.Xaml.Media;
3+
using Windows.UI;
4+
5+
namespace Files.App.Helpers
6+
{
7+
public sealed class AppThemeResourcesHelper
8+
{
9+
/// <summary>
10+
/// Forces the application to use the correct resource styles
11+
/// </summary>
12+
public void ApplyResources()
13+
{
14+
// Get the index of the current theme
15+
var selTheme = ThemeHelper.RootTheme;
16+
17+
// Toggle between the themes to force the controls to use the new resource styles
18+
ThemeHelper.RootTheme = ElementTheme.Dark;
19+
ThemeHelper.RootTheme = ElementTheme.Light;
20+
21+
// Restore the theme to the correct theme
22+
ThemeHelper.RootTheme = selTheme;
23+
}
24+
25+
/// <summary>
26+
/// Overrides the xaml resource for RootBackgroundBrush
27+
/// </summary>
28+
/// <param name="appThemeRootBackgroundColor"></param>
29+
public void SetRootBackgroundColor(Color appThemeRootBackgroundColor)
30+
{
31+
Application.Current.Resources["RootBackgroundBrush"] = appThemeRootBackgroundColor;
32+
}
33+
34+
/// <summary>
35+
/// Overrides the xaml resource for the list view item height
36+
/// </summary>
37+
/// <param name="useCompactSpacing"></param>
38+
public void SetCompactSpacing(bool useCompactSpacing)
39+
{
40+
if (useCompactSpacing)
41+
{
42+
Application.Current.Resources["ListItemHeight"] = 24;
43+
Application.Current.Resources["NavigationViewItemOnLeftMinHeight"] = 20;
44+
}
45+
else
46+
{
47+
Application.Current.Resources["ListItemHeight"] = 36;
48+
Application.Current.Resources["NavigationViewItemOnLeftMinHeight"] = 32;
49+
}
50+
}
51+
}
52+
}

src/Files.App/Helpers/ColorHelpers.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ namespace Files.App.Helpers
55
{
66
internal static class ColorHelpers
77
{
8+
/// <summary>
9+
/// Converts Hex to Windows.UI.Color.
10+
/// </summary>
811
public static Color FromHex(string colorHex)
912
{
1013
colorHex = colorHex.Replace("#", string.Empty);
@@ -14,5 +17,24 @@ public static Color FromHex(string colorHex)
1417

1518
return Color.FromArgb(255, r, g, b);
1619
}
20+
21+
/// <summary>
22+
/// Converts Uint to Windows.UI.Color.
23+
/// </summary>
24+
public static Color FromUint(this uint value)
25+
{
26+
return Windows.UI.Color.FromArgb((byte)((value >> 24) & 0xFF),
27+
(byte)((value >> 16) & 0xFF),
28+
(byte)((value >> 8) & 0xFF),
29+
(byte)(value & 0xFF));
30+
}
31+
32+
/// <summary>
33+
/// Converts Windows.UI.Color to Uint.
34+
/// </summary>
35+
public static uint ToUint(this Color c)
36+
{
37+
return (uint)(((c.A << 24) | (c.R << 16) | (c.G << 8) | c.B) & 0xffffffffL);
38+
}
1739
}
1840
}

src/Files.App/Helpers/ExternalResourcesHelper.cs

Lines changed: 0 additions & 188 deletions
This file was deleted.

src/Files.App/ServicesImplementation/Settings/AppearanceSettingsService.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,13 @@ public bool BundlesWidgetExpanded
127127
set => Set(value);
128128
}
129129

130+
/// <inheritdoc/>
131+
public UInt32 AppThemeRootBackgroundColor
132+
{
133+
get => Get(uint.MinValue);
134+
set => Set(value);
135+
}
136+
130137
protected override void RaiseOnSettingChangedEvent(object sender, SettingChangedEventArgs e)
131138
{
132139
switch (e.SettingName)
@@ -143,6 +150,7 @@ protected override void RaiseOnSettingChangedEvent(object sender, SettingChanged
143150
case nameof(ShowRecentFilesWidget):
144151
case nameof(ShowDrivesWidget):
145152
case nameof(ShowBundlesWidget):
153+
case nameof(AppThemeRootBackgroundColor):
146154
Analytics.TrackEvent($"Set {e.SettingName} to {e.NewValue}");
147155
break;
148156
}

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

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@
218218
<value>Date format</value>
219219
</data>
220220
<data name="SettingsAppearanceTheme" xml:space="preserve">
221-
<value>Choose your color</value>
221+
<value>Theme</value>
222222
</data>
223223
<data name="SettingsFilesAndFoldersShowFileExtensions" xml:space="preserve">
224224
<value>Show extensions for known file types</value>
@@ -235,6 +235,9 @@
235235
<data name="Appearance" xml:space="preserve">
236236
<value>Appearance</value>
237237
</data>
238+
<data name="Background" xml:space="preserve">
239+
<value>Background</value>
240+
</data>
238241
<data name="SettingsNavExperimental.Content" xml:space="preserve">
239242
<value>Experimental</value>
240243
</data>
@@ -1507,9 +1510,6 @@
15071510
<data name="Default" xml:space="preserve">
15081511
<value>Default</value>
15091512
</data>
1510-
<data name="SettingsAppearanceCustomThemes" xml:space="preserve">
1511-
<value>Custom themes</value>
1512-
</data>
15131513
<data name="PropertyItemCount" xml:space="preserve">
15141514
<value>Item count</value>
15151515
</data>
@@ -1987,18 +1987,6 @@
19871987
<data name="SecurityUnknownOwnerText.Text" xml:space="preserve">
19881988
<value>Unknown owner</value>
19891989
</data>
1990-
<data name="SettingsThemesLearnMoreButton.AutomationProperties.Name" xml:space="preserve">
1991-
<value>Learn more about custom themes</value>
1992-
</data>
1993-
<data name="SettingsThemesLearnMoreButton.ToolTipService.ToolTip" xml:space="preserve">
1994-
<value>Learn more about custom themes</value>
1995-
</data>
1996-
<data name="SettingsThemesTeachingTipHeader.Text" xml:space="preserve">
1997-
<value>Custom themes provide a great way for you to personalize Files.</value>
1998-
</data>
1999-
<data name="SettingsThemesTeachingTipHyperlinkText.Text" xml:space="preserve">
2000-
<value>View documentation.</value>
2001-
</data>
20021990
<data name="ExtractArchive" xml:space="preserve">
20031991
<value>Extract Archive</value>
20041992
</data>

0 commit comments

Comments
 (0)