-
Notifications
You must be signed in to change notification settings - Fork 4
/
Utilities.cs
91 lines (81 loc) · 2.45 KB
/
Utilities.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
using Microsoft.UI.Composition.SystemBackdrops;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Media;
using System;
using System.IO;
using System.Threading.Tasks;
using Windows.Storage;
using Windows.Storage.Pickers;
using WinRT.Interop;
namespace Edge.Utilities;
public static class Utilities
{
public static void SetBackdrop(this Window window)
{
if (App.settings["ShowMicaIfEnabled"].GetValue<bool>())
{
if (MicaController.IsSupported())
{
window.SystemBackdrop = new MicaBackdrop();
}
else
{
window.SystemBackdrop = new DesktopAcrylicBackdrop();
}
}
else
{
window.SystemBackdrop = null;
}
}
public static void SetThemeColor(this Window window)
{
string appearance = App.settings["Appearance"].ToString();
if (window.Content is FrameworkElement rootElement)
{
rootElement.RequestedTheme = Enum.Parse<ElementTheme>(appearance);
}
}
public static IntPtr GetWindowHandle(this Window window)
{
return WindowNative.GetWindowHandle(window);
}
public static IntPtr GetWindowHandle(this UIElement element)
{
Window window = App.GetWindowForElement(element);
return window.GetWindowHandle();
}
public static async Task<StorageFile> SaveFile(string suggestFile, IntPtr hwnd)
{
FileInfo fileInfo = new(suggestFile);
FileSavePicker picker = new()
{
SuggestedStartLocation = PickerLocationId.Downloads,
SuggestedFileName = fileInfo.Name,
FileTypeChoices = { { fileInfo.Extension, [fileInfo.Extension] } }
};
InitializeWithWindow.Initialize(picker, hwnd);
return await picker.PickSaveFileAsync();
}
public static string ToGlyph(this string name)
{
return name switch
{
"back" => "\ue72b",
"forward" => "\ue72a",
"reload" => "\ue72c",
"saveAs" => "\ue792",
"print" => "\ue749",
"share" => "\ue72d",
"emoji" => "\ue899",
"undo" => "\ue7a7",
"redo" => "\ue7a6",
"cut" => "\ue8c6",
"copy" => "\ue8c8",
"paste" => "\ue77f",
"openLinkInNewWindow" => "\ue737",
"copyLinkLocation" => "\ue71b",
_ => string.Empty,
};
}
}