refactor(desktop): 页面切换统一走 INavigationService

侧栏原先是在 MainWindow.axaml.cs 里用一个针对 ListBox.SelectedIndex 的 switch
接起来的,直接调 App.Services.GetRequiredService<...> 从 code-behind 赋页面。
NavigationService 存在、已注册,却从没被用过。

后果:首页的深层链接无法改变侧栏选中项;新增一个页面要同时改 view model 和
code-behind;每个页面即使该是单例也会被重新构造。

现在:
- INavigationService 增加 NavigateRoot<T>(),用于"跳到顶层页面"(清空回退栈),
  与已有的 NavigateTo<T>()、GoBack() 并存。
- MainWindowViewModel 订阅 NavigationChanged,把当前 view model 反映射成侧栏
  索引,因此从首页卡片跳转时侧栏高亮会跟着走。
- MainWindow.axaml.cs 基本清空;ListBox 绑索引,导航由 view model 发起。

这个提交里两处对话框服务的新增是给后面页面用的:
- ShowFilesPickerAsync —— 多选,解密页需要
- ShowQrCodeLoginDialogAsync —— 把网易云二维码对话框作为模态窗口承载
- ShowMessageAsync 补进接口。它早已实现、也早已被调用,只是没写进契约。
This commit is contained in:
aL1CesT committed 2026-11-09 04:27:42 +08:00
1 parent 9cda87dbfe
commit 216ea4e0c4
8 files changed
+239 -46

No files matched your search

@@ -3,6 +3,7 @@ using Microsoft.Extensions.DependencyInjection;
using ZonyLrcTools.Common.Infrastructure.DependencyInject;
using ZonyLrcTools.Common.Infrastructure.Logging;
using ZonyLrcTools.Common.Infrastructure.Network;
using ZonyLrcTools.Desktop.Infrastructure.Configuration;
using ZonyLrcTools.Desktop.Infrastructure.Localization;
using ZonyLrcTools.Desktop.ViewModels;
@@ -20,7 +21,10 @@ public static class ServiceCollectionExtensions
services.BeginAutoDependencyInject<IWarpHttpClient>();
// Configure Common services
services.ConfigureConfiguration();
// ConfigureConfiguration() from Common always reads config.yaml from the executable
// folder, which breaks portable installs and read-only install locations. The desktop
// app resolves a writable location first and binds from there instead.
services.ConfigureDesktopConfiguration();
services.ConfigureLocalization();
services.ConfigureToolService();
@@ -39,11 +43,18 @@ public static class ServiceCollectionExtensions
services.AddSingleton<IDialogService, DialogService>();
services.AddSingleton<IThemeService, ThemeService>();
// Stores the NetEase login cookie between launches so the QR dialog is a first-run event.
services.AddSingleton<NetEaseSessionStore>();
// Remembers a manually chosen KuGou database path (machine state, not a user preference).
services.AddSingleton<KugouDatabaseStore>();
// Register ViewModels (Singleton to preserve state across navigation)
services.AddSingleton<MainWindowViewModel>();
services.AddSingleton<HomeViewModel>();
services.AddSingleton<LyricsDownloadViewModel>();
services.AddSingleton<AlbumDownloadViewModel>();
services.AddSingleton<DecryptViewModel>();
services.AddSingleton<SettingsViewModel>();
return services;