Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Launcher] use .net WPF #36215

Merged
merged 29 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
652050b
Initial implementation
mantaionut Nov 26, 2024
52ac97b
Fix fluent style
mantaionut Dec 4, 2024
efcaf86
Fix no endline
mantaionut Dec 4, 2024
3604572
Update expect.txt
crutkas Dec 4, 2024
c44b566
Fix formatting
mantaionut Dec 5, 2024
d8234be
Fix light theme looking bad on Windows 10
mantaionut Dec 5, 2024
e6744dc
fix formatting
mantaionut Dec 5, 2024
63c4e70
test change
mantaionut Dec 5, 2024
9ab827c
Now really fixed W10
mantaionut Dec 5, 2024
c66e432
Add a comment
mantaionut Dec 5, 2024
bd93564
Fix typos
mantaionut Dec 5, 2024
b369aea
Fix spellcheck errors
jaimecbernardo Dec 5, 2024
14007e2
Merge branch 'Launcher_use_net_wpf' of https://github.com/mantaionut/…
jaimecbernardo Dec 5, 2024
61ad561
Fix spellcheck pattern for websites
jaimecbernardo Dec 5, 2024
5f5f434
Change patterns for spellcheck in the right file
jaimecbernardo Dec 5, 2024
76ea8c2
Fix XAML styling
jaimecbernardo Dec 5, 2024
f0a582e
Fix contrast colors on W11
mantaionut Dec 6, 2024
8a564d6
Fix formatting
mantaionut Dec 6, 2024
3f74844
Removed emty line
mantaionut Dec 6, 2024
920db49
Fix formatting
mantaionut Dec 6, 2024
ecb2cba
Added comment to fluentHC file
mantaionut Dec 6, 2024
e5c9070
fix comment
mantaionut Dec 6, 2024
b4cc548
Fix Windows10 again.
mantaionut Dec 6, 2024
bcc7e65
Merge branch 'main' into Launcher_use_net_wpf
jaimecbernardo Dec 9, 2024
717d6cb
W11 fix chaning from high contrast to normal not having correct backg…
mantaionut Dec 9, 2024
d7b7468
W10 Fix high contrast not working after switching from light/dark moed
mantaionut Dec 10, 2024
87c05a7
Address feedback
mantaionut Dec 10, 2024
91c7706
Fix formatting
mantaionut Dec 10, 2024
ecc468a
Second W11 fix chaning from high contrast to normal not having correc…
mantaionut Dec 10, 2024
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
4 changes: 4 additions & 0 deletions .github/actions/spell-check/expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ boxmodel
BPBF
bpmf
bpp
Breadcrumb
Browsable
BROWSEINFO
bsd
Expand Down Expand Up @@ -328,6 +329,7 @@ DEVMODEW
DEVMON
devpkey
DEVSOURCE
DGR
DIIRFLAG
dimm
DISABLEASACTIONKEY
Expand Down Expand Up @@ -1840,3 +1842,5 @@ zonable
zoneset
Zoneszonabletester
zzz


2 changes: 1 addition & 1 deletion .github/actions/spell-check/patterns.txt
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ _mm_(?!dd)\w+

# hit-count: 4 file-count: 4
# microsoft
\b(?:https?://|)(?:(?:(?:blogs|download\.visualstudio|docs|msdn2?|research)\.|)microsoft|blogs\.msdn)\.co(?:m|\.\w\w)/[-_a-zA-Z0-9()=./%]*
\b(?:https?://|)(?:(?:(?:blogs|download\.visualstudio|developer|docs|msdn2?|research)\.|)microsoft|blogs\.msdn)\.co(?:m|\.\w\w)/[-_a-zA-Z0-9()=./%]*

aka\.ms/[a-zA-Z0-9]+

Expand Down
2 changes: 0 additions & 2 deletions src/modules/launcher/PowerLauncher/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ui:ThemesDictionary Theme="Dark" />
<ui:ControlsDictionary />
<ResourceDictionary Source="pack://application:,,,/Styles/Styles.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

// https://github.com/dotnet/wpf/blob/main/src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Fluent/Controls/AnimationFactorToValueConverter.cs
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

#pragma warning disable IDE0130 // Namespace does not match folder structure
namespace Fluent.Controls
#pragma warning restore IDE0130 // Namespace does not match folder structure
{
internal sealed class AnimationFactorToValueConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
if (values[0] is not double completeValue)
{
return 0.0;
}

if (values[1] is not double factor)
{
return 0.0;
}

if (parameter is "negative")
{
factor = -factor;
}

return factor * completeValue;
}

public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

// Copied from https://github.com/dotnet/wpf/blob/main/src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Fluent/Controls/FallbackBrushConverter.cs
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using System.Windows.Data;

using System.Windows.Media;

#pragma warning disable IDE0130 // Namespace does not match folder structure
namespace Fluent.Controls
#pragma warning restore IDE0130 // Namespace does not match folder structure
{
internal sealed class FallbackBrushConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is SolidColorBrush brush)
{
return brush;
}

if (value is Color color)
{
return new SolidColorBrush(color);
}

// We draw red to visibly see an invalid bind in the UI.
return Brushes.Red;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
71 changes: 48 additions & 23 deletions src/modules/launcher/PowerLauncher/Helper/ThemeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,71 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Globalization;
using System.Linq;

using ManagedCommon;
using Microsoft.Win32;
using Wpf.Ui.Appearance;

namespace PowerLauncher.Helper
{
public static class ThemeExtensions
{
public static Theme ToTheme(this ApplicationTheme applicationTheme)
public static Theme GetCurrentTheme()
{
return applicationTheme switch
// Check for high-contrast mode
Theme highContrastTheme = GetHighContrastBaseType();
if (highContrastTheme != Theme.Light)
{
ApplicationTheme.Dark => Theme.Dark,
ApplicationTheme.Light => Theme.Light,
ApplicationTheme.HighContrast => GetHighContrastBaseType(),
_ => Theme.Light,
};
return highContrastTheme;
}

// Check if the system is using dark or light mode
return IsSystemDarkMode() ? Theme.Dark : Theme.Light;
}

private static Theme GetHighContrastBaseType()
private static bool IsSystemDarkMode()
{
string registryKey = @"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes";
string theme = (string)Registry.GetValue(registryKey, "CurrentTheme", string.Empty);
theme = theme.Split('\\').Last().Split('.').First().ToString();
const string registryKey = @"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize";
const string registryValue = "AppsUseLightTheme";

switch (theme)
// Retrieve the registry value, which is a DWORD (0 or 1)
object registryValueObj = Registry.GetValue(registryKey, registryValue, null);
if (registryValueObj != null)
{
case "hc1":
return Theme.HighContrastOne;
case "hc2":
return Theme.HighContrastTwo;
case "hcwhite":
return Theme.HighContrastWhite;
case "hcblack":
return Theme.HighContrastBlack;
default:
return Theme.HighContrastOne;
// 0 = Dark mode, 1 = Light mode
bool isLightMode = Convert.ToBoolean((int)registryValueObj, CultureInfo.InvariantCulture);
return !isLightMode; // Invert because 0 = Dark
}
else
{
// Default to Light theme if the registry key is missing
return false; // Default to dark mode assumption
}
}

public static Theme GetHighContrastBaseType()
{
const string registryKey = @"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes";
const string registryValue = "CurrentTheme";

string themePath = (string)Registry.GetValue(registryKey, registryValue, string.Empty);
if (string.IsNullOrEmpty(themePath))
{
return Theme.Light; // Default to light theme if missing
}

string theme = themePath.Split('\\').Last().Split('.').First().ToLowerInvariant();

return theme switch
{
"hc1" => Theme.HighContrastOne,
"hc2" => Theme.HighContrastTwo,
"hcwhite" => Theme.HighContrastWhite,
"hcblack" => Theme.HighContrastBlack,
_ => Theme.Light,
};
}
}
}
Loading
Loading