From a80d7bbc03e4d9d68d64c1b6ab2cb1e142fedb31 Mon Sep 17 00:00:00 2001
From: status102 <102887808+status102@users.noreply.github.com>
Date: Tue, 4 Mar 2025 11:53:57 +0800
Subject: [PATCH] =?UTF-8?q?rft:=20Wpf=E5=94=A4=E9=86=92=E4=BB=BB=E5=8A=A1?=
=?UTF-8?q?=E5=BA=8F=E5=88=97=E5=8C=96?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/MaaWpfGui/Main/AsstProxy.cs | 20 -------
.../Models/AsstTasks/AsstStartUpTask.cs | 53 +++++++++++++++++++
.../ViewModels/UI/TaskQueueViewModel.cs | 14 +++--
.../StartUpSettingsUserControlModel.cs | 3 +-
4 files changed, 64 insertions(+), 26 deletions(-)
create mode 100644 src/MaaWpfGui/Models/AsstTasks/AsstStartUpTask.cs
diff --git a/src/MaaWpfGui/Main/AsstProxy.cs b/src/MaaWpfGui/Main/AsstProxy.cs
index 27afd101e5..a8eda2a955 100644
--- a/src/MaaWpfGui/Main/AsstProxy.cs
+++ b/src/MaaWpfGui/Main/AsstProxy.cs
@@ -2186,26 +2186,6 @@ namespace MaaWpfGui.Main
return id != 0;
}
- ///
- /// 开始唤醒。
- ///
- /// 客户端版本。
- /// 是否自动启动客户端。
- /// 需要切换到的登录名,留空以禁用
- /// 是否成功。
- public bool AsstAppendStartUp(string clientType, bool enable, string accountName)
- {
- var taskParams = new JObject
- {
- ["client_type"] = clientType,
- ["start_game_enabled"] = enable,
- ["account_name"] = accountName,
- };
- AsstTaskId id = AsstAppendTaskWithEncoding(AsstTaskType.StartUp, taskParams);
- _taskStatus.Add(id, TaskType.StartUp);
- return id != 0;
- }
-
public bool AsstAppendCloseDown(string clientType)
{
if (!AsstStop())
diff --git a/src/MaaWpfGui/Models/AsstTasks/AsstStartUpTask.cs b/src/MaaWpfGui/Models/AsstTasks/AsstStartUpTask.cs
new file mode 100644
index 0000000000..8112863ec1
--- /dev/null
+++ b/src/MaaWpfGui/Models/AsstTasks/AsstStartUpTask.cs
@@ -0,0 +1,53 @@
+//
+// MaaWpfGui - A part of the MaaCoreArknights project
+// Copyright (C) 2021 MistEO and Contributors
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License v3.0 only as published by
+// the Free Software Foundation, either version 3 of the License, or
+// any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY
+//
+
+#nullable enable
+using System.ComponentModel;
+using MaaWpfGui.Services;
+using Newtonsoft.Json;
+using Newtonsoft.Json.Linq;
+
+namespace MaaWpfGui.Models.AsstTasks;
+
+public class AsstStartUpTask : AsstBaseTask
+{
+ public override AsstTaskType TaskType => AsstTaskType.StartUp;
+
+ ///
+ /// Gets or sets 客户端版本
+ ///
+ [JsonProperty("client_type")]
+ public string ClientType { get; set; } = string.Empty;
+
+ ///
+ /// Gets or sets a value indicating whether gets or sets 是否自动启动客户端
+ ///
+ [JsonProperty("start_game_enabled")]
+ public bool StartGame { get; set; }
+
+ ///
+ /// Gets or sets 需要切换到的登录名,留空以禁用
+ ///
+ [JsonProperty("account_name", DefaultValueHandling = DefaultValueHandling.Ignore)]
+ [DefaultValue("")]
+ public string AccountName { get; set; } = string.Empty;
+
+ ///
+ /// 开始唤醒。
+ ///
+ /// 客户端版本。
+ /// 是否自动启动客户端。
+ /// 需要切换到的登录名,留空以禁用
+ /// 是否成功。
+ public override (AsstTaskType TaskType, JObject Params) Serialize() => (AsstTaskType.StartUp, JObject.FromObject(this));
+}
diff --git a/src/MaaWpfGui/ViewModels/UI/TaskQueueViewModel.cs b/src/MaaWpfGui/ViewModels/UI/TaskQueueViewModel.cs
index d866816074..a6e73b9f9d 100644
--- a/src/MaaWpfGui/ViewModels/UI/TaskQueueViewModel.cs
+++ b/src/MaaWpfGui/ViewModels/UI/TaskQueueViewModel.cs
@@ -27,6 +27,7 @@ using MaaWpfGui.Extensions;
using MaaWpfGui.Helper;
using MaaWpfGui.Main;
using MaaWpfGui.Models;
+using MaaWpfGui.Models.AsstTasks;
using MaaWpfGui.Services;
using MaaWpfGui.States;
using MaaWpfGui.Utilities;
@@ -1539,11 +1540,14 @@ namespace MaaWpfGui.ViewModels.UI
private static bool AppendStart()
{
- var mode = SettingsViewModel.GameSettings.ClientType;
- var enable = mode.Length != 0;
- StartUpTask.AccountName = StartUpTask.AccountName.Trim();
- var accountName = StartUpTask.AccountName;
- return Instances.AsstProxy.AsstAppendStartUp(mode, enable, accountName);
+ var clientType = SettingsViewModel.GameSettings.ClientType;
+ var (type, param) = new AsstStartUpTask()
+ {
+ ClientType = clientType,
+ StartGame = !string.IsNullOrEmpty(clientType),
+ AccountName = StartUpTask.AccountName,
+ }.Serialize();
+ return Instances.AsstProxy.AsstAppendTaskWithEncoding(AsstProxy.TaskType.StartUp, type, param);
}
private bool AppendFight()
diff --git a/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/StartUpSettingsUserControlModel.cs b/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/StartUpSettingsUserControlModel.cs
index 977eec311b..07e087d27b 100644
--- a/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/StartUpSettingsUserControlModel.cs
+++ b/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/StartUpSettingsUserControlModel.cs
@@ -27,13 +27,14 @@ public class StartUpSettingsUserControlModel : TaskViewModel
public static StartUpSettingsUserControlModel Instance { get; }
- private string _accountName = ConfigurationHelper.GetValue(ConfigurationKeys.AccountName, string.Empty);
+ private string _accountName = ConfigurationHelper.GetValue(ConfigurationKeys.AccountName, string.Empty).Trim();
public string AccountName
{
get => _accountName;
set
{
+ value = value.Trim();
SetAndNotify(ref _accountName, value);
ConfigurationHelper.SetValue(ConfigurationKeys.AccountName, value);
}