From bb83e76d3349e428da5979e1efd93cefee370049 Mon Sep 17 00:00:00 2001 From: Lightczx <1686188646@qq.com> Date: Wed, 3 Jan 2024 16:17:27 +0800 Subject: [PATCH] impl #1241 --- .../Snap.Hutao/Resource/Localization/SH.resx | 8 ++- src/Snap.Hutao/Snap.Hutao/Snap.Hutao.csproj | 6 +++ .../View/Dialog/ReconfirmDialog.xaml | 21 ++++++++ .../View/Dialog/ReconfirmDialog.xaml.cs | 35 +++++++++++++ .../Snap.Hutao/View/Page/SettingPage.xaml | 6 +-- .../ViewModel/Setting/SettingViewModel.cs | 49 ++++++++++++++++++- 6 files changed, 118 insertions(+), 7 deletions(-) create mode 100644 src/Snap.Hutao/Snap.Hutao/View/Dialog/ReconfirmDialog.xaml create mode 100644 src/Snap.Hutao/Snap.Hutao/View/Dialog/ReconfirmDialog.xaml.cs diff --git a/src/Snap.Hutao/Snap.Hutao/Resource/Localization/SH.resx b/src/Snap.Hutao/Snap.Hutao/Resource/Localization/SH.resx index 490dff8e86..e1b60ce8c7 100644 --- a/src/Snap.Hutao/Snap.Hutao/Resource/Localization/SH.resx +++ b/src/Snap.Hutao/Snap.Hutao/Resource/Localization/SH.resx @@ -1271,6 +1271,12 @@ 使用米游社扫描二维码 + + 请输入你正在启用的功能标题 + + + 你正在启用一个危险功能 + 该操作是不可逆的,所有用户登录状态会丢失 @@ -2415,7 +2421,7 @@ 在完整阅读原神和胡桃工具箱用户协议后,我选择启用「启动游戏-高级功能」 - 启动高级功能 + 启用高级功能 更改自动连点功能的快捷键 diff --git a/src/Snap.Hutao/Snap.Hutao/Snap.Hutao.csproj b/src/Snap.Hutao/Snap.Hutao/Snap.Hutao.csproj index d22d2b0465..1ec8349061 100644 --- a/src/Snap.Hutao/Snap.Hutao/Snap.Hutao.csproj +++ b/src/Snap.Hutao/Snap.Hutao/Snap.Hutao.csproj @@ -173,6 +173,7 @@ + @@ -343,6 +344,11 @@ + + + MSBuild:Compile + + MSBuild:Compile diff --git a/src/Snap.Hutao/Snap.Hutao/View/Dialog/ReconfirmDialog.xaml b/src/Snap.Hutao/Snap.Hutao/View/Dialog/ReconfirmDialog.xaml new file mode 100644 index 0000000000..a8b72cad1e --- /dev/null +++ b/src/Snap.Hutao/Snap.Hutao/View/Dialog/ReconfirmDialog.xaml @@ -0,0 +1,21 @@ + + + + diff --git a/src/Snap.Hutao/Snap.Hutao/View/Dialog/ReconfirmDialog.xaml.cs b/src/Snap.Hutao/Snap.Hutao/View/Dialog/ReconfirmDialog.xaml.cs new file mode 100644 index 0000000000..1873c7880e --- /dev/null +++ b/src/Snap.Hutao/Snap.Hutao/View/Dialog/ReconfirmDialog.xaml.cs @@ -0,0 +1,35 @@ +// Copyright (c) DGP Studio. All rights reserved. +// Licensed under the MIT license. + +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Controls; + +namespace Snap.Hutao.View.Dialog; + +[DependencyProperty("Text", typeof(string), default(string), nameof(OnTextChanged))] +internal sealed partial class ReconfirmDialog : ContentDialog +{ + private readonly ITaskContext taskContext; + + public ReconfirmDialog(IServiceProvider serviceProvider) + { + InitializeComponent(); + + taskContext = serviceProvider.GetRequiredService(); + } + + public string ConfirmText { get; private set; } = default!; + + public async ValueTask ConfirmAsync(string confirmText) + { + await taskContext.SwitchToMainThreadAsync(); + ConfirmText = confirmText; + return await ShowAsync() is ContentDialogResult.Primary; + } + + private static void OnTextChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args) + { + ReconfirmDialog dialog = (ReconfirmDialog)sender; + dialog.IsPrimaryButtonEnabled = string.Equals(dialog.Text, dialog.ConfirmText, StringComparison.Ordinal); + } +} diff --git a/src/Snap.Hutao/Snap.Hutao/View/Page/SettingPage.xaml b/src/Snap.Hutao/Snap.Hutao/View/Page/SettingPage.xaml index 45ee5eb859..5abc8c26e6 100644 --- a/src/Snap.Hutao/Snap.Hutao/View/Page/SettingPage.xaml +++ b/src/Snap.Hutao/Snap.Hutao/View/Page/SettingPage.xaml @@ -376,7 +376,6 @@ IsClickEnabled="True"/> - - - + - + \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/ViewModel/Setting/SettingViewModel.cs b/src/Snap.Hutao/Snap.Hutao/ViewModel/Setting/SettingViewModel.cs index c6a183afab..b67c34ea74 100644 --- a/src/Snap.Hutao/Snap.Hutao/ViewModel/Setting/SettingViewModel.cs +++ b/src/Snap.Hutao/Snap.Hutao/ViewModel/Setting/SettingViewModel.cs @@ -122,11 +122,56 @@ public NameValue? SelectedRegion public IPInformation? IPInformation { get => ipInformation; private set => SetProperty(ref ipInformation, value); } - [SuppressMessage("", "CA1822")] public bool IsAllocConsoleDebugModeEnabled { get => LocalSetting.Get(SettingKeys.IsAllocConsoleDebugModeEnabled, false); - set => LocalSetting.Set(SettingKeys.IsAllocConsoleDebugModeEnabled, value); + set + { + ConfirmSetIsAllocConsoleDebugModeEnabledAsync(value).SafeForget(); + + async ValueTask ConfirmSetIsAllocConsoleDebugModeEnabledAsync(bool value) + { + if (value) + { + ReconfirmDialog dialog = await contentDialogFactory.CreateInstanceAsync().ConfigureAwait(false); + if (await dialog.ConfirmAsync(SH.ViewSettingAllocConsoleHeader).ConfigureAwait(true)) + { + LocalSetting.Set(SettingKeys.IsAllocConsoleDebugModeEnabled, true); + OnPropertyChanged(nameof(IsAllocConsoleDebugModeEnabled)); + return; + } + } + + LocalSetting.Set(SettingKeys.IsAllocConsoleDebugModeEnabled, false); + OnPropertyChanged(nameof(IsAllocConsoleDebugModeEnabled)); + } + } + } + + public bool IsAdvancedLaunchOptionsEnabled + { + get => launchOptions.IsAdvancedLaunchOptionsEnabled; + set + { + ConfirmSetIsAdvancedLaunchOptionsEnabledAsync(value).SafeForget(); + + async ValueTask ConfirmSetIsAdvancedLaunchOptionsEnabledAsync(bool value) + { + if (value) + { + ReconfirmDialog dialog = await contentDialogFactory.CreateInstanceAsync().ConfigureAwait(false); + if (await dialog.ConfirmAsync(SH.ViewPageSettingIsAdvancedLaunchOptionsEnabledHeader).ConfigureAwait(true)) + { + launchOptions.IsAdvancedLaunchOptionsEnabled = true; + OnPropertyChanged(nameof(IsAllocConsoleDebugModeEnabled)); + return; + } + } + + launchOptions.IsAdvancedLaunchOptionsEnabled = false; + OnPropertyChanged(nameof(IsAllocConsoleDebugModeEnabled)); + } + } } protected override async ValueTask InitializeUIAsync()