Skip to content

Commit

Permalink
#187 & Custom Theme Color
Browse files Browse the repository at this point in the history
  • Loading branch information
natsurainko committed Oct 1, 2023
1 parent 202f6cd commit 3cb5259
Show file tree
Hide file tree
Showing 11 changed files with 211 additions and 23 deletions.
2 changes: 1 addition & 1 deletion FluentLauncher.LocalizationPoroject
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,12 @@ public partial class SettingsService : SettingsContainer, IFluentCoreSettingsSer
[SettingItem(typeof(bool), "UseNewHomePage", Default = true, Converter = typeof(JsonStringConverter<bool>))]
[SettingItem(typeof(double), "TintLuminosityOpacity", Default = 0.64, Converter = typeof(JsonStringConverter<double>))]
[SettingItem(typeof(double), "TintOpacity", Default = 0, Converter = typeof(JsonStringConverter<double>))]
[SettingItem(typeof(bool), "EnableDefaultAcrylicBrush", Default = true, Converter = typeof(JsonStringConverter<bool>))]
[SettingItem(typeof(bool), "EnableDefaultAcrylicBrush", Default = false, Converter = typeof(JsonStringConverter<bool>))]
[SettingItem(typeof(string), "ImageFilePath", Default = "", Converter = typeof(JsonStringConverter<string>))]
[SettingItem(typeof(int), "SolidSelectedIndex", Default = 0, Converter = typeof(JsonStringConverter<int>))]
[SettingItem(typeof(Windows.UI.Color), "SolidCustomColor", Converter = typeof(JsonStringConverter<Windows.UI.Color>))]
[SettingItem(typeof(Windows.UI.Color), "ThemeCustomColor", Converter = typeof(JsonStringConverter<Windows.UI.Color>))]
[SettingItem(typeof(bool), "UseSystemAccentColor", Default = true, Converter = typeof(JsonStringConverter<bool>))]

[SettingItem(typeof(double), "AppWindowHeight", Default = 500, Converter = typeof(JsonStringConverter<double>))]
[SettingItem(typeof(double), "AppWindowWidth", Default = 950, Converter = typeof(JsonStringConverter<double>))]
Expand Down
26 changes: 26 additions & 0 deletions Natsurainko.FluentLauncher/Services/UI/AppearanceService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,23 @@ public void ApplyBackgroundBeforePageInit(ShellPage page)
}
}

public void ApplyThemeColorBeforePageInit(ShellPage page)
{
if (!_settingsService.UseSystemAccentColor)
{
App.Current.Resources["SystemAccentColorLight1"] = _settingsService.ThemeCustomColor.GetValueOrDefault();
App.Current.Resources["SystemAccentColorLight2"] = _settingsService.ThemeCustomColor.GetValueOrDefault();
App.Current.Resources["SystemAccentColorLight3"] = _settingsService.ThemeCustomColor.GetValueOrDefault();
App.Current.Resources["SystemAccentColorDark1"] = _settingsService.ThemeCustomColor.GetValueOrDefault();
App.Current.Resources["SystemAccentColorDark2"] = _settingsService.ThemeCustomColor.GetValueOrDefault();
App.Current.Resources["SystemAccentColorDark3"] = _settingsService.ThemeCustomColor.GetValueOrDefault();

App.Current.Resources.Add("RawSystemAccentColor", App.Current.Resources["SystemAccentColor"]);
App.Current.Resources["SystemAccentColor"] = _settingsService.ThemeCustomColor.GetValueOrDefault();
}
else App.Current.Resources.Add("RawSystemAccentColor", App.Current.Resources["SystemAccentColor"]);
}

public void ApplyBackgroundAfterPageInit(ShellPage page)
{
switch (_settingsService.BackgroundMode)
Expand Down Expand Up @@ -144,6 +161,12 @@ bool TrySetAcrylicBackdrop(MainWindow window)
{
m_backdropController.TintOpacity = (float)_settingsService.TintOpacity;
m_backdropController.LuminosityOpacity = (float)_settingsService.TintLuminosityOpacity;
m_backdropController.TintColor = ((FrameworkElement)window.Content).ActualTheme switch
{
ElementTheme.Dark => Colors.Black,
ElementTheme.Light => Colors.White,
_ => Colors.White
};
}

m_backdropController.AddSystemBackdropTarget(window.As<ICompositionSupportsSystemBackdrop>());
Expand Down Expand Up @@ -173,7 +196,10 @@ void Window_Closed(object sender, WindowEventArgs args)
void Window_ThemeChanged(FrameworkElement sender, object args)
{
if (m_configurationSource != null)
{
SetConfigurationSourceTheme();
TrySetAcrylicBackdrop(window);
}
}

void SetConfigurationSourceTheme()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ internal partial class ResourceItemFilesDialogViewModel : ObservableObject
private ContentDialog _dialog;

[ObservableProperty]
[NotifyPropertyChangedFor(nameof(CanComfirm))]
[NotifyPropertyChangedFor(nameof(CanConfirm))]
private object selectedFile;

private readonly InterfaceCacheService _interfaceCacheService = App.GetService<InterfaceCacheService>();
private readonly DownloadService _downloadService = App.GetService<DownloadService>();
private readonly GameService _gameService = App.GetService<GameService>();
private readonly INavigationService _navigationService;

public bool CanComfirm => SelectedFile != null;
public bool CanConfirm => SelectedFile != null;

public ResourceItemFilesDialogViewModel(object resource, INavigationService navigationService)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using AppSettingsManagement.Mvvm;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using CommunityToolkit.WinUI.Helpers;
using Microsoft.UI.Xaml.Controls;
using Natsurainko.FluentLauncher.Services.Settings;
using Natsurainko.FluentLauncher.Utils;
Expand Down Expand Up @@ -36,6 +37,12 @@ internal partial class AppearanceViewModel : SettingsViewModelBase, ISettingsVie
[BindToSetting(Path = nameof(SettingsService.UseNewHomePage))]
private bool useNewHomePage;

[ObservableProperty]
[BindToSetting(Path = nameof(SettingsService.UseSystemAccentColor))]
[NotifyPropertyChangedFor(nameof(CurrentThemeColor))]
[NotifyPropertyChangedFor(nameof(CurrentThemeColorString))]
private bool useSystemAccentColor;

[ObservableProperty]
[BindToSetting(Path = nameof(SettingsService.EnableDefaultAcrylicBrush))]
private bool enableDefaultAcrylicBrush;
Expand All @@ -60,8 +67,30 @@ internal partial class AppearanceViewModel : SettingsViewModelBase, ISettingsVie
[BindToSetting(Path = nameof(SettingsService.SolidCustomColor))]
private Color? solidCustomColor;

[ObservableProperty]
[BindToSetting(Path = nameof(SettingsService.ThemeCustomColor))]
[NotifyPropertyChangedFor(nameof(ThemeCustomColorString))]
[NotifyPropertyChangedFor(nameof(CurrentThemeColor))]
[NotifyPropertyChangedFor(nameof(CurrentThemeColorString))]
private Color? themeCustomColor;

public string ThemeCustomColorString => System.Drawing.ColorTranslator.ToHtml(System.Drawing.Color.FromArgb(ColorHelper.ToInt(ThemeCustomColor.GetValueOrDefault())));

public string CurrentThemeColorString
{
get
{
int value = ColorHelper.ToInt(CurrentThemeColor);
return System.Drawing.ColorTranslator.ToHtml(System.Drawing.Color.FromArgb(value));
}
}

public Color CurrentThemeColor => UseSystemAccentColor ? (Color)App.Current.Resources["RawSystemAccentColor"] : ThemeCustomColor.GetValueOrDefault();

public List<string> SupportedLanguages => ResourceUtils.Languages;
private Flyout ColorFlyout;

private Flyout backgroundColorFlyout;
private Flyout themeColorFlyout;

public AppearanceViewModel(SettingsService settingsService)
{
Expand All @@ -78,12 +107,20 @@ private void AppearanceViewModel_PropertyChanged(object sender, PropertyChangedE
}

[RelayCommand]
private void SelectColorConfirm() => ColorFlyout.Hide();
private void SelectColorConfirm(Button button)
{
if (button.Tag.ToString() == "backgroundColor")
backgroundColorFlyout.Hide();
else themeColorFlyout.Hide();
}

[RelayCommand]
private void Loaded(object args)
{
var button = args.As<Button, object>().sender;
ColorFlyout = button.Flyout as Flyout;

if (button.Tag.ToString() == "backgroundColor")
backgroundColorFlyout = button.Flyout as Flyout;
else themeColorFlyout = button.Flyout as Flyout;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
mc:Ignorable="d">

<Grid>
<ScrollViewer Padding="30,7.5,30,0" VerticalScrollBarVisibility="Auto">
<ScrollViewer Padding="30,15,30,0" VerticalScrollBarVisibility="Auto">
<ItemsRepeater
Margin="0,0,0,20"
Background="Transparent"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</Page.Resources>

<Grid>
<ScrollViewer Padding="30,7.5,30,0" VerticalScrollBarVisibility="Auto">
<ScrollViewer Padding="30,15,30,0" VerticalScrollBarVisibility="Auto">
<ItemsRepeater
Margin="0,0,0,20"
Background="Transparent"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,10 @@
HorizontalAlignment="Stretch"
Command="{Binding ConfirmCommand}"
ElementSoundMode="FocusOnly"
IsEnabled="{Binding CanComfirm}"
IsEnabled="{Binding CanConfirm}"
IsTabStop="False"
Style="{ThemeResource AccentButtonStyle}">
<TextBlock x:Uid="Buttons_Comfirm" Text="Comfirm" />
<TextBlock x:Uid="Buttons_Confirm" Text="Confirm" />
</Button>
<Button
Grid.Column="2"
Expand Down
16 changes: 16 additions & 0 deletions Natsurainko.FluentLauncher/Views/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,20 @@ public MainWindow(INavigationService navService)

App.GetService<AppearanceService>().ApplyBackgroundAtWindowCreated(this);
App.MainWindow = this;

((FrameworkElement)this.Content).ActualThemeChanged += MainWindow_ActualThemeChanged;
}

private void MainWindow_ActualThemeChanged(FrameworkElement sender, object args)
{
AppWindow.TitleBar.ButtonBackgroundColor = AppWindow.TitleBar.ButtonInactiveBackgroundColor = Colors.Transparent;
AppWindow.TitleBar.ButtonForegroundColor = App.Current.RequestedTheme == ApplicationTheme.Light ? Colors.Black : Colors.White;
AppWindow.TitleBar.ButtonHoverForegroundColor = App.Current.RequestedTheme == ApplicationTheme.Light ? Colors.Black : Colors.White;

var hoverColor = App.Current.RequestedTheme == ApplicationTheme.Light ? Colors.Black : Colors.White;
hoverColor.A = 35;

AppWindow.TitleBar.ButtonHoverBackgroundColor = hoverColor;
}

private bool _firstActivated = true;
Expand All @@ -61,4 +75,6 @@ private void WindowEx_Activated(object sender, WindowActivatedEventArgs args)

_firstActivated = false;
}


}
Loading

0 comments on commit 3cb5259

Please sign in to comment.