Revert "1"

This commit is contained in:
DR-lin-eng
2025-03-13 01:24:38 +08:00
committed by GitHub
parent 5a067f16b1
commit 8c6effb192
20 changed files with 158 additions and 119 deletions

View File

@@ -11,6 +11,7 @@ using BetterGenshinImpact.View.Pages;
using BetterGenshinImpact.ViewModel;
using BetterGenshinImpact.ViewModel.Pages;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Serilog;
@@ -21,9 +22,10 @@ using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
using System.Windows;
using BetterGenshinImpact.View.Pages.View;
using BetterGenshinImpact.ViewModel.Pages.OneDragon;
using BetterGenshinImpact.ViewModel.Pages.View;
using Wpf.Ui;
using Wpf.Ui.DependencyInjection;
using Wpf.Ui.Violeta.Controls;
namespace BetterGenshinImpact;
@@ -71,11 +73,10 @@ public partial class App : Application
Log.Logger = loggerConfiguration.CreateLogger();
services.AddLogging(c => c.AddSerilog());
services.AddNavigationViewPageProvider();
// App Host
services.AddHostedService<ApplicationHostService>();
// Page resolver service
services.AddSingleton<INavigationService, NavigationService>();
services.AddSingleton<IPageService, PageService>();
services.AddSingleton<IUpdateService, UpdateService>();
// Service containing navigation, same as INavigationWindow... but without window

View File

@@ -75,10 +75,9 @@
<PackageReference Include="Vanara.PInvoke.NtDll" Version="4.0.2" />
<PackageReference Include="Vanara.PInvoke.SHCore" Version="4.0.2" />
<PackageReference Include="Vanara.PInvoke.User32" Version="4.0.2" />
<PackageReference Include="WPF-UI" Version="4.0.0" />
<PackageReference Include="WPF-UI.DependencyInjection" Version="4.0.0" />
<PackageReference Include="WPF-UI.Tray" Version="4.0.0" />
<PackageReference Include="WPF-UI.Violeta" Version="3.0.5.28" />
<PackageReference Include="WPF-UI" Version="3.0.5" />
<PackageReference Include="WPF-UI.Tray" Version="3.0.5" />
<PackageReference Include="WPF-UI.Violeta" Version="3.0.5.26" />
<PackageReference Include="YoloV8" Version="4.1.7" />
<PackageReference Include="gong-wpf-dragdrop" Version="3.2.1" />
</ItemGroup>

View File

@@ -22,7 +22,6 @@ public class MiningHandler : IActionHandler
e(hold)
e(hold),a(0.2),a(0.2),a(0.2),a(0.2)
e(hold)
a(0.2),a(0.2),a(0.2),a(0.2),a(0.2),a(0.2),a(0.2),a(0.2)
""");
private readonly ScanPickTask _scanPickTask = new();

View File

@@ -91,7 +91,7 @@ namespace LogParse
if (configGroupEntity != null)
{
result = parseBgiLine(@"→ 开始执行(?:地图追踪任务|JS脚本): ""(.+?)""", logstr);
result = parseBgiLine(@"→ 开始执行地图追踪任务: ""(.+?)""", logstr);
if (result.Item1)
{
configTask = new();

View File

@@ -13,10 +13,16 @@ namespace BetterGenshinImpact.Service;
/// <summary>
/// Managed host of the application.
/// </summary>
public class ApplicationHostService(IServiceProvider serviceProvider) : IHostedService
public class ApplicationHostService : IHostedService
{
private readonly IServiceProvider _serviceProvider;
private INavigationWindow? _navigationWindow;
public ApplicationHostService(IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider;
}
/// <summary>
/// Triggered when the application host is ready to start the service.
/// </summary>
@@ -44,10 +50,12 @@ public class ApplicationHostService(IServiceProvider serviceProvider) : IHostedS
if (!Application.Current.Windows.OfType<MainWindow>().Any())
{
_navigationWindow = (serviceProvider.GetService(typeof(INavigationWindow)) as INavigationWindow)!;
_navigationWindow = (
_serviceProvider.GetService(typeof(INavigationWindow)) as INavigationWindow
)!;
_navigationWindow!.ShowWindow();
_ = _navigationWindow.Navigate(typeof(HomePage));
_navigationWindow.Navigate(typeof(HomePage));
}
await Task.CompletedTask;

View File

@@ -1,46 +1,46 @@
// using System;
// using System.Windows;
// using Wpf.Ui;
//
// namespace BetterGenshinImpact.Service;
//
// /// <summary>
// /// Service that provides pages for navigation.
// /// </summary>
// public class PageService : IPageService
// {
// /// <summary>
// /// Service which provides the instances of pages.
// /// </summary>
// private readonly IServiceProvider _serviceProvider;
//
// /// <summary>
// /// Creates new instance and attaches the <see cref="IServiceProvider"/>.
// /// </summary>
// public PageService(IServiceProvider serviceProvider)
// {
// _serviceProvider = serviceProvider;
// }
//
// /// <inheritdoc />
// public T? GetPage<T>() where T : class
// {
// if (!typeof(FrameworkElement).IsAssignableFrom(typeof(T)))
// {
// throw new InvalidOperationException("The page should be a WPF control.");
// }
//
// return (T?)_serviceProvider.GetService(typeof(T));
// }
//
// /// <inheritdoc />
// public FrameworkElement? GetPage(Type pageType)
// {
// if (!typeof(FrameworkElement).IsAssignableFrom(pageType))
// {
// throw new InvalidOperationException("The page should be a WPF control.");
// }
//
// return _serviceProvider.GetService(pageType) as FrameworkElement;
// }
// }
using System;
using System.Windows;
using Wpf.Ui;
namespace BetterGenshinImpact.Service;
/// <summary>
/// Service that provides pages for navigation.
/// </summary>
public class PageService : IPageService
{
/// <summary>
/// Service which provides the instances of pages.
/// </summary>
private readonly IServiceProvider _serviceProvider;
/// <summary>
/// Creates new instance and attaches the <see cref="IServiceProvider"/>.
/// </summary>
public PageService(IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider;
}
/// <inheritdoc />
public T? GetPage<T>() where T : class
{
if (!typeof(FrameworkElement).IsAssignableFrom(typeof(T)))
{
throw new InvalidOperationException("The page should be a WPF control.");
}
return (T?)_serviceProvider.GetService(typeof(T));
}
/// <inheritdoc />
public FrameworkElement? GetPage(Type pageType)
{
if (!typeof(FrameworkElement).IsAssignableFrom(pageType))
{
throw new InvalidOperationException("The page should be a WPF control.");
}
return _serviceProvider.GetService(pageType) as FrameworkElement;
}
}

View File

@@ -177,7 +177,7 @@
<ui:TitleBar.Icon>
<ui:ImageIcon Source="pack://application:,,,/Assets/Images/logo.png" />
</ui:TitleBar.Icon>
<ui:TitleBar.TrailingContent>
<ui:TitleBar.Header>
<StackPanel Orientation="Horizontal" VerticalAlignment="Top">
<ui:Button Width="46"
Height="32"
@@ -197,7 +197,7 @@
Icon="{ui:SymbolIcon CaretDown24}"
ToolTip="最小化到托盘" />
</StackPanel>
</ui:TitleBar.TrailingContent>
</ui:TitleBar.Header>
</ui:TitleBar>
<tray:NotifyIcon Grid.Row="0"

View File

@@ -7,19 +7,18 @@ using System.Windows.Media;
using BetterGenshinImpact.GameTask;
using BetterGenshinImpact.Helpers.Ui;
using Wpf.Ui;
using Wpf.Ui.Abstractions;
using Wpf.Ui.Controls;
using Wpf.Ui.Tray.Controls;
namespace BetterGenshinImpact.View;
public partial class MainWindow : INavigationWindow
public partial class MainWindow : FluentWindow, INavigationWindow
{
private readonly ILogger<MainWindow> _logger = App.GetLogger<MainWindow>();
public MainWindowViewModel ViewModel { get; }
public MainWindow(MainWindowViewModel viewModel, INavigationService navigationService, ISnackbarService snackbarService)
public MainWindow(MainWindowViewModel viewModel, IPageService pageService, INavigationService navigationService, ISnackbarService snackbarService)
{
_logger.LogDebug("主窗体实例化");
DataContext = ViewModel = viewModel;
@@ -27,6 +26,7 @@ public partial class MainWindow : INavigationWindow
InitializeComponent();
this.InitializeDpiAwareness();
SetPageService(pageService);
snackbarService.SetSnackbarPresenter(SnackbarPresenter);
navigationService.SetNavigationControl(RootNavigation);
@@ -62,8 +62,10 @@ public partial class MainWindow : INavigationWindow
throw new NotImplementedException();
}
public void SetPageService(INavigationViewPageProvider navigationViewPageProvider) =>
RootNavigation.SetPageProviderService(navigationViewPageProvider);
public void SetPageService(IPageService pageService)
{
RootNavigation.SetPageService(pageService);
}
public void ShowWindow() => Show();

View File

@@ -27,7 +27,7 @@ using Wpf.Ui.Violeta.Controls;
namespace BetterGenshinImpact.ViewModel.Pages;
public partial class CommonSettingsPageViewModel : ViewModel
public partial class CommonSettingsPageViewModel : ObservableObject, INavigationAware, IViewModel
{
public AllConfig Config { get; set; }
@@ -136,6 +136,14 @@ public partial class CommonSettingsPageViewModel : ViewModel
InitializeCountries();
}
public void OnNavigatedTo()
{
}
public void OnNavigatedFrom()
{
}
[RelayCommand]
public void OnRefreshMaskSettings()
{

View File

@@ -27,7 +27,7 @@ using Wpf.Ui.Controls;
namespace BetterGenshinImpact.ViewModel.Pages;
public partial class HomePageViewModel : ViewModel
public partial class HomePageViewModel : ObservableObject, INavigationAware, IViewModel
{
[ObservableProperty]
private string[] _modeNames = GameCaptureFactory.ModeNames();
@@ -293,6 +293,14 @@ public partial class HomePageViewModel : ViewModel
UIDispatcherHelper.Invoke(() => Start(_hWnd));
}
public void OnNavigatedTo()
{
}
public void OnNavigatedFrom()
{
}
[RelayCommand]
public void OnGoToWikiUrl()
{

View File

@@ -21,7 +21,7 @@ using Wpf.Ui.Violeta.Controls;
namespace BetterGenshinImpact.ViewModel.Pages;
public partial class JsListViewModel : ViewModel
public partial class JsListViewModel : ObservableObject, INavigationAware, IViewModel
{
private readonly ILogger<JsListViewModel> _logger = App.GetLogger<JsListViewModel>();
private readonly string scriptPath = Global.ScriptPath();
@@ -71,11 +71,15 @@ public partial class JsListViewModel : ViewModel
return di.GetDirectories();
}
public override void OnNavigatedTo()
public void OnNavigatedTo()
{
InitScriptListViewData();
}
public void OnNavigatedFrom()
{
}
[RelayCommand]
public void OnOpenScriptsFolder()
{

View File

@@ -18,7 +18,7 @@ using static Vanara.PInvoke.User32;
namespace BetterGenshinImpact.ViewModel.Pages;
public partial class KeyBindingsSettingsPageViewModel : ViewModel
public partial class KeyBindingsSettingsPageViewModel : ObservableObject, INavigationAware, IViewModel
{
private readonly ILogger<KeyBindingsSettingsPageViewModel> _logger;
@@ -30,6 +30,14 @@ public partial class KeyBindingsSettingsPageViewModel : ViewModel
[ObservableProperty]
private ObservableCollection<KeyBindingSettingModel> _keyBindingSettingModels = [];
public void OnNavigatedFrom()
{
}
public void OnNavigatedTo()
{
}
public KeyBindingsSettingsPageViewModel(IConfigService configService, ILogger<KeyBindingsSettingsPageViewModel> logger)
{
_logger = logger;

View File

@@ -22,7 +22,7 @@ using Wpf.Ui.Violeta.Controls;
namespace BetterGenshinImpact.ViewModel.Pages;
public partial class KeyMouseRecordPageViewModel : ViewModel
public partial class KeyMouseRecordPageViewModel : ObservableObject, INavigationAware, IViewModel
{
private readonly ILogger<KeyMouseRecordPageViewModel> _logger = App.GetLogger<KeyMouseRecordPageViewModel>();
private readonly string scriptPath = Global.Absolute(@"User\KeyMouseScript");
@@ -74,11 +74,15 @@ public partial class KeyMouseRecordPageViewModel : ViewModel
return files.Select(file => new FileInfo(file)).ToList();
}
public override void OnNavigatedTo()
public void OnNavigatedTo()
{
InitScriptListViewData();
}
public void OnNavigatedFrom()
{
}
[RelayCommand]
public async Task OnStartRecord()
{

View File

@@ -11,7 +11,7 @@ using Wpf.Ui.Controls;
namespace BetterGenshinImpact.ViewModel.Pages;
public partial class MacroSettingsPageViewModel : ViewModel
public partial class MacroSettingsPageViewModel : ObservableObject, INavigationAware, IViewModel
{
public AllConfig Config { get; set; }
@@ -25,7 +25,15 @@ public partial class MacroSettingsPageViewModel : ViewModel
Config = configService.Get();
_navigationService = navigationService;
}
public void OnNavigatedTo()
{
}
public void OnNavigatedFrom()
{
}
[RelayCommand]
public void OnGoToHotKeyPage()
{

View File

@@ -17,14 +17,17 @@ using System.Threading.Tasks;
using BetterGenshinImpact.Core.Script;
using BetterGenshinImpact.ViewModel.Message;
using CommunityToolkit.Mvvm.Messaging;
using Wpf.Ui.Controls;
using Wpf.Ui.Violeta.Controls;
using System.Windows;
using BetterGenshinImpact.GameTask;
using BetterGenshinImpact.View.Pages.View;
using BetterGenshinImpact.ViewModel.Pages.View;
using Wpf.Ui.Violeta.Win32;
namespace BetterGenshinImpact.ViewModel.Pages;
public partial class MapPathingViewModel : ViewModel
public partial class MapPathingViewModel : ObservableObject, INavigationAware, IViewModel
{
private readonly ILogger<MapPathingViewModel> _logger = App.GetLogger<MapPathingViewModel>();
public static readonly string PathJsonPath = Global.Absolute(@"User\AutoPathing");
@@ -71,11 +74,15 @@ public partial class MapPathingViewModel : ViewModel
}
}
public override void OnNavigatedTo()
public void OnNavigatedTo()
{
InitScriptListViewData();
}
public void OnNavigatedFrom()
{
}
[RelayCommand]
public void OnOpenScriptsFolder()
{

View File

@@ -28,7 +28,7 @@ using Wpf.Ui.Violeta.Controls;
namespace BetterGenshinImpact.ViewModel.Pages;
public partial class OneDragonFlowViewModel : ViewModel
public partial class OneDragonFlowViewModel : ObservableObject, INavigationAware, IViewModel
{
private readonly ILogger<OneDragonFlowViewModel> _logger = App.GetLogger<OneDragonFlowViewModel>();
@@ -97,7 +97,7 @@ public partial class OneDragonFlowViewModel : ViewModel
InitConfigList();
}
public override void OnNavigatedTo()
public void OnNavigatedTo()
{
InitConfigList();
}

View File

@@ -41,7 +41,7 @@ using TextBlock = Wpf.Ui.Controls.TextBlock;
namespace BetterGenshinImpact.ViewModel.Pages;
public partial class ScriptControlViewModel : ViewModel
public partial class ScriptControlViewModel : ObservableObject, INavigationAware, IViewModel
{
private readonly ISnackbarService _snackbarService;
@@ -63,9 +63,12 @@ public partial class ScriptControlViewModel : ViewModel
public readonly string ScriptGroupPath = Global.Absolute(@"User\ScriptGroup");
public readonly string LogPath = Global.Absolute(@"log");
public override void OnNavigatedTo()
public void OnNavigatedFrom()
{
}
public void OnNavigatedTo()
{
ReadScriptGroup();
}

View File

@@ -35,7 +35,7 @@ using Vanara.Extensions;
namespace BetterGenshinImpact.ViewModel.Pages;
public partial class TaskSettingsPageViewModel : ViewModel
public partial class TaskSettingsPageViewModel : ObservableObject, INavigationAware, IViewModel
{
public AllConfig Config { get; set; }
@@ -168,6 +168,14 @@ public partial class TaskSettingsPageViewModel : ViewModel
_autoFightViewModel.OnStrategyDropDownOpened(type);
}
public void OnNavigatedTo()
{
}
public void OnNavigatedFrom()
{
}
[RelayCommand]
public void OnGoToHotKeyPage()
{

View File

@@ -14,7 +14,7 @@ using Wpf.Ui.Controls;
namespace BetterGenshinImpact.ViewModel.Pages;
public partial class TriggerSettingsPageViewModel : ViewModel
public partial class TriggerSettingsPageViewModel : ObservableObject, INavigationAware, IViewModel
{
[ObservableProperty]
private string[] _clickChatOptionNames = ["优先选择第一个选项", "随机选择选项", "优先选择最后一个选项", "不选择选项"];
@@ -51,6 +51,14 @@ public partial class TriggerSettingsPageViewModel : ViewModel
}
}
public void OnNavigatedTo()
{
}
public void OnNavigatedFrom()
{
}
[RelayCommand]
private void OnEditBlacklist()
{

View File

@@ -1,36 +0,0 @@
using System.Threading.Tasks;
using CommunityToolkit.Mvvm.ComponentModel;
using Wpf.Ui.Abstractions.Controls;
namespace BetterGenshinImpact.ViewModel;
public abstract partial class ViewModel : ObservableObject, INavigationAware, IViewModel
{
/// <inheritdoc />
public virtual Task OnNavigatedToAsync()
{
OnNavigatedTo();
return Task.CompletedTask;
}
/// <summary>
/// Handles the event that is fired after the component is navigated to.
/// </summary>
// ReSharper disable once MemberCanBeProtected.Global
public virtual void OnNavigatedTo() { }
/// <inheritdoc />
public virtual Task OnNavigatedFromAsync()
{
OnNavigatedFrom();
return Task.CompletedTask;
}
/// <summary>
/// Handles the event that is fired before the component is navigated from.
/// </summary>
// ReSharper disable once MemberCanBeProtected.Global
public virtual void OnNavigatedFrom() { }
}