rft: WpfGui重构 拆分设置-远程控制 (#11202)

* rft: WpfGui重构 拆分`设置-远程控制`

* perf: 移除
This commit is contained in:
status102
2024-11-20 16:48:52 +08:00
committed by GitHub
parent 962f8b200d
commit e9bb0681a2
6 changed files with 111 additions and 79 deletions

View File

@@ -25,6 +25,7 @@ using MaaWpfGui.Constants;
using MaaWpfGui.Helper;
using MaaWpfGui.States;
using MaaWpfGui.ViewModels.UI;
using MaaWpfGui.ViewModels.UserControl.Settings;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Serilog;
@@ -50,6 +51,8 @@ namespace MaaWpfGui.Services.RemoteControl
private string _currentSequentialTaskId = string.Empty;
private static RemoteControlUserControlModel RemoteSettings => SettingsViewModel.RemoteControlSettings;
public RemoteControlService()
{
InitializePollJobTask();
@@ -63,7 +66,7 @@ namespace MaaWpfGui.Services.RemoteControl
return;
}
if (!IsEndpointValid(Instances.SettingsViewModel.RemoteControlGetTaskEndpointUri))
if (!IsEndpointValid(RemoteSettings.RemoteControlGetTaskEndpointUri))
{
return;
}
@@ -77,7 +80,7 @@ namespace MaaWpfGui.Services.RemoteControl
await Task.Delay(1000);
try
{
if (!IsEndpointValid(Instances.SettingsViewModel.RemoteControlGetTaskEndpointUri))
if (!IsEndpointValid(RemoteSettings.RemoteControlGetTaskEndpointUri))
{
Log.Logger.Information("RemoteControlGetTaskEndpointUri is not valid, return");
_inited = false;
@@ -102,7 +105,7 @@ namespace MaaWpfGui.Services.RemoteControl
await Task.Delay(1000);
try
{
if (!IsEndpointValid(Instances.SettingsViewModel.RemoteControlGetTaskEndpointUri))
if (!IsEndpointValid(RemoteSettings.RemoteControlGetTaskEndpointUri))
{
Log.Logger.Information("RemoteControlGetTaskEndpointUri is not valid, return");
return;
@@ -126,7 +129,7 @@ namespace MaaWpfGui.Services.RemoteControl
await Task.Delay(1000);
try
{
if (!IsEndpointValid(Instances.SettingsViewModel.RemoteControlGetTaskEndpointUri))
if (!IsEndpointValid(RemoteSettings.RemoteControlGetTaskEndpointUri))
{
Log.Logger.Information("RemoteControlGetTaskEndpointUri is not valid, return");
return;
@@ -282,15 +285,15 @@ namespace MaaWpfGui.Services.RemoteControl
private async Task PollJobTaskLoop()
{
var endpoint = Instances.SettingsViewModel.RemoteControlGetTaskEndpointUri;
var endpoint = RemoteSettings.RemoteControlGetTaskEndpointUri;
if (!IsEndpointValid(endpoint))
{
return;
}
var uid = Instances.SettingsViewModel.RemoteControlUserIdentity;
var did = Instances.SettingsViewModel.RemoteControlDeviceIdentity;
var uid = RemoteSettings.RemoteControlUserIdentity;
var did = RemoteSettings.RemoteControlDeviceIdentity;
var response = await Instances.HttpService.PostAsJsonAsync(new Uri(endpoint), new { user = uid, device = did });
if (response == null)
{
@@ -462,11 +465,11 @@ namespace MaaWpfGui.Services.RemoteControl
break;
}
var endpoint = Instances.SettingsViewModel.RemoteControlReportStatusUri;
var endpoint = RemoteSettings.RemoteControlReportStatusUri;
if (IsEndpointValid(endpoint))
{
var uid = Instances.SettingsViewModel.RemoteControlUserIdentity;
var did = Instances.SettingsViewModel.RemoteControlDeviceIdentity;
var uid = RemoteSettings.RemoteControlUserIdentity;
var did = RemoteSettings.RemoteControlDeviceIdentity;
var response = await Instances.HttpService.PostAsJsonAsync(new Uri(endpoint), new
{
user = uid,
@@ -557,11 +560,11 @@ namespace MaaWpfGui.Services.RemoteControl
break;
}
var endpoint = Instances.SettingsViewModel.RemoteControlReportStatusUri;
var endpoint = RemoteSettings.RemoteControlReportStatusUri;
if (IsEndpointValid(endpoint))
{
var uid = Instances.SettingsViewModel.RemoteControlUserIdentity;
var did = Instances.SettingsViewModel.RemoteControlDeviceIdentity;
var uid = RemoteSettings.RemoteControlUserIdentity;
var did = RemoteSettings.RemoteControlDeviceIdentity;
var response = await Instances.HttpService.PostAsJsonAsync(new Uri(endpoint), new
{
user = uid,
@@ -716,15 +719,15 @@ namespace MaaWpfGui.Services.RemoteControl
public static async Task ConnectionTest()
{
var endpoint = Instances.SettingsViewModel.RemoteControlGetTaskEndpointUri;
var endpoint = RemoteSettings.RemoteControlGetTaskEndpointUri;
if (!IsEndpointValid(endpoint, alarm: true))
{
return;
}
var uid = Instances.SettingsViewModel.RemoteControlUserIdentity;
var did = Instances.SettingsViewModel.RemoteControlDeviceIdentity;
var uid = RemoteSettings.RemoteControlUserIdentity;
var did = RemoteSettings.RemoteControlDeviceIdentity;
try
{
@@ -771,7 +774,7 @@ namespace MaaWpfGui.Services.RemoteControl
public static void RegenerateDeviceIdentity()
{
Instances.SettingsViewModel.RemoteControlDeviceIdentity = Guid.NewGuid().ToString("N");
RemoteSettings.RemoteControlDeviceIdentity = Guid.NewGuid().ToString("N");
}
public static bool IsEndpointValid(string endpoint, bool alarm = false)

View File

@@ -108,6 +108,11 @@ namespace MaaWpfGui.ViewModels.UI
/// </summary>
public static TimerSettingsUserControlModel TimerSettings { get; } = new();
/// <summary>
/// Gets 远程控制model
/// </summary>
public static RemoteControlUserControlModel RemoteControlSettings { get; } = new();
/// <summary>
/// Gets 软件更新model
/// </summary>
@@ -407,63 +412,6 @@ namespace MaaWpfGui.ViewModels.UI
#endregion EasterEggs
#region Remote Control
private string _remoteControlGetTaskEndpointUri = ConfigurationHelper.GetValue(ConfigurationKeys.RemoteControlGetTaskEndpointUri, string.Empty);
public string RemoteControlGetTaskEndpointUri
{
get => _remoteControlGetTaskEndpointUri;
set
{
if (!SetAndNotify(ref _remoteControlGetTaskEndpointUri, value))
{
return;
}
Instances.RemoteControlService.InitializePollJobTask();
ConfigurationHelper.SetValue(ConfigurationKeys.RemoteControlGetTaskEndpointUri, value);
}
}
private string _remoteControlReportStatusUri = ConfigurationHelper.GetValue(ConfigurationKeys.RemoteControlReportStatusUri, string.Empty);
public string RemoteControlReportStatusUri
{
get => _remoteControlReportStatusUri;
set
{
SetAndNotify(ref _remoteControlReportStatusUri, value);
ConfigurationHelper.SetValue(ConfigurationKeys.RemoteControlReportStatusUri, value);
}
}
private string _remoteControlUserIdentity = ConfigurationHelper.GetValue(ConfigurationKeys.RemoteControlUserIdentity, string.Empty);
public string RemoteControlUserIdentity
{
get => _remoteControlUserIdentity;
set
{
SetAndNotify(ref _remoteControlUserIdentity, value);
ConfigurationHelper.SetValue(ConfigurationKeys.RemoteControlUserIdentity, value);
}
}
private string _remoteControlDeviceIdentity = ConfigurationHelper.GetValue(ConfigurationKeys.RemoteControlDeviceIdentity, string.Empty);
public string RemoteControlDeviceIdentity
{
get => _remoteControlDeviceIdentity;
set
{
SetAndNotify(ref _remoteControlDeviceIdentity, value);
ConfigurationHelper.SetValue(ConfigurationKeys.RemoteControlDeviceIdentity, value);
}
}
#endregion Remote Control
#region Performance
public List<GpuOption> GpuOptions => GpuOption.GetGpuOptions();

View File

@@ -0,0 +1,78 @@
// <copyright file="RemoteControlUserControlModel.cs" company="MaaAssistantArknights">
// 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
// </copyright>
#nullable enable
using MaaWpfGui.Constants;
using MaaWpfGui.Helper;
using Stylet;
namespace MaaWpfGui.ViewModels.UserControl.Settings;
/// <summary>
/// 远程控制
/// </summary>
public class RemoteControlUserControlModel : PropertyChangedBase
{
private string _remoteControlGetTaskEndpointUri = ConfigurationHelper.GetValue(ConfigurationKeys.RemoteControlGetTaskEndpointUri, string.Empty);
public string RemoteControlGetTaskEndpointUri
{
get => _remoteControlGetTaskEndpointUri;
set
{
if (!SetAndNotify(ref _remoteControlGetTaskEndpointUri, value))
{
return;
}
Instances.RemoteControlService.InitializePollJobTask();
ConfigurationHelper.SetValue(ConfigurationKeys.RemoteControlGetTaskEndpointUri, value);
}
}
private string _remoteControlReportStatusUri = ConfigurationHelper.GetValue(ConfigurationKeys.RemoteControlReportStatusUri, string.Empty);
public string RemoteControlReportStatusUri
{
get => _remoteControlReportStatusUri;
set
{
SetAndNotify(ref _remoteControlReportStatusUri, value);
ConfigurationHelper.SetValue(ConfigurationKeys.RemoteControlReportStatusUri, value);
}
}
private string _remoteControlUserIdentity = ConfigurationHelper.GetValue(ConfigurationKeys.RemoteControlUserIdentity, string.Empty);
public string RemoteControlUserIdentity
{
get => _remoteControlUserIdentity;
set
{
SetAndNotify(ref _remoteControlUserIdentity, value);
ConfigurationHelper.SetValue(ConfigurationKeys.RemoteControlUserIdentity, value);
}
}
private string _remoteControlDeviceIdentity = ConfigurationHelper.GetValue(ConfigurationKeys.RemoteControlDeviceIdentity, string.Empty);
public string RemoteControlDeviceIdentity
{
get => _remoteControlDeviceIdentity;
set
{
SetAndNotify(ref _remoteControlDeviceIdentity, value);
ConfigurationHelper.SetValue(ConfigurationKeys.RemoteControlDeviceIdentity, value);
}
}
}

View File

@@ -80,7 +80,10 @@
DataContext="{Binding StartSettings}" />
<hc:Divider Content="{Binding ListTitle[6]}" />
<userControl:RemoteControlUserControl Margin="0,20" HorizontalAlignment="Center" />
<settingsViews:RemoteControlUserControl
Margin="0,20"
HorizontalAlignment="Center"
DataContext="{Binding RemoteControlSettings}" />
<hc:Divider Content="{Binding ListTitle[7]}" />
<settingsViews:GuiSettingsUserControl

View File

@@ -1,5 +1,5 @@
<UserControl
x:Class="MaaWpfGui.Views.UserControl.RemoteControlUserControl"
x:Class="MaaWpfGui.Views.UserControl.Settings.RemoteControlUserControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:calcBinding="clr-namespace:CalcBinding;assembly=CalcBinding"
@@ -10,9 +10,9 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:remoteControl="clr-namespace:MaaWpfGui.Services.RemoteControl"
xmlns:s="https://github.com/canton7/Stylet"
xmlns:ui="clr-namespace:MaaWpfGui.ViewModels.UI"
xmlns:viewModels="clr-namespace:MaaWpfGui.ViewModels.UserControl.Settings"
d:Background="White"
d:DataContext="{d:DesignInstance {x:Type ui:SettingsViewModel}}"
d:DataContext="{d:DesignInstance {x:Type viewModels:RemoteControlUserControlModel}}"
d:DesignHeight="300"
d:DesignWidth="550"
mc:Ignorable="d">

View File

@@ -26,7 +26,7 @@ using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace MaaWpfGui.Views.UserControl
namespace MaaWpfGui.Views.UserControl.Settings
{
/// <summary>
/// RemoteControlUserControl.xaml 的交互逻辑