diff --git a/App.xaml.cs b/App.xaml.cs index 962e65a..ae34f75 100644 --- a/App.xaml.cs +++ b/App.xaml.cs @@ -17,7 +17,7 @@ public partial class App : Application { public static List mainWindows = []; public static Settings settings; - public static WebView2 webView2 = new(); + public static WebView2 WebView2 = new(); public static ObservableCollection Histories = []; public static ObservableCollection DownloadList = []; public static WordSearchEngine searchEngine; @@ -31,7 +31,7 @@ public App() public async void EnsureWebView2Async() { - await webView2.EnsureCoreWebView2Async(); + await WebView2.EnsureCoreWebView2Async(); } public static MainWindow CreateNewWindow() diff --git a/Edge.csproj b/Edge.csproj index 30a478e..9b13dec 100644 --- a/Edge.csproj +++ b/Edge.csproj @@ -31,6 +31,7 @@ + diff --git a/MainWindow.xaml b/MainWindow.xaml index 70d9ed3..e62f36b 100644 --- a/MainWindow.xaml +++ b/MainWindow.xaml @@ -168,6 +168,16 @@ + + + + + + + + diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs index a8b5819..d432ab2 100644 --- a/MainWindow.xaml.cs +++ b/MainWindow.xaml.cs @@ -322,5 +322,11 @@ private void TabViewPointerPressed(object sender, Microsoft.UI.Xaml.Input.Pointe } } } + + private void OpenBrowserTaskManager(object sender, RoutedEventArgs e) + { + TaskManager taskManager = new(); + taskManager.Activate(); + } } } diff --git a/Pages/TaskManager.xaml b/Pages/TaskManager.xaml new file mode 100644 index 0000000..b15ad44 --- /dev/null +++ b/Pages/TaskManager.xaml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pages/TaskManager.xaml.cs b/Pages/TaskManager.xaml.cs new file mode 100644 index 0000000..00abbd1 --- /dev/null +++ b/Pages/TaskManager.xaml.cs @@ -0,0 +1,99 @@ +using CommunityToolkit.WinUI.UI.Controls; +using Microsoft.UI.Xaml; +using Microsoft.Web.WebView2.Core; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Diagnostics; +using System.Linq; + + +namespace Edge +{ + public class ProcessInfo + { + public string Task { get; set; } + public long Memory { get; set; } + public string MemoryKB { get; set; } + public int ProcessId { get; set; } + } + + public sealed partial class TaskManager : Window + { + public ObservableCollection infos = []; + + public TaskManager() + { + this.InitializeComponent(); + ExtendsContentIntoTitleBar = true; + AppWindow.SetIcon("./Assets/icon.ico"); + SetTitleBar(TitleBar); + AppWindow.TitleBar.PreferredHeightOption = Microsoft.UI.Windowing.TitleBarHeightOption.Tall; + + this.SetBackdrop(); + this.SetThemeColor(); + + InitialData(); + } + + private async void InitialData() + { + IReadOnlyList eInfos = await App.WebView2.CoreWebView2.Environment.GetProcessExtendedInfosAsync(); + foreach (CoreWebView2ProcessExtendedInfo item in eInfos) + { + ProcessInfo info = new() + { + Task = item.ProcessInfo.Kind switch + { + CoreWebView2ProcessKind.Browser => "浏览器", + CoreWebView2ProcessKind.Renderer => item.AssociatedFrameInfos[0].Source, + CoreWebView2ProcessKind.Utility => "实用工具", + CoreWebView2ProcessKind.Gpu => "GPU 进程", + _ => "未知" + }, + ProcessId = item.ProcessInfo.ProcessId + }; + + Process process = Process.GetProcessById(item.ProcessInfo.ProcessId); + info.Memory = process.PrivateMemorySize64 / 1024; + info.MemoryKB = $"{info.Memory} KB"; + infos.Add(info); + } + } + + private void DataGrid_Sorting(object sender, DataGridColumnEventArgs e) + { + DataGrid dataGrid = sender as DataGrid; + foreach (var column in dataGrid.Columns) + { + if (column != e.Column) + { + column.SortDirection = null; + } + } + + if (e.Column.SortDirection == DataGridSortDirection.Ascending) + { + e.Column.SortDirection = DataGridSortDirection.Descending; + dataGrid.ItemsSource = (string)e.Column.Tag switch + { + "Task" => infos.OrderByDescending(x => x.Task), + "Memory" => infos.OrderByDescending(x => x.Memory), + "ProcessId" => infos.OrderByDescending(x => x.ProcessId), + _ => infos + }; + } + else + { + e.Column.SortDirection = DataGridSortDirection.Ascending; + dataGrid.ItemsSource = (string)e.Column.Tag switch + { + "Task" => infos.OrderBy(x => x.Task), + "Memory" => infos.OrderBy(x => x.Memory), + "ProcessId" => infos.OrderBy(x => x.ProcessId), + _ => infos + }; + } + } + } +} diff --git a/Settings/DownloadItem.xaml.cs b/Settings/DownloadItem.xaml.cs index 210080b..3f90aeb 100644 --- a/Settings/DownloadItem.xaml.cs +++ b/Settings/DownloadItem.xaml.cs @@ -10,7 +10,7 @@ public DownloadItem() { this.InitializeComponent(); - DownloadFolderCard.Description = App.webView2.CoreWebView2.Profile.DefaultDownloadFolderPath; + DownloadFolderCard.Description = App.WebView2.CoreWebView2.Profile.DefaultDownloadFolderPath; setDownloadBehavior.IsOn = App.settings.AskDownloadBehavior; setDownloadFlyout.IsOn = App.settings.ShowFlyoutWhenStartDownloading; @@ -41,7 +41,7 @@ private async void ChangeDownloadFolder(object sender, Microsoft.UI.Xaml.RoutedE if (folder != null) { - DownloadFolderCard.Description = App.webView2.CoreWebView2.Profile.DefaultDownloadFolderPath = folder.Name; + DownloadFolderCard.Description = App.WebView2.CoreWebView2.Profile.DefaultDownloadFolderPath = folder.Name; } } } diff --git a/Settings/PrivacyItem.xaml.cs b/Settings/PrivacyItem.xaml.cs index 859041c..07006ab 100644 --- a/Settings/PrivacyItem.xaml.cs +++ b/Settings/PrivacyItem.xaml.cs @@ -46,7 +46,7 @@ public PrivacyItem() this.InitializeComponent(); trackView.ItemsSource = TrackKindList; - var level = App.webView2.CoreWebView2.Profile.PreferredTrackingPreventionLevel; + var level = App.WebView2.CoreWebView2.Profile.PreferredTrackingPreventionLevel; bool isTrackOn = level != CoreWebView2TrackingPreventionLevel.None; if (isTrackOn) { @@ -58,7 +58,7 @@ public PrivacyItem() } trackSwitch.IsOn = isTrackOn; - msSmartScreen.IsOn = App.webView2.CoreWebView2.Settings.IsReputationCheckingRequired; + msSmartScreen.IsOn = App.WebView2.CoreWebView2.Settings.IsReputationCheckingRequired; } private async void ClearBrowsingData(object sender, RoutedEventArgs e) @@ -67,7 +67,7 @@ private async void ClearBrowsingData(object sender, RoutedEventArgs e) { if (item.IsChecked) { - await App.webView2.CoreWebView2.Profile.ClearBrowsingDataAsync(item.Kind); + await App.WebView2.CoreWebView2.Profile.ClearBrowsingDataAsync(item.Kind); } } ClearBrowsingDataButton.Description = "已清理选择的项目"; @@ -77,11 +77,11 @@ private void TrackLevelToggled(object sender, RoutedEventArgs e) { if ((sender as ToggleSwitch).IsOn) { - App.webView2.CoreWebView2.Profile.PreferredTrackingPreventionLevel = trackLevelList[trackView.SelectedIndex + 1]; + App.WebView2.CoreWebView2.Profile.PreferredTrackingPreventionLevel = trackLevelList[trackView.SelectedIndex + 1]; } else { - App.webView2.CoreWebView2.Profile.PreferredTrackingPreventionLevel = CoreWebView2TrackingPreventionLevel.None; + App.WebView2.CoreWebView2.Profile.PreferredTrackingPreventionLevel = CoreWebView2TrackingPreventionLevel.None; } } @@ -89,13 +89,13 @@ private void TrackChanged(object sender, SelectionChangedEventArgs e) { if (trackSwitch.IsOn) { - App.webView2.CoreWebView2.Profile.PreferredTrackingPreventionLevel = trackLevelList[trackView.SelectedIndex + 1]; + App.WebView2.CoreWebView2.Profile.PreferredTrackingPreventionLevel = trackLevelList[trackView.SelectedIndex + 1]; } } private void SmartScreenChanged(object sender, RoutedEventArgs e) { - App.webView2.CoreWebView2.Settings.IsReputationCheckingRequired = (sender as ToggleSwitch).IsOn; + App.WebView2.CoreWebView2.Settings.IsReputationCheckingRequired = (sender as ToggleSwitch).IsOn; } } }