perf: c# 代码逻辑&格式优化

This commit is contained in:
zzyyyl
2022-08-28 18:35:34 +08:00
committed by zzyyyl
parent 8a0aca1de8
commit fb8e8029d8
6 changed files with 144 additions and 170 deletions

View File

@@ -200,7 +200,7 @@ namespace MeoAsstGui
}
var mainModel = _container.Get<TaskQueueViewModel>();
mainModel.Inited = true;
mainModel.SetInited();
mainModel.Idle = true;
var settingsModel = _container.Get<SettingsViewModel>();
Execute.OnUIThread(async () =>

View File

@@ -273,16 +273,10 @@ namespace MeoAsstGui
// 系统按钮
private string _buttonSystemText = null;
private string _buttonSystemUrl;
/// <summary>
/// Gets or sets the button system URL.
/// </summary>
public string ButtonSystemUrl
{
get => _buttonSystemUrl;
set => _buttonSystemUrl = value;
}
public string ButtonSystemUrl { get; set; }
private bool _buttonSystemEnabled = false;
@@ -404,7 +398,7 @@ namespace MeoAsstGui
{
if (_buttonSystemEnabled)
{
Uri burl = new Uri(_buttonSystemUrl);
Uri burl = new Uri(ButtonSystemUrl);
new ToastContentBuilder()
.AddText(_notificationTitle)
.AddText(_contentCollection.ToString())

View File

@@ -429,10 +429,7 @@ namespace MeoAsstGui
/// <summary>
/// Gets the server type.
/// </summary>
public string ServerType
{
get => _serverMapping[ClientType];
}
public string ServerType => _serverMapping[ClientType];
/* 基建设置 */
@@ -1559,35 +1556,30 @@ namespace MeoAsstGui
}
/* 界面设置 */
#pragma warning disable SA1401 // Fields should be private
#pragma warning disable IDE1006
/// <summary>
/// Gets or sets a value indicating whether to use tray icon.
/// Gets a value indicating whether to use tray icon.
/// </summary>
public bool UseTray = true;
#pragma warning restore SA1401 // Fields should be private
#pragma warning restore IDE1006
public bool UseTray => true;
/*
private bool _useTray = Convert.ToBoolean(ViewStatusStorage.Get("GUI.UseTray", bool.TrueString));
public bool UseTray
{
get => _useTray;
set
{
SetAndNotify(ref _useTray, value);
ViewStatusStorage.Set("GUI.UseTray", value.ToString());
var trayObj = _container.Get<TrayIcon>();
trayObj.SetVisible(value);
get => _useTray;
set
{
SetAndNotify(ref _useTray, value);
ViewStatusStorage.Set("GUI.UseTray", value.ToString());
var trayObj = _container.Get<TrayIcon>();
trayObj.SetVisible(value);
if (!Convert.ToBoolean(value))
{
MinimizeToTray = false;
}
}
if (!Convert.ToBoolean(value))
{
MinimizeToTray = false;
}
}
}*/
private bool _minimizeToTray = Convert.ToBoolean(ViewStatusStorage.Get("GUI.MinimizeToTray", bool.FalseString));
@@ -1708,21 +1700,18 @@ namespace MeoAsstGui
{
case InverseClearType.Clear:
taskQueueModel.InverseMode = false;
taskQueueModel.InverseShowVisibility = Visibility.Collapsed;
taskQueueModel.NotInverseShowVisibility = Visibility.Visible;
taskQueueModel.ShowInverse = false;
taskQueueModel.SelectedAllWidth = 90;
break;
case InverseClearType.Inverse:
taskQueueModel.InverseMode = true;
taskQueueModel.InverseShowVisibility = Visibility.Collapsed;
taskQueueModel.NotInverseShowVisibility = Visibility.Visible;
taskQueueModel.ShowInverse = false;
taskQueueModel.SelectedAllWidth = 90;
break;
case InverseClearType.ClearInverse:
taskQueueModel.InverseShowVisibility = Visibility.Visible;
taskQueueModel.NotInverseShowVisibility = Visibility.Collapsed;
taskQueueModel.ShowInverse = true;
taskQueueModel.SelectedAllWidth = TaskQueueViewModel.SelectedAllWidthWhenBoth;
break;
}

View File

@@ -97,19 +97,22 @@ namespace MeoAsstGui
trayIcon.SetTaskQueueViewModel(this);
}
// public void ShowButton()
// {
// Visible = Visibility.Visible;
// Hibernate = true;
// }
/*
public void ShowButton()
{
Visible = Visibility.Visible;
Hibernate = true;
}
// private Visibility _visible = Visibility.Collapsed;
private Visibility _visible = Visibility.Collapsed;
public Visibility Visible
{
get => _visible;
set => SetAndNotify(ref _visible, value);
}
*/
// public Visibility Visible
// {
// get => _visible;
// set => SetAndNotify(ref _visible, value);
// }
private readonly System.Windows.Forms.Timer _timer = new System.Windows.Forms.Timer();
private void InitTimer()
@@ -556,6 +559,11 @@ namespace MeoAsstGui
}
}
/// <summary>
/// The width of "Select All" when both.
/// </summary>
public const int SelectedAllWidthWhenBoth = 80;
private int _selectedAllWidth =
ViewStatusStorage.Get("GUI.InverseClearMode", "Clear") == "ClearInverse" ? SelectedAllWidthWhenBoth : 85;
@@ -568,11 +576,6 @@ namespace MeoAsstGui
set => SetAndNotify(ref _selectedAllWidth, value);
}
/// <summary>
/// The width of "Select All" when both.
/// </summary>
public const int SelectedAllWidthWhenBoth = 80;
private int _inverseSelectedWidth = 90;
/// <summary>
@@ -584,28 +587,15 @@ namespace MeoAsstGui
set => SetAndNotify(ref _inverseSelectedWidth, value);
}
private Visibility _inverseShowVisibility =
ViewStatusStorage.Get("GUI.InverseClearMode", "Clear") == "ClearInverse" ? Visibility.Visible : Visibility.Collapsed;
private bool _showInverse = ViewStatusStorage.Get("GUI.InverseClearMode", "Clear") == "ClearInverse";
/// <summary>
/// Gets or sets the visibility of "Select inversely".
/// Gets or sets a value indicating whether "Select inversely" is visible.
/// </summary>
public Visibility InverseShowVisibility
public bool ShowInverse
{
get => _inverseShowVisibility;
set => SetAndNotify(ref _inverseShowVisibility, value);
}
private Visibility _notInverseShowVisibility =
ViewStatusStorage.Get("GUI.InverseClearMode", "Clear") == "ClearInverse" ? Visibility.Collapsed : Visibility.Visible;
/// <summary>
/// Gets or sets the visibility of "Not inversion".
/// </summary>
public Visibility NotInverseShowVisibility
{
get => _notInverseShowVisibility;
set => SetAndNotify(ref _notInverseShowVisibility, value);
get => _showInverse;
set => SetAndNotify(ref _showInverse, value);
}
private string _inverseShowText = Convert.ToBoolean(ViewStatusStorage.Get("MainFunction.InverseMode", bool.FalseString)) ? Localization.GetString("Inverse") : Localization.GetString("Clear");
@@ -1251,42 +1241,39 @@ namespace MeoAsstGui
/*
public void CheckAndShutdown()
{
if (Shutdown)
{
System.Diagnostics.Process.Start("shutdown.exe", "-s -t 60");
if (Shutdown)
{
System.Diagnostics.Process.Start("shutdown.exe", "-s -t 60");
var result = _windowManager.ShowMessageBox("已刷完,即将关机,是否取消?", "提示", MessageBoxButton.OK, MessageBoxImage.Question);
if (result == MessageBoxResult.OK)
{
System.Diagnostics.Process.Start("shutdown.exe", "-a");
}
}
if (Hibernate)
{
System.Diagnostics.Process.Start("shutdown.exe", "-h");
}
if (Suspend)
{
System.Diagnostics.Process.Start("rundll32.exe", "powrprof.dll,SetSuspendState 0,1,0");
}
var result = _windowManager.ShowMessageBox("已刷完,即将关机,是否取消?", "提示", MessageBoxButton.OK, MessageBoxImage.Question);
if (result == MessageBoxResult.OK)
{
System.Diagnostics.Process.Start("shutdown.exe", "-a");
}
}
if (Hibernate)
{
System.Diagnostics.Process.Start("shutdown.exe", "-h");
}
if (Suspend)
{
System.Diagnostics.Process.Start("rundll32.exe", "powrprof.dll,SetSuspendState 0,1,0");
}
}
*/
private bool _inited = false;
/// <summary>
/// Gets a value indicating whether it is initialized.
/// </summary>
public bool Inited { get; private set; } = false;
/// <summary>
/// Gets or sets a value indicating whether it is initialized.
/// Sets it initialized.
/// </summary>
public bool Inited
public void SetInited()
{
get => _inited;
set
{
if (value)
{
SetAndNotify(ref _inited, value);
}
}
Inited = true;
NotifyOfPropertyChange("Inited");
}
private bool _idle = false;
@@ -1320,56 +1307,58 @@ namespace MeoAsstGui
set => SetAndNotify(ref _fightTaskRunning, value);
}
// private bool _shutdown = false;
/*
private bool _shutdown = false;
// public bool Shutdown
// {
// get => return _shutdown;
// set
// {
// SetAndNotify(ref _shutdown, value);
//
// if (value)
// {
// Hibernate = false;
// Suspend = false;
// }
// }
// }
public bool Shutdown
{
get => return _shutdown;
set
{
SetAndNotify(ref _shutdown, value);
// private bool _hibernate = false; // 休眠
if (value)
{
Hibernate = false;
Suspend = false;
}
}
}
// public bool Hibernate
// {
// get => return _hibernate;
// set
// {
// SetAndNotify(ref _hibernate, value);
//
// if (value)
// {
// Shutdown = false;
// Suspend = false;
// }
// }
// }
private bool _hibernate = false; // 休眠
// private bool _suspend = false; // 待机
public bool Hibernate
{
get => return _hibernate;
set
{
SetAndNotify(ref _hibernate, value);
// public bool Suspend
// {
// get => return _suspend;
// set
// {
// SetAndNotify(ref _suspend, value);
//
// if (value)
// {
// Shutdown = false;
// Hibernate = false;
// }
// }
// }
if (value)
{
Shutdown = false;
Suspend = false;
}
}
}
private bool _suspend = false; // 待机
public bool Suspend
{
get => return _suspend;
set
{
SetAndNotify(ref _suspend, value);
if (value)
{
Shutdown = false;
Hibernate = false;
}
}
}
*/
/// <summary>
/// Gets or sets the list of all stages.

View File

@@ -117,29 +117,31 @@ namespace MeoAsstGui
set => SetAndNotify(ref _updateUrl, value);
}
// public FlowDocument UpdateInfoDocument
// {
// get
// {
// try
// {
// return MarkdownXaml.ToFlowDocument(UpdateInfo, s_markdownPipeline);
// }
// catch (Exception)
// {
// // 不知道为什么有一部分用户的电脑上,用 MarkdownXaml 解析直接就会 crash
// // 换另一个库再试一遍
// try
// {
// return new MdXaml.Markdown().Transform(UpdateInfo);
// }
// catch (Exception)
// {
// return new FlowDocument();
// }
// }
// }
// }
/*
public FlowDocument UpdateInfoDocument
{
get
{
try
{
return MarkdownXaml.ToFlowDocument(UpdateInfo, s_markdownPipeline);
}
catch (Exception)
{
// 不知道为什么有一部分用户的电脑上,用 MarkdownXaml 解析直接就会 crash
// 换另一个库再试一遍
try
{
return new MdXaml.Markdown().Transform(UpdateInfo);
}
catch (Exception)
{
return new FlowDocument();
}
}
}
}
*/
/// <summary>
/// Gets a value indicating whether it is the first boot after updating.

View File

@@ -87,7 +87,7 @@
Command="{s:Action InverseSelected}"
Content="{Binding InverseShowText}"
IsEnabled="{Binding Idle}"
Visibility="{Binding InverseShowVisibility}">
Visibility="{c:Binding ShowInverse}">
<hc:SplitButton.DropDownContent>
<MenuItem
Width="{Binding InverseSelectedWidth}"
@@ -103,7 +103,7 @@
Command="{s:Action InverseSelected}"
Content="{Binding InverseShowText}"
IsEnabled="{Binding Idle}"
Visibility="{Binding NotInverseShowVisibility}" />
Visibility="{c:Binding Path=!ShowInverse}" />
</Grid>
</Grid>
</Border>