Add Darkmode in setting

Add System darkmode detection helper
Add InitializeDarkmode in onload
This commit is contained in:
DB p 2021-11-23 14:33:11 +09:00
parent ef71f6dee2
commit 92ee7638d8
9 changed files with 227 additions and 197 deletions

View file

@ -15,6 +15,7 @@ namespace Flow.Launcher.Infrastructure.UserSettings
private string language = "en";
public string Hotkey { get; set; } = $"{KeyConstant.Alt} + {KeyConstant.Space}";
public string OpenResultModifiers { get; set; } = KeyConstant.Alt;
public string DarkMode { get; set; }
public bool ShowOpenResultHotkey { get; set; } = true;
public double WindowSize { get; set; } = 580;

View file

@ -8,7 +8,7 @@
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ui:ThemeResources RequestedTheme="Dark">
<ui:ThemeResources>
<ui:ThemeResources.ThemeDictionaries>
<ResourceDictionary x:Key="Light">
<ResourceDictionary.MergedDictionaries>
@ -19,7 +19,6 @@
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/Resources/Dark.xaml" />
</ResourceDictionary.MergedDictionaries>
<SolidColorBrush x:Key="NavigationViewSelectionIndicatorForeground" Color="{StaticResource SystemBaseHighColor}" />
</ResourceDictionary>
</ui:ThemeResources.ThemeDictionaries>
</ui:ThemeResources>

View file

@ -96,6 +96,7 @@
</PackageReference>
<PackageReference Include="PropertyChanged.Fody" Version="3.4.0" />
<PackageReference Include="SharpVectors" Version="1.7.6" />
<PackageReference Include="System.Management" Version="6.0.0" />
</ItemGroup>
<ItemGroup>

View file

@ -0,0 +1,76 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
using System.Management;
using System.Security.Principal;
namespace Flow.Launcher.Helper
{
class SystemTheme
{
private const string PersonalizeKey = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize";
private const string SysThemeValueName = "SystemUsesLightTheme";
public static event EventHandler<SystemThemeChangedEventArgs> SystemThemeChanged;
public static bool GetIsSystemLightTheme() => ReadDWord(SysThemeValueName);
private static bool ReadDWord(string valueName)
{
var regkey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(PersonalizeKey);
if (regkey == null)
{
return false;
}
return (int)regkey.GetValue(valueName, 0) > 0;
}
public static void Initialize()
{
UpdateTheme();
try
{
var currentUser = WindowsIdentity.GetCurrent();
var query = new WqlEventQuery(string.Format("SELECT * FROM RegistryValueChangeEvent WHERE Hive='HKEY_USERS' AND KeyPath='{0}\\\\{1}' AND ValueName='{2}'",
currentUser.User.Value, PersonalizeKey.Replace("\\", "\\\\"), SysThemeValueName));
ManagementEventWatcher watcher = new(query);
watcher.EventArrived += new EventArrivedEventHandler(HandleEvent);
watcher.Start();
}
catch (ManagementException managementException)
{
Debug.WriteLine($"{nameof(SystemTheme)}: " + managementException.Message);
}
}
private static void HandleEvent(object sender, EventArrivedEventArgs e)
{
UpdateTheme();
}
private static void UpdateTheme()
{
bool isSystemLightTheme = GetIsSystemLightTheme();
var args = new SystemThemeChangedEventArgs(isSystemLightTheme);
SystemThemeChanged?.Invoke(null, args);
}
}
public class SystemThemeChangedEventArgs : EventArgs
{
public SystemThemeChangedEventArgs(bool isSystemLightTheme)
{
IsSystemLightTheme = isSystemLightTheme;
}
public bool IsSystemLightTheme { get; private set; }
}
}

View file

@ -67,7 +67,7 @@ namespace Flow.Launcher
{
// show notify icon when flowlauncher is hidden
InitializeNotifyIcon();
InitializeDarkMode();
WindowsInteropHelper.DisableControlBox(this);
InitProgressbarAnimation();
InitializePosition();
@ -372,5 +372,19 @@ namespace Flow.Launcher
{
QueryTextBox.CaretIndex = QueryTextBox.Text.Length;
}
public void InitializeDarkMode()
{
if (_settings.DarkMode == "Light")
{
ModernWpf.ThemeManager.Current.ApplicationTheme = ModernWpf.ApplicationTheme.Light;
}
else if (_settings.DarkMode == "Dark")
{
ModernWpf.ThemeManager.Current.ApplicationTheme = ModernWpf.ApplicationTheme.Dark;
}
else
{ }
}
}
}

View file

@ -7,13 +7,13 @@
<!-- Popup Color -->
<Style x:Key="PageBackgroundColor" TargetType="{x:Type Window}">
<Setter Property="Background" Value="{StaticResource Color05B}" />
<Setter Property="Foreground" Value="{StaticResource Color05B}" />
<Setter Property="Background" Value="{DynamicResource Color05B}" />
<Setter Property="Foreground" Value="{DynamicResource Color05B}" />
</Style>
<!-- Setting Window -->
<Style x:Key="PageTitle" TargetType="{x:Type TextBlock}">
<Setter Property="Foreground" Value="{StaticResource Color05B}" />
<Setter Property="Foreground" Value="{DynamicResource Color05B}" />
</Style>
<Style x:Key="Glyph" TargetType="{x:Type TextBlock}">
<Setter Property="Grid.Column" Value="0" />
@ -21,23 +21,23 @@
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="FontSize" Value="20" />
<Setter Property="FontFamily" Value="/Resources/#Segoe Fluent Icons" />
<Setter Property="Foreground" Value="{StaticResource Color05B}" />
<Setter Property="Foreground" Value="{DynamicResource Color05B}" />
</Style>
<Style x:Key="TabMenu" TargetType="{x:Type TextBlock}">
<Setter Property="FontSize" Value="14" />
<Setter Property="FontFamily" Value="Segoe UI" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="Foreground" Value="{StaticResource Color05B}" />
<Setter Property="Foreground" Value="{DynamicResource Color05B}" />
</Style>
<Style x:Key="TabMenuIcon" TargetType="{x:Type TextBlock}">
<Setter Property="Margin" Value="0,0,12,0" />
<Setter Property="FontSize" Value="16" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="FontFamily" Value="/Resources/#Segoe Fluent Icons" />
<Setter Property="Foreground" Value="{StaticResource Color05B}" />
<Setter Property="Foreground" Value="{DynamicResource Color05B}" />
</Style>
<Style x:Key="SettingSeparatorStyle" TargetType="{x:Type Separator}">
<Setter Property="BorderBrush" Value="{StaticResource Color03B}" />
<Setter Property="BorderBrush" Value="{DynamicResource Color03B}" />
</Style>
<!-- Title Bar -->
@ -53,7 +53,7 @@
</Style>
<Style x:Key="TitleBarButtonStyle" TargetType="Button">
<Setter Property="Foreground" Value="{StaticResource Color05B}" />
<Setter Property="Foreground" Value="{DynamicResource Color05B}" />
<Setter Property="Padding" Value="0" />
<Setter Property="WindowChrome.IsHitTestVisibleInChrome" Value="True" />
<Setter Property="IsTabStop" Value="False" />
@ -62,7 +62,7 @@
<ControlTemplate TargetType="{x:Type Button}">
<Border
x:Name="border"
Background="{StaticResource Color01B}"
Background="{DynamicResource Color01B}"
BorderThickness="0"
SnapsToDevicePixels="true">
<ContentPresenter
@ -75,10 +75,10 @@
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter TargetName="border" Property="Background" Value="{StaticResource Color06B}" />
<Setter TargetName="border" Property="Background" Value="{DynamicResource Color06B}" />
</Trigger>
<Trigger Property="IsPressed" Value="true">
<Setter TargetName="border" Property="Background" Value="{StaticResource Color09B}" />
<Setter TargetName="border" Property="Background" Value="{DynamicResource Color09B}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
@ -87,7 +87,7 @@
</Style>
<Style x:Key="TitleBarCloseButtonStyle" TargetType="Button">
<Setter Property="Foreground" Value="{StaticResource Color05B}" />
<Setter Property="Foreground" Value="{DynamicResource Color05B}" />
<Setter Property="Padding" Value="0" />
<Setter Property="WindowChrome.IsHitTestVisibleInChrome" Value="True" />
<Setter Property="IsTabStop" Value="False" />
@ -109,11 +109,11 @@
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter TargetName="border" Property="Background" Value="{StaticResource Color10B}" />
<Setter TargetName="border" Property="Background" Value="{DynamicResource Color10B}" />
<Setter Property="Foreground" Value="{DynamicResource MouseOverWindowCloseButtonForegroundBrush}" />
</Trigger>
<Trigger Property="IsPressed" Value="true">
<Setter TargetName="border" Property="Background" Value="{StaticResource Color11B}" />
<Setter TargetName="border" Property="Background" Value="{DynamicResource Color11B}" />
<Setter Property="Foreground" Value="{DynamicResource MouseOverWindowCloseButtonForegroundBrush}" />
</Trigger>
</ControlTemplate.Triggers>
@ -1394,16 +1394,16 @@
<ControlTemplate TargetType="Button">
<Border
x:Name="Background"
Background="{StaticResource ButtonBackgroundColor}"
BorderBrush="{StaticResource ButtonOutBorder}"
BorderThickness="{StaticResource CustomButtonOutBorderThickness}"
Background="{DynamicResource ButtonBackgroundColor}"
BorderBrush="{DynamicResource ButtonOutBorder}"
BorderThickness="{DynamicResource CustomButtonOutBorderThickness}"
CornerRadius="4"
SnapsToDevicePixels="True">
<Border
x:Name="Border"
Padding="{TemplateBinding Padding}"
BorderBrush="{StaticResource ButtonInsideBorder}"
BorderThickness="{StaticResource CustomButtonInsideBorderThickness}"
BorderBrush="{DynamicResource ButtonInsideBorder}"
BorderThickness="{DynamicResource CustomButtonInsideBorderThickness}"
CornerRadius="4">
<ContentPresenter
x:Name="ContentPresenter"
@ -1416,27 +1416,27 @@
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="Background" Property="Background" Value="{StaticResource ButtonMouseOver}" />
<Setter TargetName="Background" Property="BorderThickness" Value="{StaticResource CustomButtonOutBorderThickness}" />
<Setter TargetName="Background" Property="BorderBrush" Value="{StaticResource ButtonOutBorder}" />
<Setter TargetName="Border" Property="BorderBrush" Value="{StaticResource ButtonInsideBorder}" />
<Setter TargetName="Border" Property="BorderThickness" Value="{StaticResource CustomButtonInsideBorderThickness}" />
<Setter TargetName="Background" Property="Background" Value="{DynamicResource ButtonMouseOver}" />
<Setter TargetName="Background" Property="BorderThickness" Value="{DynamicResource CustomButtonOutBorderThickness}" />
<Setter TargetName="Background" Property="BorderBrush" Value="{DynamicResource ButtonOutBorder}" />
<Setter TargetName="Border" Property="BorderBrush" Value="{DynamicResource ButtonInsideBorder}" />
<Setter TargetName="Border" Property="BorderThickness" Value="{DynamicResource CustomButtonInsideBorderThickness}" />
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter TargetName="Background" Property="Background" Value="{StaticResource ButtonMousePressed}" />
<Setter TargetName="Background" Property="BorderThickness" Value="{StaticResource PressedCustomButtonOutBorderThickness}" />
<Setter TargetName="Background" Property="BorderBrush" Value="{StaticResource ButtonMousePressedInsideBorder}" />
<Setter TargetName="Border" Property="BorderBrush" Value="{StaticResource ButtonInsideMouseOverBorder}" />
<Setter TargetName="Border" Property="BorderThickness" Value="{StaticResource PressedCustomButtonInsideBorderThickness}" />
<Setter TargetName="ContentPresenter" Property="TextElement.Foreground" Value="{StaticResource ButtonMousePressedText}" />
<Setter TargetName="Background" Property="Background" Value="{DynamicResource ButtonMousePressed}" />
<Setter TargetName="Background" Property="BorderThickness" Value="{DynamicResource PressedCustomButtonOutBorderThickness}" />
<Setter TargetName="Background" Property="BorderBrush" Value="{DynamicResource ButtonMousePressedInsideBorder}" />
<Setter TargetName="Border" Property="BorderBrush" Value="{DynamicResource ButtonInsideMouseOverBorder}" />
<Setter TargetName="Border" Property="BorderThickness" Value="{DynamicResource PressedCustomButtonInsideBorderThickness}" />
<Setter TargetName="ContentPresenter" Property="TextElement.Foreground" Value="{DynamicResource ButtonMousePressedText}" />
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter TargetName="Background" Property="Background" Value="{StaticResource ButtonBackgroundDisabledColor}" />
<Setter TargetName="Background" Property="BorderThickness" Value="{StaticResource DisabledCustomButtonOutBorderThickness}" />
<Setter TargetName="Background" Property="BorderBrush" Value="{StaticResource ButtonOutBorder}" />
<Setter TargetName="Border" Property="BorderBrush" Value="{StaticResource ButtonInsideBorderDisabled}" />
<Setter TargetName="Border" Property="BorderThickness" Value="{StaticResource DisabledCustomButtonInsideBorderThickness}" />
<Setter TargetName="ContentPresenter" Property="TextElement.Foreground" Value="{StaticResource ButtonDisabledText}" />
<Setter TargetName="Background" Property="Background" Value="{DynamicResource ButtonBackgroundDisabledColor}" />
<Setter TargetName="Background" Property="BorderThickness" Value="{DynamicResource DisabledCustomButtonOutBorderThickness}" />
<Setter TargetName="Background" Property="BorderBrush" Value="{DynamicResource ButtonOutBorder}" />
<Setter TargetName="Border" Property="BorderBrush" Value="{DynamicResource ButtonInsideBorderDisabled}" />
<Setter TargetName="Border" Property="BorderThickness" Value="{DynamicResource DisabledCustomButtonInsideBorderThickness}" />
<Setter TargetName="ContentPresenter" Property="TextElement.Foreground" Value="{DynamicResource ButtonDisabledText}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
@ -2606,7 +2606,7 @@
ui:ControlHelper.CornerRadius="4"
Content="{StaticResource ChevronUp}"
FontSize="{TemplateBinding FontSize}"
Style="{StaticResource NumberBoxSpinButtonStyle}"
Style="{DynamicResource NumberBoxSpinButtonStyle}"
Visibility="Collapsed" />
<RepeatButton
@ -2616,7 +2616,7 @@
ui:ControlHelper.CornerRadius="4"
Content="{StaticResource ChevronDown}"
FontSize="{TemplateBinding FontSize}"
Style="{StaticResource NumberBoxSpinButtonStyle}"
Style="{DynamicResource NumberBoxSpinButtonStyle}"
Visibility="Collapsed" />
<ContentPresenter
@ -2679,7 +2679,7 @@
</Trigger>
<!-- SpinButtonsPopup -->
<Trigger Property="SpinButtonPlacementMode" Value="Compact">
<Setter TargetName="InputBox" Property="Style" Value="{StaticResource NumberBoxTextBoxStyle}" />
<Setter TargetName="InputBox" Property="Style" Value="{DynamicResource NumberBoxTextBoxStyle}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>

View file

@ -68,8 +68,8 @@
</Setter>
</Style>
<Style x:Key="SettingGroupBox" TargetType="{x:Type Border}">
<Setter Property="Background" Value="{StaticResource Color00B}" />
<Setter Property="BorderBrush" Value="{StaticResource Color03B}" />
<Setter Property="Background" Value="{DynamicResource Color00B}" />
<Setter Property="BorderBrush" Value="{DynamicResource Color03B}" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="CornerRadius" Value="5" />
<Setter Property="Margin" Value="0,5,0,0" />
@ -78,12 +78,12 @@
</Style>
<Style x:Key="SettingTitleLabel" TargetType="{x:Type TextBlock}">
<Setter Property="Foreground" Value="{StaticResource Color05B}" />
<Setter Property="Foreground" Value="{DynamicResource Color05B}" />
<Setter Property="Margin" Value="0,0,0,0" />
</Style>
<Style x:Key="SettingSubTitleLabel" TargetType="{x:Type TextBlock}">
<Setter Property="Foreground" Value="{StaticResource Color04B}" />
<Setter Property="Foreground" Value="{DynamicResource Color04B}" />
<Setter Property="FontSize" Value="12" />
<Setter Property="Margin" Value="0,0,0,0" />
<Setter Property="Padding" Value="0,0,24,0" />
@ -194,7 +194,7 @@
<Border
x:Name="border"
Height="40"
Background="{StaticResource Color01B}"
Background="{DynamicResource Color01B}"
CornerRadius="5">
<Grid>
<Canvas>
@ -224,10 +224,10 @@
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="border" Property="Background" Value="{StaticResource Color06B}" />
<Setter TargetName="border" Property="Background" Value="{DynamicResource Color06B}" />
</Trigger>
<Trigger Property="IsSelected" Value="True">
<Setter TargetName="border" Property="Background" Value="{StaticResource Color06B}" />
<Setter TargetName="border" Property="Background" Value="{DynamicResource Color06B}" />
<Setter TargetName="Bullet" Property="Visibility" Value="Visible" />
</Trigger>
</ControlTemplate.Triggers>
@ -244,11 +244,11 @@
</Style>
<Style x:Key="PluginList" TargetType="ListBoxItem">
<Setter Property="Background" Value="{StaticResource Color00B}" />
<Setter Property="Background" Value="{DynamicResource Color00B}" />
<Setter Property="Padding" Value="0,12,0,12" />
<Setter Property="Margin" Value="0,0,18,5" />
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="BorderBrush" Value="{StaticResource Color03B}" />
<Setter Property="BorderBrush" Value="{DynamicResource Color03B}" />
<!--#region Template for blue highlight win10-->
<Setter Property="Template">
<Setter.Value>
@ -274,8 +274,8 @@
<MultiTrigger.Conditions>
<Condition Property="IsMouseOver" Value="True" />
</MultiTrigger.Conditions>
<Setter TargetName="Bd" Property="Background" Value="{StaticResource Color07B}" />
<Setter TargetName="Bd" Property="BorderBrush" Value="{StaticResource Color03B}" />
<Setter TargetName="Bd" Property="Background" Value="{DynamicResource Color07B}" />
<Setter TargetName="Bd" Property="BorderBrush" Value="{DynamicResource Color03B}" />
<Setter TargetName="Bd" Property="CornerRadius" Value="5" />
</MultiTrigger>
@ -284,8 +284,8 @@
<Condition Property="Selector.IsSelectionActive" Value="False" />
<Condition Property="IsSelected" Value="True" />
</MultiTrigger.Conditions>
<Setter TargetName="Bd" Property="Background" Value="{StaticResource Color00B}" />
<Setter TargetName="Bd" Property="BorderBrush" Value="{StaticResource Color03B}" />
<Setter TargetName="Bd" Property="Background" Value="{DynamicResource Color00B}" />
<Setter TargetName="Bd" Property="BorderBrush" Value="{DynamicResource Color03B}" />
<Setter TargetName="Bd" Property="Margin" Value="0,0,0,0" />
@ -295,8 +295,8 @@
<Condition Property="Selector.IsSelectionActive" Value="True" />
<Condition Property="IsSelected" Value="True" />
</MultiTrigger.Conditions>
<Setter TargetName="Bd" Property="Background" Value="{StaticResource Color00B}" />
<Setter TargetName="Bd" Property="BorderBrush" Value="{StaticResource Color03B}" />
<Setter TargetName="Bd" Property="Background" Value="{DynamicResource Color00B}" />
<Setter TargetName="Bd" Property="BorderBrush" Value="{DynamicResource Color03B}" />
<Setter TargetName="Bd" Property="CornerRadius" Value="5" />
<Setter TargetName="Bd" Property="Margin" Value="0,0,0,0" />
@ -315,10 +315,10 @@
<!--#region PluginStore Style-->
<Style x:Key="StoreList" TargetType="ListBoxItem">
<Setter Property="Background" Value="{StaticResource Color02B}" />
<Setter Property="Background" Value="{DynamicResource Color02B}" />
<Setter Property="Padding" Value="0,0,0,0" />
<Setter Property="Margin" Value="0,0,8,5" />
<Setter Property="BorderBrush" Value="{StaticResource Color03B}" />
<Setter Property="BorderBrush" Value="{DynamicResource Color03B}" />
<Setter Property="MinWidth" Value="330" />
<Setter Property="Height" Value="98" />
<!--#region Template for blue highlight win10-->
@ -346,8 +346,8 @@
<MultiTrigger.Conditions>
<Condition Property="IsMouseOver" Value="True" />
</MultiTrigger.Conditions>
<Setter TargetName="Bd" Property="Background" Value="{StaticResource Color07B}" />
<Setter TargetName="Bd" Property="BorderBrush" Value="{StaticResource Color03B}" />
<Setter TargetName="Bd" Property="Background" Value="{DynamicResource Color07B}" />
<Setter TargetName="Bd" Property="BorderBrush" Value="{DynamicResource Color03B}" />
<Setter TargetName="Bd" Property="CornerRadius" Value="5" />
</MultiTrigger>
@ -356,8 +356,8 @@
<Condition Property="Selector.IsSelectionActive" Value="False" />
<Condition Property="IsSelected" Value="True" />
</MultiTrigger.Conditions>
<Setter TargetName="Bd" Property="Background" Value="{StaticResource Color02B}" />
<Setter TargetName="Bd" Property="BorderBrush" Value="{StaticResource Color03B}" />
<Setter TargetName="Bd" Property="Background" Value="{DynamicResource Color02B}" />
<Setter TargetName="Bd" Property="BorderBrush" Value="{DynamicResource Color03B}" />
<Setter TargetName="Bd" Property="Margin" Value="0,0,0,0" />
@ -367,8 +367,8 @@
<Condition Property="Selector.IsSelectionActive" Value="True" />
<Condition Property="IsSelected" Value="True" />
</MultiTrigger.Conditions>
<Setter TargetName="Bd" Property="Background" Value="{StaticResource Color02B}" />
<Setter TargetName="Bd" Property="BorderBrush" Value="{StaticResource Color03B}" />
<Setter TargetName="Bd" Property="Background" Value="{DynamicResource Color02B}" />
<Setter TargetName="Bd" Property="BorderBrush" Value="{DynamicResource Color03B}" />
<Setter TargetName="Bd" Property="CornerRadius" Value="5" />
<Setter TargetName="Bd" Property="Margin" Value="0,0,0,0" />
@ -399,7 +399,7 @@
Grid.Column="0"
Margin="0,0,0,0"
Panel.ZIndex="1"
Background="{StaticResource Color01B}"
Background="{DynamicResource Color01B}"
IsItemsHost="True" />
<Border
Grid.Column="1"
@ -415,7 +415,7 @@
</Style>
</Window.Resources>
<Border Style="{StaticResource WindowMainPanelStyle}">
<Grid Background="{StaticResource Color01B}">
<Grid Background="{DynamicResource Color01B}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
@ -439,14 +439,14 @@
Margin="4,0,0,0"
VerticalAlignment="Center"
FontSize="12"
Foreground="{StaticResource Color05B}"
Foreground="{DynamicResource Color05B}"
Text="{DynamicResource flowlauncher_settings}" />
<Button
Grid.Column="2"
Click="OnMinimizeButtonClick"
RenderOptions.EdgeMode="Aliased"
Style="{StaticResource TitleBarButtonStyle}">
Style="{DynamicResource TitleBarButtonStyle}">
<Path
Width="46"
Height="32"
@ -579,7 +579,7 @@
<ScrollViewer
Margin="0,0,0,0"
Background="{StaticResource Color01B}"
Background="{DynamicResource Color01B}"
ScrollViewer.CanContentScroll="False">
<StackPanel Margin="5,18,25,30" Orientation="Vertical">
<TextBlock
@ -892,13 +892,13 @@
Grid.Row="1"
Grid.Column="0"
Padding="0,0,0,0"
Background="{StaticResource Color01B}">
Background="{DynamicResource Color01B}">
<ListBox
Width="Auto"
Margin="5,0,0,0"
Padding="0,0,7,0"
HorizontalAlignment="Stretch"
Background="{StaticResource Color01B}"
Background="{DynamicResource Color01B}"
ItemContainerStyle="{StaticResource PluginList}"
ItemsSource="{Binding PluginViewModels}"
ScrollViewer.CanContentScroll="False"
@ -949,13 +949,13 @@
</StackPanel>
<StackPanel Grid.Column="1" Margin="12,0,14,0">
<TextBlock
Foreground="{StaticResource Color05B}"
Foreground="{DynamicResource Color05B}"
Text="{Binding PluginPair.Metadata.Name}"
TextWrapping="Wrap"
ToolTip="{Binding PluginPair.Metadata.Version}" />
<TextBlock
Margin="0,2,0,0"
Foreground="{StaticResource Color04B}"
Foreground="{DynamicResource Color04B}"
TextWrapping="WrapWithOverflow">
<Run FontSize="12" Text="{Binding PluginPair.Metadata.Description}" />
</TextBlock>
@ -966,7 +966,7 @@
Margin="0,0,8,0"
VerticalAlignment="Center"
FontSize="12"
Foreground="{StaticResource Color08B}"
Foreground="{DynamicResource Color08B}"
Text="{DynamicResource priority}" />
<Border>
<Button
@ -988,10 +988,10 @@
<Setter Property="Padding" Value="12,8,12,8" />
<Setter Property="BorderThickness" Value="0" />
<Setter Property="FontWeight" Value="DemiBold" />
<Setter Property="Foreground" Value="{StaticResource Color05B}" />
<Setter Property="Foreground" Value="{DynamicResource Color05B}" />
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=PriorityButton, UpdateSourceTrigger=PropertyChanged, Path=Content}" Value="0">
<Setter Property="Foreground" Value="{StaticResource Color08B}" />
<Setter Property="Foreground" Value="{DynamicResource Color08B}" />
<Setter Property="FontWeight" Value="Normal" />
</DataTrigger>
</Style.Triggers>
@ -1070,8 +1070,8 @@
Padding="0"
HorizontalAlignment="Stretch"
VerticalAlignment="Center"
Background="{StaticResource Color02B}"
BorderBrush="{StaticResource Color03B}"
Background="{DynamicResource Color02B}"
BorderBrush="{DynamicResource Color03B}"
BorderThickness="0,1,0,0">
<!--#region SubInfo Styling-->
<Border.Style>
@ -1286,7 +1286,7 @@
Padding="0,0,0,0"
HorizontalAlignment="Stretch"
VerticalContentAlignment="Center"
Background="{StaticResource Color01B}"
Background="{DynamicResource Color01B}"
ItemContainerStyle="{StaticResource StoreList}"
ItemsSource="{Binding ExternalPlugins}"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
@ -1375,18 +1375,18 @@
</StackPanel.Style>
<TextBlock
Padding="0,0,20,0"
Foreground="{StaticResource Color05B}"
Foreground="{DynamicResource Color05B}"
Text="{Binding Name}"
TextWrapping="WrapWithOverflow"
ToolTip="{Binding Version}" />
<TextBlock
Margin="0,2,0,0"
Padding="0,0,20,0"
Foreground="{StaticResource Color04B}"
Foreground="{DynamicResource Color04B}"
TextWrapping="WrapWithOverflow">
<Run
FontSize="12"
Foreground="{StaticResource Color04B}"
Foreground="{DynamicResource Color04B}"
Text="{Binding Description}" />
</TextBlock>
@ -1414,7 +1414,7 @@
VerticalAlignment="Stretch"
Panel.ZIndex="1">
<Grid.Background>
<SolidColorBrush Opacity=".95" Color="{StaticResource HoverStoreGrid}" />
<SolidColorBrush Opacity=".95" Color="{DynamicResource HoverStoreGrid}" />
</Grid.Background>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="{Binding ActualWidth, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBoxItem}}}" />
@ -1429,14 +1429,14 @@
Margin="20,0,0,0"
Padding="0,0,0,0"
FontWeight="Bold"
Foreground="{StaticResource Color05B}"
Foreground="{DynamicResource Color05B}"
Text="{Binding Name}"
TextWrapping="WrapWithOverflow"
ToolTip="{Binding Name}" />
<TextBlock
Margin="10,0,0,0"
Padding="0,0,20,0"
Foreground="{StaticResource Color05B}"
Foreground="{DynamicResource Color05B}"
Text="{Binding Version}"
TextWrapping="WrapWithOverflow"
ToolTip="{Binding Version}" />
@ -1444,7 +1444,7 @@
<StackPanel Margin="20,2,120,0" Orientation="Vertical">
<TextBlock Padding="0,0,0,0" TextWrapping="Wrap">
<Hyperlink
Foreground="{StaticResource Color04B}"
Foreground="{DynamicResource Color04B}"
NavigateUri="{Binding Website}"
RequestNavigate="OnRequestNavigate">
<Run FontSize="12" Text="{Binding Author}" />
@ -1601,7 +1601,7 @@
Width="100"
Margin="0,0,8,2"
VerticalAlignment="Center"
Foreground="{StaticResource Color05B}"
Foreground="{DynamicResource Color05B}"
Text="{Binding ElementName=WindowWidthValue, Path=Value, UpdateSourceTrigger=PropertyChanged}"
TextAlignment="Right" />
<Slider
@ -1651,14 +1651,14 @@
<Border
x:Name="Bd"
Padding="{TemplateBinding Padding}"
Background="{StaticResource Color12B}"
BorderBrush="{StaticResource Color03B}"
Background="{DynamicResource Color12B}"
BorderBrush="{DynamicResource Color03B}"
BorderThickness="1,1,1,0"
CornerRadius="4"
SnapsToDevicePixels="true">
<Border
x:Name="Bd2"
BorderBrush="{StaticResource Color14B}"
BorderBrush="{DynamicResource Color14B}"
BorderThickness="0,0,0,2"
CornerRadius="4">
<ContentPresenter
@ -1868,13 +1868,14 @@
<TextBlock Style="{DynamicResource SettingTitleLabel}" Text="{DynamicResource DarkMode}" />
</StackPanel>
<ComboBox
x:Name="DarkModeComboBox"
Grid.Column="2"
MaxWidth="200"
Margin="10,0,18,0"
DisplayMemberPath="Display"
ItemsSource="{Binding LastQueryModes}"
SelectedValue="{Binding Settings.LastQueryMode}"
SelectedValuePath="Value" />
Width="120"
Margin="0,0,18,0"
FontSize="14"
ItemsSource="{Binding DarkMode}"
SelectedItem="{Binding Settings.DarkMode}"
SelectionChanged="DarkModeSelectedIndexChanged" />
<TextBlock Style="{StaticResource Glyph}">
&#xe708;
</TextBlock>
@ -2035,12 +2036,12 @@
Padding="0,12,0,0"
VerticalAlignment="Center"
FontSize="14"
Foreground="{StaticResource Color05B}"
Foreground="{DynamicResource Color05B}"
Text="{DynamicResource customQueryHotkey}" />
<ListView
Grid.Row="4"
Margin="0,0,0,0"
Background="{StaticResource Color02B}"
Background="{DynamicResource Color02B}"
BorderBrush="DarkGray"
BorderThickness="1"
ItemsSource="{Binding Settings.CustomPluginHotkeys}"
@ -2284,14 +2285,14 @@
<Border>
<ScrollViewer
Margin="0,0,0,0"
Background="{StaticResource Color01B}"
Background="{DynamicResource Color01B}"
ScrollViewer.CanContentScroll="False">
<StackPanel Margin="5,14,25,30" Orientation="Vertical">
<TextBlock
Grid.Row="2"
Margin="0,5,0,5"
FontSize="30"
Style="{StaticResource PageTitle}"
Style="{DynamicResource PageTitle}"
Text="{DynamicResource about}"
TextAlignment="left" />
<StackPanel Orientation="Horizontal">

View file

@ -16,6 +16,8 @@ using Flow.Launcher.Helper;
using System.Windows.Controls;
using Flow.Launcher.Core.ExternalPlugins;
using System.Runtime.InteropServices;
using ThemeManager = ModernWpf.ThemeManager;
using ApplicationTheme = ModernWpf.ApplicationTheme;
namespace Flow.Launcher
{
@ -310,6 +312,19 @@ namespace Flow.Launcher
}
}
private void DarkModeSelectedIndexChanged(object sender, EventArgs e)
{
if (settings.DarkMode == "Light")
{
ModernWpf.ThemeManager.Current.ApplicationTheme = ModernWpf.ApplicationTheme.Light;
}
else if (settings.DarkMode == "Dark")
{
ModernWpf.ThemeManager.Current.ApplicationTheme = ModernWpf.ApplicationTheme.Dark;
}
}
/* Custom TitleBar */
private void OnMinimizeButtonClick(object sender, RoutedEventArgs e)
@ -352,101 +367,5 @@ namespace Flow.Launcher
this.RefreshMaximizeRestoreButton();
}
protected override void OnSourceInitialized(EventArgs e)
{
base.OnSourceInitialized(e);
((HwndSource)PresentationSource.FromVisual(this)).AddHook(HookProc);
}
public static IntPtr HookProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
if (msg == WM_GETMINMAXINFO)
{
// We need to tell the system what our size should be when maximized. Otherwise it will cover the whole screen,
// including the task bar.
MINMAXINFO mmi = (MINMAXINFO)Marshal.PtrToStructure(lParam, typeof(MINMAXINFO));
// Adjust the maximized size and position to fit the work area of the correct monitor
IntPtr monitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST);
if (monitor != IntPtr.Zero)
{
MONITORINFO monitorInfo = new MONITORINFO();
monitorInfo.cbSize = Marshal.SizeOf(typeof(MONITORINFO));
GetMonitorInfo(monitor, ref monitorInfo);
RECT rcWorkArea = monitorInfo.rcWork;
RECT rcMonitorArea = monitorInfo.rcMonitor;
mmi.ptMaxPosition.X = Math.Abs(rcWorkArea.Left - rcMonitorArea.Left);
mmi.ptMaxPosition.Y = Math.Abs(rcWorkArea.Top - rcMonitorArea.Top);
mmi.ptMaxSize.X = Math.Abs(rcWorkArea.Right - rcWorkArea.Left);
mmi.ptMaxSize.Y = Math.Abs(rcWorkArea.Bottom - rcWorkArea.Top);
}
Marshal.StructureToPtr(mmi, lParam, true);
}
return IntPtr.Zero;
}
private const int WM_GETMINMAXINFO = 0x0024;
private const uint MONITOR_DEFAULTTONEAREST = 0x00000002;
[DllImport("user32.dll")]
private static extern IntPtr MonitorFromWindow(IntPtr handle, uint flags);
[DllImport("user32.dll")]
private static extern bool GetMonitorInfo(IntPtr hMonitor, ref MONITORINFO lpmi);
[Serializable]
[StructLayout(LayoutKind.Sequential)]
public struct RECT
{
public int Left;
public int Top;
public int Right;
public int Bottom;
public RECT(int left, int top, int right, int bottom)
{
this.Left = left;
this.Top = top;
this.Right = right;
this.Bottom = bottom;
}
}
[StructLayout(LayoutKind.Sequential)]
public struct MONITORINFO
{
public int cbSize;
public RECT rcMonitor;
public RECT rcWork;
public uint dwFlags;
}
[Serializable]
[StructLayout(LayoutKind.Sequential)]
public struct POINT
{
public int X;
public int Y;
public POINT(int x, int y)
{
this.X = x;
this.Y = y;
}
}
[StructLayout(LayoutKind.Sequential)]
public struct MINMAXINFO
{
public POINT ptReserved;
public POINT ptMaxSize;
public POINT ptMaxPosition;
public POINT ptMinTrackSize;
public POINT ptMaxTrackSize;
}
}
}

View file

@ -20,6 +20,7 @@ using Flow.Launcher.Infrastructure.Storage;
using Flow.Launcher.Infrastructure.UserSettings;
using Flow.Launcher.Plugin;
using Flow.Launcher.Plugin.SharedModels;
using ApplicationTheme = ModernWpf.ApplicationTheme;
namespace Flow.Launcher.ViewModel
{
@ -316,6 +317,23 @@ namespace Flow.Launcher.ViewModel
}
}
enum DarkModes
{
System,
Light,
Dark
}
public List<string> DarkMode
{
get
{
var darkModeStrings = new List<string>();
var enumList = Enum.GetValues(typeof(DarkModes)).Cast<DarkModes>().ToList();
enumList.ForEach(x => darkModeStrings.Add(x.ToString()));
return darkModeStrings;
}
}
public double WindowWidthSize
{
get => Settings.WindowSize;
@ -352,6 +370,7 @@ namespace Flow.Launcher.ViewModel
}
}
public ResultsViewModel PreviewResults
{
get