Skip to content
This repository has been archived by the owner on Mar 23, 2023. It is now read-only.

[FEATURE] Add Dark mode #209 #98 #31 #229

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
3 changes: 1 addition & 2 deletions RaceControl/RaceControl.Core/Controls/BusyIndicator.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Background="#60DDDDDD">
VerticalAlignment="Stretch">
<Viewbox
Width="50"
Height="50"
Expand Down
2 changes: 2 additions & 0 deletions RaceControl/RaceControl.Core/Settings/ISettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public interface ISettings

bool EnableMpvAutoSync { get; set; }

bool UseDarkTheme { get; set; }

string AdditionalMpvParameters { get; set; }

string CustomMpvPath { get; set; }
Expand Down
7 changes: 7 additions & 0 deletions RaceControl/RaceControl.Core/Settings/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class Settings : BindableBase, ISettings
private bool _disableLiveSessionNotification;
private bool _disableMpvNoBorder;
private bool _enableMpvAutoSync;
private bool _useDarkTheme;
private string _additionalMpvParameters;
private string _customMpvPath;
private string _latestRelease;
Expand Down Expand Up @@ -105,6 +106,12 @@ public bool EnableMpvAutoSync
set => SetProperty(ref _enableMpvAutoSync, value);
}

public bool UseDarkTheme
{
get => _useDarkTheme;
set => SetProperty(ref _useDarkTheme, value);
}

public string AdditionalMpvParameters
{
get => _additionalMpvParameters;
Expand Down
10 changes: 9 additions & 1 deletion RaceControl/RaceControl/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,12 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:prism="http://prismlibrary.com/"
DispatcherUnhandledException="PrismApplication_DispatcherUnhandledException" />
DispatcherUnhandledException="PrismApplication_DispatcherUnhandledException">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Themes/LightTheme.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</prism:PrismApplication>
9 changes: 9 additions & 0 deletions RaceControl/RaceControl/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ namespace RaceControl
{
public partial class App
{
private static readonly ResourceDictionary LightTheme = new() { Source = new Uri(@"/Themes/LightTheme.xaml", UriKind.Relative) };
private static readonly ResourceDictionary DarkTheme = new() { Source = new Uri(@"/Themes/DarkTheme.xaml", UriKind.Relative) };

private readonly SplashScreen _splashScreen = new("splashscreen.png");

private static int _flyleafUniqueId;
Expand Down Expand Up @@ -100,6 +103,12 @@ protected override void RegisterTypes(IContainerRegistry registry)

protected override Window CreateShell()
{
var settings = Container.Resolve<ISettings>();
settings.Load();

App.Current.Resources.MergedDictionaries.Clear();
App.Current.Resources.MergedDictionaries.Add(settings.UseDarkTheme ? DarkTheme : LightTheme);

_splashScreen.Close(TimeSpan.Zero);

return Container.Resolve<MainWindow>();
Expand Down
5,346 changes: 5,346 additions & 0 deletions RaceControl/RaceControl/Themes/DarkTheme.xaml

Large diffs are not rendered by default.

5,336 changes: 5,336 additions & 0 deletions RaceControl/RaceControl/Themes/LightTheme.xaml

Large diffs are not rendered by default.

12 changes: 11 additions & 1 deletion RaceControl/RaceControl/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ namespace RaceControl.ViewModels
public class MainWindowViewModel : ViewModelBase, ICloseWindow
{
private const int PlayPauseHotKeyID = 9000;
private static readonly ResourceDictionary LightTheme = new() { Source = new Uri(@"/Themes/LightTheme.xaml", UriKind.Relative) };
private static readonly ResourceDictionary DarkTheme = new() { Source = new Uri(@"/Themes/DarkTheme.xaml", UriKind.Relative) };

private readonly IExtendedDialogService _dialogService;
private readonly IEventAggregator _eventAggregator;
Expand Down Expand Up @@ -86,6 +88,7 @@ public class MainWindowViewModel : ViewModelBase, ICloseWindow
private ICommand _audioTrackSelectionChangedCommand;
private ICommand _logOutCommand;
private ICommand _requestNavigateCommand;
private ICommand _updateThemeCommand;

private HwndSource _hwndSource;
private string _episodeFilterText;
Expand Down Expand Up @@ -169,6 +172,7 @@ public MainWindowViewModel(
public ICommand AudioTrackSelectionChangedCommand => _audioTrackSelectionChangedCommand ??= new DelegateCommand(AudioTrackSelectionChangedExecute);
public ICommand LogOutCommand => _logOutCommand ??= new DelegateCommand(LogOutExecute);
public ICommand RequestNavigateCommand => _requestNavigateCommand ??= new DelegateCommand<RequestNavigateEventArgs>(RequestNavigateExecute);
public ICommand UpdateThemeCommand => _updateThemeCommand ??= new DelegateCommand(UpdateThemeExecute);

public Action Close { get; set; }

Expand Down Expand Up @@ -302,8 +306,8 @@ private void LoadedExecute(RoutedEventArgs args)
_hwndSource = HwndSource.FromHwnd(helper.Handle);

IsBusy = true;
Settings.Load();
VideoDialogLayout.Load();
UpdateThemeCommand.TryExecute();
SetVlcExeLocation();
SetMpvExeLocation();
SetMpcExeLocation();
Expand Down Expand Up @@ -604,6 +608,12 @@ private static void RequestNavigateExecute(RequestNavigateEventArgs e)
ProcessUtils.BrowseToUrl(e.Uri.AbsoluteUri);
}

private void UpdateThemeExecute()
{
Application.Current.Resources.MergedDictionaries.Clear();
Application.Current.Resources.MergedDictionaries.Add(Settings.UseDarkTheme ? DarkTheme : LightTheme);
}

private void RefreshTimer_Elapsed(object sender, ElapsedEventArgs e)
{
lock (_refreshTimerLock)
Expand Down
1 change: 1 addition & 0 deletions RaceControl/RaceControl/Views/DownloadDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:enums="clr-namespace:RaceControl.Common.Enums;assembly=RaceControl.Common"
xmlns:prism="http://prismlibrary.com/"
Style="{DynamicResource UserControlStyle}"
prism:ViewModelLocator.AutoWireViewModel="True">
<prism:Dialog.WindowStyle>
<Style TargetType="Window">
Expand Down
1 change: 1 addition & 0 deletions RaceControl/RaceControl/Views/LoginDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
xmlns:core="clr-namespace:RaceControl.Core.Converters;assembly=RaceControl.Core"
xmlns:mvvm="clr-namespace:RaceControl.Core.Mvvm;assembly=RaceControl.Core"
xmlns:prism="http://prismlibrary.com/"
Style="{DynamicResource UserControlStyle}"
prism:ViewModelLocator.AutoWireViewModel="True">
<UserControl.Resources>
<core:InverseBooleanConverter x:Key="InverseBooleanConverter" />
Expand Down
Loading