diff --git a/src/MaaWpfGui/Configuration/Single/MaaTask/StartUpTask.cs b/src/MaaWpfGui/Configuration/Single/MaaTask/StartUpTask.cs index 11394e9a66..9365932d66 100644 --- a/src/MaaWpfGui/Configuration/Single/MaaTask/StartUpTask.cs +++ b/src/MaaWpfGui/Configuration/Single/MaaTask/StartUpTask.cs @@ -11,13 +11,25 @@ // but WITHOUT ANY WARRANTY // #nullable enable +using System.Text.Json.Serialization; using static MaaWpfGui.Main.AsstProxy; namespace MaaWpfGui.Configuration.Single.MaaTask; -public class StartUpTask : BaseTask +public class StartUpTask : BaseTask, IJsonOnDeserialized { public StartUpTask() => TaskType = TaskType.StartUp; public string AccountName { get; set; } = string.Empty; + + /// + /// Gets or sets a value indicating whether 启用账号切换。null 表示尚未迁移的旧配置,迁移后不再为 null。 + /// + public bool? AccountSwitchEnabled { get; set; } + + public void OnDeserialized() + { + // v6.14.0-b2 新增一次性配置迁移:旧配置没有这个字段(json 中不存在,反序列化后为 null),此时按是否已有账号名决定初始值 + AccountSwitchEnabled ??= !string.IsNullOrEmpty(AccountName); + } } diff --git a/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/StartUpSettingsUserControlModel.cs b/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/StartUpSettingsUserControlModel.cs index 61abc56758..78322ba967 100644 --- a/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/StartUpSettingsUserControlModel.cs +++ b/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/StartUpSettingsUserControlModel.cs @@ -46,6 +46,12 @@ public class StartUpSettingsUserControlModel : TaskSettingsViewModel, StartUpSet } } + public bool AccountSwitchEnabled + { + get => GetTaskConfig().AccountSwitchEnabled ?? false; + set => SetTaskConfig(t => t.AccountSwitchEnabled == value, t => t.AccountSwitchEnabled = value); + } + // UI 绑定的方法 [UsedImplicitly] public async void AccountSwitchManualRun() @@ -88,7 +94,8 @@ public class StartUpSettingsUserControlModel : TaskSettingsViewModel, StartUpSet var clientType = SettingsViewModel.GameSettings.ClientType; var accountName = !SettingsViewModel.ConnectSettings.UseAttachWindow && - clientType is ClientType.Official or ClientType.Bilibili or ClientType.Txwy + clientType is ClientType.Official or ClientType.Bilibili or ClientType.Txwy && + startUp.AccountSwitchEnabled is true ? startUp.AccountName : string.Empty; diff --git a/src/MaaWpfGui/Views/UserControl/TaskQueue/StartUpTaskUserControl.xaml b/src/MaaWpfGui/Views/UserControl/TaskQueue/StartUpTaskUserControl.xaml index 48ddabb605..0f037a06c9 100644 --- a/src/MaaWpfGui/Views/UserControl/TaskQueue/StartUpTaskUserControl.xaml +++ b/src/MaaWpfGui/Views/UserControl/TaskQueue/StartUpTaskUserControl.xaml @@ -20,39 +20,37 @@ mc:Ignorable="d"> - - - - - + - - + + - -