perf: 账号切换增加是否启用勾选框 (#17280)

* perf: 账号切换增加是否启用勾选框

* rft: 改用 OnDeserialized 处理迁移
This commit is contained in:
uye
2026-07-06 21:04:24 +08:00
committed by GitHub
parent f859c21d1e
commit 7e61c2eaba
3 changed files with 48 additions and 31 deletions

View File

@@ -11,13 +11,25 @@
// but WITHOUT ANY WARRANTY
// </copyright>
#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;
/// <summary>
/// Gets or sets a value indicating whether 启用账号切换。null 表示尚未迁移的旧配置,迁移后不再为 null。
/// </summary>
public bool? AccountSwitchEnabled { get; set; }
public void OnDeserialized()
{
// v6.14.0-b2 新增一次性配置迁移旧配置没有这个字段json 中不存在,反序列化后为 null此时按是否已有账号名决定初始值
AccountSwitchEnabled ??= !string.IsNullOrEmpty(AccountName);
}
}

View File

@@ -46,6 +46,12 @@ public class StartUpSettingsUserControlModel : TaskSettingsViewModel, StartUpSet
}
}
public bool AccountSwitchEnabled
{
get => GetTaskConfig<StartUpTask>().AccountSwitchEnabled ?? false;
set => SetTaskConfig<StartUpTask>(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;

View File

@@ -20,39 +20,37 @@
mc:Ignorable="d">
<StackPanel>
<StackPanel Visibility="{c:Binding !UseAttachWindow, Source={x:Static settings_vms:ConnectSettingsUserControlModel.Instance}}">
<Grid Margin="0,5" Visibility="{c:Binding 'ClientType == &quot;Official&quot; or ClientType == &quot;Bilibili&quot; or ClientType == &quot;txwy&quot;', Source={x:Static settings_vms:GameSettingsUserControlModel.Instance}}">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<StackPanel Visibility="{c:Binding 'ClientType == &quot;Official&quot; or ClientType == &quot;Bilibili&quot; or ClientType == &quot;txwy&quot;', Source={x:Static settings_vms:GameSettingsUserControlModel.Instance}}">
<StackPanel
Margin="0,5"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Orientation="Horizontal">
<TextBlock
Margin="8,0,0,0"
Text="{DynamicResource AccountSwitch}"
Visibility="Hidden" />
<controls:TooltipBlock Margin="0,0,5,0" TooltipText="{DynamicResource AccountSwitchTip}" />
<CheckBox Content="{DynamicResource AccountSwitch}" IsChecked="{Binding AccountSwitchEnabled}" />
<controls:TooltipBlock TooltipText="{DynamicResource AccountSwitchTip}" />
</StackPanel>
<hc:TextBox
Grid.Column="0"
hc:BorderElement.CornerRadius="4,0,0,4"
hc:TitleElement.Title="{DynamicResource AccountSwitch}"
IsReadOnly="{c:Binding !Idle,
Source={x:Static helper:Instances.SettingsViewModel}}"
Text="{Binding AccountName, UpdateSourceTrigger=PropertyChanged}" />
<Button
Grid.Column="1"
Padding="12,1,12,1"
HorizontalAlignment="Center"
VerticalAlignment="Bottom"
hc:BorderElement.CornerRadius="0,4,4,0"
BorderThickness="0,1,1,1"
Command="{s:Action AccountSwitchManualRun}"
Content="{DynamicResource AccountSwitchManualRun}"
IsEnabled="{c:Binding 'AccountName != &quot;&quot;'}" />
</Grid>
<Grid Margin="0,5" Visibility="{c:Binding AccountSwitchEnabled}">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBox
Grid.Column="0"
hc:BorderElement.CornerRadius="4,0,0,4"
IsReadOnly="{c:Binding !Idle,
Source={x:Static helper:Instances.SettingsViewModel}}"
Text="{Binding AccountName, UpdateSourceTrigger=PropertyChanged}" />
<Button
Grid.Column="1"
Padding="12,1,12,1"
HorizontalAlignment="Center"
VerticalAlignment="Bottom"
hc:BorderElement.CornerRadius="0,4,4,0"
BorderThickness="0,1,1,1"
Command="{s:Action AccountSwitchManualRun}"
Content="{DynamicResource AccountSwitchManualRun}"
IsEnabled="{c:Binding 'AccountName != &quot;&quot;'}" />
</Grid>
</StackPanel>
<controls:TextBlock
Margin="0,5"