From 3fc3935519fbbae040b51de32bed61be21c43136 Mon Sep 17 00:00:00 2001 From: huiyadanli Date: Thu, 8 Feb 2024 15:44:50 +0800 Subject: [PATCH] add start param #152 --- .../Properties/launchSettings.json | 7 +++++++ .../ViewModel/Pages/HomePageViewModel.cs | 20 ++++++++++++++----- {Scripts => Build/Scripts}/package.bat | 0 3 files changed, 22 insertions(+), 5 deletions(-) create mode 100644 BetterGenshinImpact/Properties/launchSettings.json rename {Scripts => Build/Scripts}/package.bat (100%) diff --git a/BetterGenshinImpact/Properties/launchSettings.json b/BetterGenshinImpact/Properties/launchSettings.json new file mode 100644 index 00000000..e6acdf98 --- /dev/null +++ b/BetterGenshinImpact/Properties/launchSettings.json @@ -0,0 +1,7 @@ +{ + "profiles": { + "BetterGenshinImpact": { + "commandName": "Project" + } + } +} \ No newline at end of file diff --git a/BetterGenshinImpact/ViewModel/Pages/HomePageViewModel.cs b/BetterGenshinImpact/ViewModel/Pages/HomePageViewModel.cs index 4b29b600..0fa6b621 100644 --- a/BetterGenshinImpact/ViewModel/Pages/HomePageViewModel.cs +++ b/BetterGenshinImpact/ViewModel/Pages/HomePageViewModel.cs @@ -20,6 +20,7 @@ using Windows.System; using BetterGenshinImpact.Core.Recognition.OCR; using OpenCvSharp; using Wpf.Ui.Controls; +using MessageBox = System.Windows.MessageBox; namespace BetterGenshinImpact.ViewModel.Pages; @@ -33,12 +34,10 @@ public partial class HomePageViewModel : ObservableObject, INavigationAware [ObservableProperty] private Visibility _startButtonVisibility = Visibility.Visible; [ObservableProperty] private Visibility _stopButtonVisibility = Visibility.Collapsed; - [ObservableProperty] - [NotifyCanExecuteChangedFor(nameof(StartTriggerCommand))] + [ObservableProperty] [NotifyCanExecuteChangedFor(nameof(StartTriggerCommand))] private bool _startButtonEnabled = true; - [ObservableProperty] - [NotifyCanExecuteChangedFor(nameof(StopTriggerCommand))] + [ObservableProperty] [NotifyCanExecuteChangedFor(nameof(StopTriggerCommand))] private bool _stopButtonEnabled = true; public AllConfig Config { get; set; } @@ -72,6 +71,15 @@ public partial class HomePageViewModel : ObservableObject, INavigationAware } } }); + + var args = Environment.GetCommandLineArgs(); + if (args.Length > 1) + { + if (args[1].Contains("start")) + { + _ = OnStartTriggerAsync(); + } + } } [RelayCommand] @@ -136,6 +144,7 @@ public partial class HomePageViewModel : ObservableObject, INavigationAware { hWnd = await SystemControl.StartFromLocalAsync(Config.GenshinStartConfig.InstallPath); } + if (hWnd == IntPtr.Zero) { System.Windows.MessageBox.Show("未找到原神窗口,请先启动原神!"); @@ -231,6 +240,7 @@ public partial class HomePageViewModel : ObservableObject, INavigationAware { return; } + Config.GenshinStartConfig.InstallPath = path; } }); @@ -248,4 +258,4 @@ public partial class HomePageViewModel : ObservableObject, INavigationAware } } } -} +} \ No newline at end of file diff --git a/Scripts/package.bat b/Build/Scripts/package.bat similarity index 100% rename from Scripts/package.bat rename to Build/Scripts/package.bat