XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

HaloPixelToolBox

【WinUI3】基于USB HID通讯的花再音响工具箱

公开
关注 0 Fork 0 Star 0
返回提交历史

XFEstudio/HaloPixelToolBox

新增用户画像 界面全面优化 新增托盘到右下角功能

559c3d0
XFE工作室室长 <mail@xfegzs.com>
提交于

代码差异

12 个文件 +175 -74
Modified HaloPixelToolBox/HaloPixelToolBox/App.xaml.cs +3 -7
@@ -16,6 +16,7 @@ namespace HaloPixelToolBox;
16 16 public partial class App : Application
17 17 {
18 18 public ITrayIconService TrayIconService { get; } = ServiceManager.GetService<ITrayIconService>();
19 public ICloseWindowService CloseWindowService { get; } = ServiceManager.GetService<ICloseWindowService>();
19 20 /// <summary>
20 21 /// 主页窗口
21 22 /// </summary>
@@ -89,18 +90,13 @@ public partial class App : Application
89 90 protected override void OnLaunched(LaunchActivatedEventArgs args)
90 91 {
91 92 TrayIconService.Initilize(DispatcherQueue.GetForCurrentThread());
92 MainWindow.Closed += MainWindow_Closed;
93 CloseWindowService.Initialize(MainWindow);
93 94 MainWindow.Content = new AppShellPage();
95 MainWindow.AppWindow.Resize(new(1900, 1400));
94 96 if (SystemProfile.MinimizeWhenOpen)
95 97 MainWindow.AppWindow.Hide();
96 98 else
97 99 MainWindow.Activate();
98 100 AppThemeHelper.MainWindow = MainWindow;
99 101 }
100
101 private void MainWindow_Closed(object sender, WindowEventArgs args)
102 {
103 Win32Helper.ShowWindow(WindowHelper.GetHwndForCurrentWindow(), Win32Helper.SW_HIDE);
104 args.Handled = true;
105 }
106 102 }
Added HaloPixelToolBox/HaloPixelToolBox/Implements/Services/CloseWindowService.cs +17 -0
@@ -0,0 +1,17 @@
1 using HaloPixelToolBox.Interface.Services;
2 using Windows.Foundation;
3 using XFEExtension.NetCore.WinUIHelper.Implements.Services;
4
5 namespace HaloPixelToolBox.Implements.Services;
6
7 public class CloseWindowService : GlobalServiceBase, ICloseWindowService
8 {
9 Window? window;
10 public event TypedEventHandler<object, WindowEventArgs>? Closed;
11
12 public void Initialize(Window window)
13 {
14 this.window = window;
15 this.window.Closed += (e, s) => Closed?.Invoke(e, s);
16 }
17 }
Added HaloPixelToolBox/HaloPixelToolBox/Interface/Services/ICloseWindowService.cs +10 -0
@@ -0,0 +1,10 @@
1 using Windows.Foundation;
2 using XFEExtension.NetCore.WinUIHelper.Interface.Services;
3
4 namespace HaloPixelToolBox.Interface.Services;
5
6 public interface ICloseWindowService : IGlobalService
7 {
8 event TypedEventHandler<object, WindowEventArgs> Closed;
9 void Initialize(Window window);
10 }
Modified HaloPixelToolBox/HaloPixelToolBox/Profiles/CrossVersionProfiles/SystemProfile.cs +14 -4
@@ -18,15 +18,25 @@ public partial class SystemProfile : XFEProfile
18 18 [ProfileProperty]
19 19 private bool autoStart = false;
20 20 /// <summary>
21 /// 忽略的版本号
21 /// 启动时最小化到托盘
22 22 /// </summary>
23 23 [ProfileProperty]
24 private string ignoreVersion = string.Empty;
24 private bool minimizeWhenOpen = false;
25 25 /// <summary>
26 /// 启动时最小化到托盘
26 /// 关闭时最小化到托盘
27 27 /// </summary>
28 28 [ProfileProperty]
29 private bool minimizeWhenOpen = false;
29 private bool minimizeWhenClose = true;
30 /// <summary>
31 /// 关闭时不再询问
32 /// </summary>
33 [ProfileProperty]
34 private bool neverAskAgainWhenClose = false;
35 /// <summary>
36 /// 忽略的版本号
37 /// </summary>
38 [ProfileProperty]
39 private string ignoreVersion = string.Empty;
30 40
31 41 static partial void SetThemeProperty(ref ElementTheme value) => AppThemeHelper.ChangeTheme(value);
32 42 }
Modified HaloPixelToolBox/HaloPixelToolBox/Styles/Thickness.xaml +2 -2
@@ -24,8 +24,8 @@
24 24 <Thickness x:Key="XXSmallLeftTopRightBottomMargin">4,4,4,4</Thickness>
25 25
26 26 <Thickness x:Key="NavigationViewContentGridBorderThickness">1,1,0,0</Thickness>
27 <CornerRadius x:Key="NavigationViewContentGridCornerRadius">8,0,0,0</CornerRadius>
28 <Thickness x:Key="NavigationViewContentMargin">0,48,0,0</Thickness>
27 <CornerRadius x:Key="NavigationViewContentGridCornerRadius">0,0,0,0</CornerRadius>
28 <Thickness x:Key="NavigationViewContentMargin">0,0,0,0</Thickness>
29 29 <Thickness x:Key="NavigationViewHeaderMargin">56,34,0,0</Thickness>
30 30 <Thickness x:Key="NavigationViewPageContentMargin">56,24,56,0</Thickness>
31 31
Modified HaloPixelToolBox/HaloPixelToolBox/TrayMenuWindow.xaml.cs +0 -2
@@ -1,5 +1,3 @@
1 using Microsoft.UI.Xaml.Media;
2
3 1 namespace HaloPixelToolBox;
4 2
5 3 /// <summary>
Modified HaloPixelToolBox/HaloPixelToolBox/Utilities/Helpers/Win32Helper.cs +16 -0
@@ -1,5 +1,8 @@
1 1 using HaloPixelToolBox.Utilities.Helpers.Win32;
2 using Microsoft.UI.Xaml.Media;
3 using Microsoft.UI.Xaml.Media.Imaging;
2 4 using System.Runtime.InteropServices;
5 using System.Text;
3 6
4 7 namespace HaloPixelToolBox.Utilities.Helpers;
5 8
@@ -28,4 +31,17 @@ public static partial class Win32Helper
28 31 [LibraryImport("user32.dll")]
29 32 [return: MarshalAs(UnmanagedType.Bool)]
30 33 public static partial bool GetWindowRect(IntPtr hWnd, out RECT lpRect);
34
35 [DllImport("shell32.dll", EntryPoint = "#261",
36 CharSet = CharSet.Unicode, PreserveSig = false)]
37 public static extern void GetUserTilePath(string? username, uint whatever, StringBuilder picpath, int maxLength);
38
39 public static string GetUserTilePath(string? username = null)
40 {
41 var sb = new StringBuilder(1000);
42 GetUserTilePath(username, 0x80000000, sb, sb.Capacity);
43 return sb.ToString();
44 }
45
46 public static ImageSource GetUserTile(string? username = null) => new BitmapImage(new Uri(GetUserTilePath(username)));
31 47 }
Modified HaloPixelToolBox/HaloPixelToolBox/ViewModels/AppShellPageViewModel.cs +91 -52
@@ -1,76 +1,115 @@
1 1 using CommunityToolkit.Mvvm.ComponentModel;
2 using HaloPixelToolBox.Interface.Services;
2 3 using HaloPixelToolBox.Profiles.CrossVersionProfiles;
3 4 using HaloPixelToolBox.Utilities.Helpers;
5 using Microsoft.UI.Xaml.Media;
4 6 using Microsoft.UI.Xaml.Navigation;
5 7 using XFEExtension.NetCore.WinUIHelper.Interface.Services;
6 8 using XFEExtension.NetCore.WinUIHelper.Utilities;
7 9
8 namespace HaloPixelToolBox.ViewModels
10 namespace HaloPixelToolBox.ViewModels;
11
12 public partial class AppShellPageViewModel : ViewModelBase
9 13 {
10 public partial class AppShellPageViewModel : ViewModelBase
11 {
12 [ObservableProperty]
13 bool canGoBack;
14 [ObservableProperty]
15 private string upgradeContentText = string.Empty;
14 [ObservableProperty]
15 private int selectedIndex;
16 [ObservableProperty]
17 private bool neverAskAgainWhenClose;
18 [ObservableProperty]
19 private bool canGoBack;
20 [ObservableProperty]
21 private string upgradeContentText = string.Empty;
22 [ObservableProperty]
23 private string userName = Environment.UserName;
24 [ObservableProperty]
25 private ImageSource userTile = Win32Helper.GetUserTile();
26
27 public IDialogService DialogService { get; set; } = ServiceManager.GetService<IDialogService>();
28 public INavigationViewService NavigationViewService { get; set; } = ServiceManager.GetService<INavigationViewService>();
29 public Interface.Services.IPageService PageService { get; } = ServiceManager.GetService<Interface.Services.IPageService>();
30 public IMessageService MessageService { get; set; } = ServiceManager.GetService<IMessageService>();
31 public ILoadingService LoadingService { get; set; } = ServiceManager.GetService<ILoadingService>();
32 public ICloseWindowService? CloseWindowService { get; } = ServiceManager.GetGlobalService<ICloseWindowService>();
16 33
17 public IDialogService DialogService { get; set; } = ServiceManager.GetService<IDialogService>();
18 public INavigationViewService NavigationViewService { get; set; } = ServiceManager.GetService<INavigationViewService>();
19 public Interface.Services.IPageService PageService { get; } = ServiceManager.GetService<Interface.Services.IPageService>();
20 public IMessageService MessageService { get; set; } = ServiceManager.GetService<IMessageService>();
21 public ILoadingService LoadingService { get; set; } = ServiceManager.GetService<ILoadingService>();
34 public AppShellPageViewModel()
35 {
36 NavigationViewService.NavigationService.Navigated += NavigationService_Navigated;
37 PageService.CurrentPageLoaded += CurrentPage_Loaded;
38 if (CloseWindowService is not null)
39 CloseWindowService.Closed += CloseWindowService_Closed;
40 }
22 41
23 public AppShellPageViewModel()
42 private async void CloseWindowService_Closed(object sender, WindowEventArgs args)
43 {
44 args.Handled = true;
45 NeverAskAgainWhenClose = SystemProfile.NeverAskAgainWhenClose;
46 SelectedIndex = SystemProfile.MinimizeWhenClose ? 0 : 1;
47 if (!NeverAskAgainWhenClose)
24 48 {
25 NavigationViewService.NavigationService.Navigated += NavigationService_Navigated;
26 PageService.CurrentPageLoaded += CurrentPage_Loaded;
49 if (await DialogService.ShowDialog("closeDialog") == ContentDialogResult.Primary)
50 {
51 SystemProfile.NeverAskAgainWhenClose = NeverAskAgainWhenClose;
52 SystemProfile.MinimizeWhenClose = SelectedIndex == 0;
53 }
54 else
55 {
56 return;
57 }
27 58 }
59 if (SystemProfile.MinimizeWhenClose)
60 {
61 Win32Helper.ShowWindow(WindowHelper.GetHwndForCurrentWindow(), Win32Helper.SW_HIDE);
62 }
63 else
64 {
65 Environment.Exit(0);
66 }
67 }
28 68
29 private async void CurrentPage_Loaded(object sender, RoutedEventArgs e)
69 private async void CurrentPage_Loaded(object sender, RoutedEventArgs e)
70 {
71 MessageService.ShowMessage("正在检查更新...", "检查更新", InfoBarSeverity.Informational);
72 Console.WriteLine("正在检查更新...");
73 var upgradeInfo = await UpgradeHelper.GetReleaseNotes();
74 if (upgradeInfo.IsLatest)
30 75 {
31 MessageService.ShowMessage("正在检查更新...", "检查更新", InfoBarSeverity.Informational);
32 Console.WriteLine("正在检查更新...");
33 var upgradeInfo = await UpgradeHelper.GetReleaseNotes();
34 if (upgradeInfo.IsLatest)
76 MessageService.ShowMessage("当前已是最新版本", "检查更新", InfoBarSeverity.Success);
77 Console.WriteLine("当前已是最新版本");
78 }
79 else
80 {
81 if (upgradeInfo.LatestVersion == SystemProfile.IgnoreVersion)
35 82 {
36 MessageService.ShowMessage("当前已是最新版本", "检查更新", InfoBarSeverity.Success);
37 Console.WriteLine("当前已是最新版本");
83 MessageService.ShowMessage("当前版本已被忽略", "检查更新", InfoBarSeverity.Informational);
84 Console.WriteLine("当前版本已被忽略");
38 85 }
39 86 else
40 87 {
41 if (upgradeInfo.LatestVersion == SystemProfile.IgnoreVersion)
42 {
43 MessageService.ShowMessage("当前版本已被忽略", "检查更新", InfoBarSeverity.Informational);
44 Console.WriteLine("当前版本已被忽略");
45 }
46 else
88 MessageService.ShowMessage("检测到新版本", "检查更新", InfoBarSeverity.Informational);
89 Console.WriteLine("检测到新版本");
90 Console.WriteLine($"[DEBUG]最新版本: {upgradeInfo.LatestVersion}");
91 Console.WriteLine($"[DEBUG]当前版本: {UpgradeHelper.Version}");
92 Console.WriteLine($"[DEBUG]更新信息:{upgradeInfo.ReleaseNotes}");
93 UpgradeContentText = upgradeInfo.ReleaseNotes;
94 switch (await DialogService.ShowDialog("upgradeDialog"))
47 95 {
48 MessageService.ShowMessage("检测到新版本", "检查更新", InfoBarSeverity.Informational);
49 Console.WriteLine("检测到新版本");
50 Console.WriteLine($"[DEBUG]最新版本: {upgradeInfo.LatestVersion}");
51 Console.WriteLine($"[DEBUG]当前版本: {UpgradeHelper.Version}");
52 Console.WriteLine($"[DEBUG]更新信息:{upgradeInfo.ReleaseNotes}");
53 UpgradeContentText = upgradeInfo.ReleaseNotes;
54 switch (await DialogService.ShowDialog("upgradeDialog"))
55 {
56 case ContentDialogResult.None:
57 Console.WriteLine("用户取消了更新");
58 break;
59 case ContentDialogResult.Primary:
60 Console.WriteLine("用户选择开始更新...");
61 UpgradeHelper.StartUpdate(upgradeInfo.DownloadUrl);
62 break;
63 case ContentDialogResult.Secondary:
64 Console.WriteLine("用户选择忽略当前版本");
65 SystemProfile.IgnoreVersion = upgradeInfo.LatestVersion;
66 break;
67 default:
68 break;
69 }
96 case ContentDialogResult.None:
97 Console.WriteLine("用户取消了更新");
98 break;
99 case ContentDialogResult.Primary:
100 Console.WriteLine("用户选择开始更新...");
101 UpgradeHelper.StartUpdate(upgradeInfo.DownloadUrl);
102 break;
103 case ContentDialogResult.Secondary:
104 Console.WriteLine("用户选择忽略当前版本");
105 SystemProfile.IgnoreVersion = upgradeInfo.LatestVersion;
106 break;
107 default:
108 break;
70 109 }
71 110 }
72 111 }
73
74 private void NavigationService_Navigated(object? sender, NavigationEventArgs e) => CanGoBack = NavigationViewService.NavigationService.CanGoBack;
75 112 }
113
114 private void NavigationService_Navigated(object? sender, NavigationEventArgs e) => CanGoBack = NavigationViewService.NavigationService.CanGoBack;
76 115 }
Modified HaloPixelToolBox/HaloPixelToolBox/Views/AppShellPage.xaml +19 -5
@@ -11,9 +11,19 @@
11 11
12 12 <Grid x:Name="mainGrid">
13 13 <ContentDialog x:Name="upgradeDialog" Title="更新新版本" Content="{x:Bind ViewModel.UpgradeContentText, Mode=OneWay}" PrimaryButtonText="更新" SecondaryButtonText="忽略此版本" CloseButtonText="取消" DefaultButton="Primary"/>
14 <ContentDialog x:Name="closeDialog" Title="退出花再工具箱" PrimaryButtonText="确定" SecondaryButtonText="取消" DefaultButton="Primary">
15 <StackPanel Spacing="10" Orientation="Vertical">
16 <TextBlock Text="确认退出工具箱吗?"/>
17 <RadioButtons SelectedIndex="{x:Bind ViewModel.SelectedIndex, Mode=TwoWay}">
18 <RadioButton Content="最小化到托盘" Tag="MinimizeToTray"/>
19 <RadioButton Content="退出应用" Tag="ExitApp"/>
20 </RadioButtons>
21 <CheckBox Margin="0,20,0,0" Content="记住我的选择,不再询问" IsChecked="{x:Bind ViewModel.NeverAskAgainWhenClose, Mode=TwoWay}"/>
22 </StackPanel>
23 </ContentDialog>
14 24 <Grid x:Name="appTitleBar" Canvas.ZIndex="1" Height="{Binding ElementName=navigationView, Path=CompactPaneLength}" IsHitTestVisible="True" VerticalAlignment="Top">
15 <Image Source="/Assets/icon.png" HorizontalAlignment="Left" Width="16" Height="16"/>
16 <TextBlock Text="HaloPixelToolBox" VerticalAlignment="Center" TextWrapping="NoWrap" Margin="28,0,0,0"/>
25 <Image Source="/Assets/icon.png" HorizontalAlignment="Left" Width="16" Height="16" Margin="10,0,0,0"/>
26 <TextBlock Text="花再音响工具箱" VerticalAlignment="Center" TextWrapping="NoWrap" Margin="38,0,0,0"/>
17 27 </Grid>
18 28 <Grid x:Name="rightPanelGrid" Canvas.ZIndex="2" Margin="0,50,0,0">
19 29 <Grid.TranslationTransition>
@@ -32,17 +42,21 @@
32 42 </StackPanel>
33 43 </Grid>
34 44 </Grid>
35 <NavigationView x:Name="navigationView" IsBackButtonVisible="Visible" Canvas.ZIndex="0" IsBackEnabled="{x:Bind ViewModel.CanGoBack, Mode=OneWay}" IsSettingsVisible="False" DisplayModeChanged="NavigationView_DisplayModeChanged" PaneOpening="NavigationView_PaneOpening" PaneOpened="NavigationView_PaneOpened" PaneClosing="NavigationView_PaneClosing" PaneClosed="NavigationView_PaneClosed">
45 <NavigationView x:Name="navigationView" IsBackButtonVisible="Collapsed" Canvas.ZIndex="0" IsBackEnabled="{x:Bind ViewModel.CanGoBack, Mode=OneWay}" IsSettingsVisible="False" DisplayModeChanged="NavigationView_DisplayModeChanged" PaneOpening="NavigationView_PaneOpening" PaneOpened="NavigationView_PaneOpened" PaneClosing="NavigationView_PaneClosing" PaneClosed="NavigationView_PaneClosed">
36 46 <NavigationView.MenuItems>
37 47 <NavigationViewItem Content="网易云歌词" add:NavigationAddition.NavigateTo="HaloPixelToolBox.Views.CloudMusicLyricsToolPage">
38 48 <NavigationViewItem.Icon>
39 49 <FontIcon Glyph="&#xE8D6;"/>
40 50 </NavigationViewItem.Icon>
41 51 </NavigationViewItem>
42 <!--在此处添加导航栏页面-->
52 <!--在此处添加导航栏页面-->
43 53 </NavigationView.MenuItems>
44
54
45 55 <NavigationView.FooterMenuItems>
56 <StackPanel Orientation="Horizontal" Margin="-4,0,0,0" Spacing="4">
57 <PersonPicture ProfilePicture="{x:Bind ViewModel.UserTile}" Height="25" Width="25" HorizontalAlignment="Center"/>
58 <TextBlock Text="{x:Bind ViewModel.UserName, Mode=OneWay}" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="8,0,0,0"/>
59 </StackPanel>
46 60 <NavigationViewItem Content="设置" add:NavigationAddition.NavigateTo="HaloPixelToolBox.Views.SettingPage">
47 61 <NavigationViewItem.Icon>
48 62 <FontIcon Glyph="&#xE713;"/>
Modified HaloPixelToolBox/HaloPixelToolBox/Views/AppShellPage.xaml.cs +1 -0
@@ -18,6 +18,7 @@ namespace HaloPixelToolBox.Views
18 18 ViewModel.NavigationViewService.Initialize(navigationView, navigationFrame);
19 19 ViewModel.MessageService.Initialize(messageStackPanel, DispatcherQueue);
20 20 ViewModel.DialogService.RegisterDialog(upgradeDialog);
21 ViewModel.DialogService.RegisterDialog(closeDialog);
21 22 ViewModel.PageService.Initialize(this);
22 23 ViewModel.LoadingService.Initialize(loadingGrid, globalLoadingGrid, globalLoadingTextBlock, DispatcherQueue, ViewModel.NavigationViewService.NavigationService);
23 24 ViewModel.NavigationViewService.NavigateTo<CloudMusicLyricsToolPage>();
Modified HaloPixelToolBox/HaloPixelToolBox/Views/CloudMusicLyricsToolPage.xaml +1 -1
@@ -20,7 +20,7 @@
20 20
21 21 <Grid>
22 22 <ScrollView>
23 <StackPanel Orientation="Vertical" Spacing="10">
23 <StackPanel Orientation="Vertical" Spacing="10" Margin="0,0,0,20">
24 24 <TextBlock Text="设备状态" Style="{StaticResource SettingsSectionHeaderTextBlockStyle}"/>
25 25 <Grid RowSpacing="10" ColumnSpacing="5">
26 26 <Grid.ColumnDefinitions>
Modified HaloPixelToolBox/HaloPixelToolBox/Views/SettingPage.xaml +1 -1
@@ -23,7 +23,7 @@
23 23 <Grid>
24 24 <ContentDialog x:Name="cleanCacheContentDialog" Title="清除应用缓存" Content="是否清除应用的所有缓存文件(可以定期清理)" IsPrimaryButtonEnabled="True" IsSecondaryButtonEnabled="True" PrimaryButtonText="确定" SecondaryButtonText="取消" DefaultButton="Primary"/>
25 25 <ScrollView>
26 <StackPanel Orientation="Vertical" Spacing="4">
26 <StackPanel Orientation="Vertical" Spacing="4" Margin="0,0,0,20">
27 27 <TextBlock Text="外观 &amp; 行为" Style="{StaticResource SettingsSectionHeaderTextBlockStyle}"/>
28 28 <controls:SettingsCard Header="色彩模式" Description="软件显示的主题颜色">
29 29 <controls:SettingsCard.HeaderIcon>