Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml">
<Application.Resources>

<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Themes/LightMode.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
45 changes: 45 additions & 0 deletions App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,53 @@
using System;
using System.Windows;
using Microsoft.Win32;

namespace UnifiedExplorer
{
public partial class App : Application
{
public static AppSettings Settings { get; set; } = new AppSettings();

protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);

Settings = SettingsManager.LoadSettings();
ApplyTheme(Settings.Theme);

SystemEvents.UserPreferenceChanged += SystemEvents_UserPreferenceChanged;
}

private void SystemEvents_UserPreferenceChanged(object sender, UserPreferenceChangedEventArgs e)
{
if (e.Category == UserPreferenceCategory.General && Settings.Theme == ThemeMode.System)
{
ApplyTheme(ThemeMode.System);
}
}

public static void ApplyTheme(ThemeMode mode)
{
Settings.Theme = mode;
SettingsManager.SaveSettings(Settings);

bool isLight = true;
if (mode == ThemeMode.Dark)
{
isLight = false;
}
else if (mode == ThemeMode.System)
{
isLight = SettingsManager.IsSystemThemeLight();
}

var dict = new ResourceDictionary();
dict.Source = isLight
? new Uri("Themes/LightMode.xaml", UriKind.Relative)
: new Uri("Themes/DarkMode.xaml", UriKind.Relative);

Current.Resources.MergedDictionaries.Clear();
Current.Resources.MergedDictionaries.Add(dict);
}
}
}
173 changes: 139 additions & 34 deletions MainWindow.xaml

Large diffs are not rendered by default.

183 changes: 134 additions & 49 deletions MainWindow.xaml.cs

Large diffs are not rendered by default.

68 changes: 68 additions & 0 deletions SettingsManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using System;
using System.IO;
using System.Text.Json;
using Microsoft.Win32;

namespace UnifiedExplorer
{
public enum ThemeMode
{
Light,
Dark,
System
}

public class AppSettings
{
public ThemeMode Theme { get; set; } = ThemeMode.System;
}

public static class SettingsManager
{
private static readonly string SettingsFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "appsettings.json");

public static AppSettings LoadSettings()
{
if (File.Exists(SettingsFile))
{
try
{
string json = File.ReadAllText(SettingsFile);
var settings = JsonSerializer.Deserialize<AppSettings>(json);
if (settings != null) return settings;
}
catch { }
}
return new AppSettings();
}

public static void SaveSettings(AppSettings settings)
{
try
{
string json = JsonSerializer.Serialize(settings, new JsonSerializerOptions { WriteIndented = true });
File.WriteAllText(SettingsFile, json);
}
catch { }
}

public static bool IsSystemThemeLight()
{
try
{
using var key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Themes\Personalize");
if (key != null)
{
var value = key.GetValue("AppsUseLightTheme");
if (value is int i)
{
return i == 1;
}
}
}
catch { }

return true;
}
}
}
17 changes: 17 additions & 0 deletions SettingsWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Window x:Class="UnifiedExplorer.SettingsWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Settings" Height="200" Width="300"
WindowStartupLocation="CenterOwner" ResizeMode="NoResize"
Background="{DynamicResource BackgroundColor}"
Foreground="{DynamicResource TextColor}">
<Grid Margin="15">
<StackPanel>
<TextBlock Text="Theme Settings" FontSize="16" FontWeight="Bold" Margin="0,0,0,15" Foreground="{DynamicResource TextColor}"/>

<RadioButton x:Name="DarkThemeRadio" Content="Darkmode" Margin="0,5" Checked="ThemeRadio_Checked" Tag="Dark" Foreground="{DynamicResource TextColor}"/>
<RadioButton x:Name="LightThemeRadio" Content="Lightmode" Margin="0,5" Checked="ThemeRadio_Checked" Tag="Light" Foreground="{DynamicResource TextColor}"/>
<RadioButton x:Name="SystemThemeRadio" Content="Systemsettings" Margin="0,5" Checked="ThemeRadio_Checked" Tag="System" Foreground="{DynamicResource TextColor}"/>
</StackPanel>
</Grid>
</Window>
48 changes: 48 additions & 0 deletions SettingsWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System.Windows;

namespace UnifiedExplorer
{
public partial class SettingsWindow : Window
{
private bool _isInitialized = false;

public SettingsWindow()
{
InitializeComponent();

// Set initial state based on current settings
switch (App.Settings.Theme)
{
case ThemeMode.Light:
LightThemeRadio.IsChecked = true;
break;
case ThemeMode.Dark:
DarkThemeRadio.IsChecked = true;
break;
case ThemeMode.System:
SystemThemeRadio.IsChecked = true;
break;
}

_isInitialized = true;
}

private void ThemeRadio_Checked(object sender, RoutedEventArgs e)
{
if (!_isInitialized) return;

if (DarkThemeRadio.IsChecked == true)
{
App.ApplyTheme(ThemeMode.Dark);
}
else if (LightThemeRadio.IsChecked == true)
{
App.ApplyTheme(ThemeMode.Light);
}
else if (SystemThemeRadio.IsChecked == true)
{
App.ApplyTheme(ThemeMode.System);
}
}
}
}
11 changes: 11 additions & 0 deletions Themes/DarkMode.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<SolidColorBrush x:Key="BackgroundColor" Color="#191919"/>
<SolidColorBrush x:Key="MenuBarColor" Color="#2c2c2c"/>
<SolidColorBrush x:Key="TextColor" Color="#98e7e5e5"/> <!-- e7e5e598 wait, ARGB in WPF is #AARRGGBB, issue has #e7e5e598, so A=98, R=e7, G=e5, B=e5 -->
<SolidColorBrush x:Key="SelectColor" Color="#272727"/>
<SolidColorBrush x:Key="SelectedColor" Color="#b68989"/>
<SolidColorBrush x:Key="FolderColor" Color="#ffd767"/>
<SolidColorBrush x:Key="FolderStringColor" Color="#2b2c31"/>
<SolidColorBrush x:Key="BottomBarColor" Color="#4a4a4a"/>
</ResourceDictionary>
74 changes: 74 additions & 0 deletions Themes/GlobalStyles.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style TargetType="ListBoxItem" x:Key="CustomListBoxItemStyle">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
<Setter Property="Padding" Value="5,4"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<Border x:Name="Bd" Background="{TemplateBinding Background}" BorderThickness="0" Padding="{TemplateBinding Padding}">
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="Bd" Property="Background" Value="{DynamicResource SelectColor}"/>
</Trigger>
<Trigger Property="IsSelected" Value="True">
<Setter TargetName="Bd" Property="Background" Value="{DynamicResource SelectedColor}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

<Style TargetType="TreeViewItem" x:Key="CustomTreeViewItemStyle">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
<Setter Property="Padding" Value="5,4"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="TreeViewItem">
<StackPanel>
<Border x:Name="Bd" Background="{TemplateBinding Background}" BorderThickness="0" Padding="{TemplateBinding Padding}">
<ContentPresenter x:Name="PART_Header" ContentSource="Header" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
</Border>
<ItemsPresenter x:Name="ItemsHost" Visibility="Collapsed"/>
</StackPanel>
<ControlTemplate.Triggers>
<Trigger Property="IsExpanded" Value="True">
<Setter TargetName="ItemsHost" Property="Visibility" Value="Visible"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="True" SourceName="Bd">
<Setter TargetName="Bd" Property="Background" Value="{DynamicResource SelectColor}"/>
</Trigger>
<Trigger Property="IsSelected" Value="True">
<Setter TargetName="Bd" Property="Background" Value="{DynamicResource SelectedColor}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

<Style TargetType="ListViewItem" x:Key="CustomListViewItemStyle">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
<Setter Property="Padding" Value="2"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListViewItem">
<Border x:Name="Bd" Background="{TemplateBinding Background}" BorderThickness="0" Padding="{TemplateBinding Padding}">
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="Bd" Property="Background" Value="{DynamicResource SelectColor}"/>
</Trigger>
<Trigger Property="IsSelected" Value="True">
<Setter TargetName="Bd" Property="Background" Value="{DynamicResource SelectedColor}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
11 changes: 11 additions & 0 deletions Themes/LightMode.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<SolidColorBrush x:Key="BackgroundColor" Color="#f0f0f0"/>
<SolidColorBrush x:Key="MenuBarColor" Color="#f3f3f3"/>
<SolidColorBrush x:Key="TextColor" Color="#1d1d1d"/>
<SolidColorBrush x:Key="SelectColor" Color="#d9d9d9"/>
<SolidColorBrush x:Key="SelectedColor" Color="#afaf99"/>
<SolidColorBrush x:Key="FolderColor" Color="#f3b10c"/>
<SolidColorBrush x:Key="FolderStringColor" Color="#bbbbbb"/>
<SolidColorBrush x:Key="BottomBarColor" Color="#f3f3f3"/>
</ResourceDictionary>
4 changes: 2 additions & 2 deletions UnifiedExplorer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
<ApplicationIcon>assets\app.ico</ApplicationIcon>
<Version>1.0.0</Version>
<Version>1.0.1</Version>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<FileVersion>1.0.0.0</FileVersion>
<FileVersion>1.0.1.0</FileVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
Loading