Skip to content

Commit c62cb8f

Browse files
committed
背景效果材质改为 ComboBox
1 parent d04037d commit c62cb8f

File tree

6 files changed

+34
-21
lines changed

6 files changed

+34
-21
lines changed

Data/DefaultSettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
22
"Appearance": "Default",
33
"AskDownloadBehavior": false,
4+
"BackgroundEffect": "Mica",
45
"BackgroundImage": "",
56
"SearchEngine": "Bing",
67
"ShowBackground": false,
78
"ShowFlyoutWhenStartDownloading": true,
8-
"ShowMicaIfEnabled": true,
99
"ShowSuggestUri": true,
1010
"SpecificUri": "",
1111
"StartBehavior": 0,

JsonLoad.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Collections.ObjectModel;
44
using System.IO;
@@ -7,15 +7,23 @@
77

88
namespace Edge
99
{
10+
public enum Effect
11+
{
12+
Mica,
13+
MicaAlt,
14+
Acrylic,
15+
None
16+
}
17+
1018
public class Settings
1119
{
1220
public string Appearance { get; set; }
1321
public bool AskDownloadBehavior { get; set; }
22+
public Effect BackgroundEffect { get; set; }
1423
public string BackgroundImage { get; set; }
1524
public string SearchEngine { get; set; }
1625
public bool ShowBackground { get; set; }
1726
public bool ShowFlyoutWhenStartDownloading { get; set; }
18-
public bool ShowMicaIfEnabled { get; set; }
1927
public bool ShowSuggestUri { get; set; }
2028
public string SpecificUri { get; set; }
2129
public int StartBehavior { get; set; }
@@ -30,7 +38,7 @@ public class WebsiteInfo
3038
public Uri Uri { get; set; }
3139
}
3240

33-
[JsonSourceGenerationOptions(WriteIndented = true)]
41+
[JsonSourceGenerationOptions(WriteIndented = true, UseStringEnumConverter = true)]
3442
[JsonSerializable(typeof(Settings))]
3543
[JsonSerializable(typeof(ObservableCollection<WebsiteInfo>))]
3644
[JsonSerializable(typeof(List<WebsiteInfo>))]

MainWindow.xaml.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using System;
66
using System.ComponentModel;
77
using Windows.Foundation;
8-
using Windows.System;
98
using Windows.Win32;
109
using Windows.Win32.Foundation;
1110
using Windows.Win32.UI.Shell;

Settings/AppearanceItem.xaml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,14 @@
4646
</GridView>
4747

4848
<controls:SettingsCard
49-
Header="在浏览器中显示 Windows 11 视觉效果"
50-
Description="向浏览器添加 Mica 效果。此功能取决于你的设备和 Windows 设置。">
51-
<ToggleSwitch Name="showMicaSwitch" Toggled="MicaEffectChanged"/>
49+
Header="背景材质"
50+
Description="Mica 和 MicaAlt 仅 Windows 11 可用">
51+
<ComboBox
52+
x:Name="effectBox"
53+
SelectionChanged="EffectChanged" />
5254
</controls:SettingsCard>
5355

54-
<TextBlock Text="自定义工具栏" Style="{ThemeResource FlyoutPickerTitleTextBlockStyle}" Margin="5,10,0,0"/>
56+
<TextBlock Text="自定义工具栏" Style="{ThemeResource FlyoutPickerTitleTextBlockStyle}" Margin="5,10,0,0" />
5557

5658
<ItemsControl x:Name="toolBarVisualView">
5759
<ItemsControl.ItemTemplate>

Settings/AppearanceItem.xaml.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public sealed partial class AppearanceItem : Page
1818
private static bool inLoading = false;
1919
public List<ToolBarVisual> ToolBarVisualList = [];
2020
public List<string> themeList = [.. Enum.GetNames<ElementTheme>()];
21+
public List<string> effects = [.. Enum.GetNames<Effect>()];
2122
public Dictionary<string, string> ToolBarName = new(){
2223
{"HomeButton", "“开始”按钮"},
2324
{"ForwardButton", "“前进”按钮"},
@@ -34,10 +35,11 @@ public AppearanceItem()
3435
Visual = x.Value
3536
}).ToList();
3637
toolBarVisualView.ItemsSource = ToolBarVisualList;
38+
effectBox.ItemsSource = effects;
3739

3840
inLoading = true;
3941
appearanceView.SelectedIndex = themeList.IndexOf(App.settings.Appearance);
40-
showMicaSwitch.IsOn = App.settings.ShowMicaIfEnabled;
42+
effectBox.SelectedIndex = effects.IndexOf(App.settings.BackgroundEffect.ToString());
4143
inLoading = false;
4244
}
4345

@@ -61,11 +63,11 @@ private void VisualChanged(object sender, RoutedEventArgs e)
6163
App.settings.ToolBar[visual.Text] = (sender as ToggleSwitch).IsOn;
6264
}
6365

64-
private void MicaEffectChanged(object sender, RoutedEventArgs e)
66+
private void EffectChanged(object sender, SelectionChangedEventArgs e)
6567
{
6668
if (!inLoading)
6769
{
68-
App.settings.ShowMicaIfEnabled = (sender as ToggleSwitch).IsOn;
70+
App.settings.BackgroundEffect = Enum.Parse<Effect>((sender as ComboBox).SelectedItem.ToString());
6971

7072
foreach (Window window in App.mainWindows)
7173
{

Utilities.cs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,18 @@ public static class Utilities
2727
{
2828
public static void SetBackdrop(this Window window)
2929
{
30-
if (App.settings.ShowMicaIfEnabled)
30+
Effect effect = App.settings.BackgroundEffect;
31+
if (effect == Effect.Mica && MicaController.IsSupported())
3132
{
32-
if (MicaController.IsSupported())
33-
{
34-
window.SystemBackdrop = new MicaBackdrop();
35-
}
36-
else
37-
{
38-
window.SystemBackdrop = new DesktopAcrylicBackdrop();
39-
}
33+
window.SystemBackdrop = new MicaBackdrop();
34+
}
35+
else if (effect == Effect.MicaAlt && MicaController.IsSupported())
36+
{
37+
window.SystemBackdrop = new MicaBackdrop() { Kind = MicaKind.BaseAlt };
38+
}
39+
else if (effect == Effect.Acrylic)
40+
{
41+
window.SystemBackdrop = new DesktopAcrylicBackdrop();
4042
}
4143
else
4244
{

0 commit comments

Comments
 (0)