chore: 添加一个临时定时 (#12243)

* chore: 添加一个临时定时

* chore: 定时器全部改成可单次执行
This commit is contained in:
uye
2025-04-06 22:56:30 +08:00
committed by GitHub
parent 8ac6b22200
commit 830dfaaafb
3 changed files with 45 additions and 22 deletions

View File

@@ -488,7 +488,7 @@ namespace MaaWpfGui.ViewModels.UI
for (int i = 0; i < 8; ++i)
{
if (!SettingsViewModel.TimerSettings.TimerModels.Timers[i].IsOn)
if (SettingsViewModel.TimerSettings.TimerModels.Timers[i].IsOn == false)
{
continue;
}
@@ -547,6 +547,8 @@ namespace MaaWpfGui.ViewModels.UI
{
_logger.Information($"Scheduled start: Timer Index: {configIndex}");
await HandleScheduledStart(configIndex);
SettingsViewModel.TimerSettings.TimerModels.Timers[configIndex].IsOn ??= false;
}
}

View File

@@ -82,7 +82,7 @@ public class TimerSettingsUserControlModel : PropertyChangedBase
{
public class TimerProperties : PropertyChangedBase
{
public TimerProperties(int timeId, bool isOn, int hour, int min, string? timerConfig)
public TimerProperties(int timeId, bool? isOn, int hour, int min, string? timerConfig)
{
TimerId = timeId;
_isOn = isOn;
@@ -102,17 +102,14 @@ public class TimerSettingsUserControlModel : PropertyChangedBase
private readonly string _timerName = LocalizationHelper.GetString("Timer");
public string TimerName
{
get => $"{_timerName} {TimerId + 1}";
}
public string TimerName => $"{_timerName} {TimerId + 1}";
private bool _isOn;
private bool? _isOn;
/// <summary>
/// Gets or sets a value indicating whether the timer is set.
/// </summary>
public bool IsOn
public bool? IsOn
{
get => _isOn;
set
@@ -174,12 +171,12 @@ public class TimerSettingsUserControlModel : PropertyChangedBase
{
for (int i = 0; i < 8; i++)
{
Timers[i] = new TimerProperties(
i,
ConfigurationHelper.GetTimer(i, bool.FalseString) == bool.TrueString,
int.Parse(ConfigurationHelper.GetTimerHour(i, $"{i * 3}")),
int.Parse(ConfigurationHelper.GetTimerMin(i, "0")),
ConfigurationHelper.GetTimerConfig(i, ConfigurationHelper.GetCurrentConfiguration()));
var timerState = ConfigurationHelper.GetTimer(i, bool.FalseString);
bool? isOn = bool.TryParse(timerState, out bool parsedBool) ? parsedBool : null;
var hour = int.Parse(ConfigurationHelper.GetTimerHour(i, $"{i * 3}"));
var minute = int.Parse(ConfigurationHelper.GetTimerMin(i, "0"));
var config = ConfigurationHelper.GetTimerConfig(i, ConfigurationHelper.GetCurrentConfiguration());
Timers[i] = new(i, isOn, hour, minute, config);
}
}
}

View File

@@ -87,7 +87,10 @@
<CheckBox
Margin="10"
Content="{Binding TimerModels.Timers[0].TimerName}"
IsChecked="{Binding TimerModels.Timers[0].IsOn}" />
IsChecked="{Binding TimerModels.Timers[0].IsOn}"
MouseRightButtonUp="{s:Action ToggleCheckBoxNullOnRightClick,
Target={x:Type helper:CheckBoxHelper}}"
ToolTip="{DynamicResource CheckBoxesNotSaved}" />
<StackPanel Orientation="Horizontal">
<hc:NumericUpDown
Width="55"
@@ -133,7 +136,10 @@
<CheckBox
Margin="10"
Content="{Binding TimerModels.Timers[1].TimerName}"
IsChecked="{Binding TimerModels.Timers[1].IsOn}" />
IsChecked="{Binding TimerModels.Timers[1].IsOn}"
MouseRightButtonUp="{s:Action ToggleCheckBoxNullOnRightClick,
Target={x:Type helper:CheckBoxHelper}}"
ToolTip="{DynamicResource CheckBoxesNotSaved}" />
<StackPanel Orientation="Horizontal">
<hc:NumericUpDown
Width="55"
@@ -179,7 +185,10 @@
<CheckBox
Margin="10"
Content="{Binding TimerModels.Timers[2].TimerName}"
IsChecked="{Binding TimerModels.Timers[2].IsOn}" />
IsChecked="{Binding TimerModels.Timers[2].IsOn}"
MouseRightButtonUp="{s:Action ToggleCheckBoxNullOnRightClick,
Target={x:Type helper:CheckBoxHelper}}"
ToolTip="{DynamicResource CheckBoxesNotSaved}" />
<StackPanel Orientation="Horizontal">
<hc:NumericUpDown
Width="55"
@@ -225,7 +234,10 @@
<CheckBox
Margin="10"
Content="{Binding TimerModels.Timers[3].TimerName}"
IsChecked="{Binding TimerModels.Timers[3].IsOn}" />
IsChecked="{Binding TimerModels.Timers[3].IsOn}"
MouseRightButtonUp="{s:Action ToggleCheckBoxNullOnRightClick,
Target={x:Type helper:CheckBoxHelper}}"
ToolTip="{DynamicResource CheckBoxesNotSaved}" />
<StackPanel Orientation="Horizontal">
<hc:NumericUpDown
Width="55"
@@ -271,7 +283,10 @@
<CheckBox
Margin="10"
Content="{Binding TimerModels.Timers[4].TimerName}"
IsChecked="{Binding TimerModels.Timers[4].IsOn}" />
IsChecked="{Binding TimerModels.Timers[4].IsOn}"
MouseRightButtonUp="{s:Action ToggleCheckBoxNullOnRightClick,
Target={x:Type helper:CheckBoxHelper}}"
ToolTip="{DynamicResource CheckBoxesNotSaved}" />
<StackPanel Orientation="Horizontal">
<hc:NumericUpDown
Width="55"
@@ -317,7 +332,10 @@
<CheckBox
Margin="10"
Content="{Binding TimerModels.Timers[5].TimerName}"
IsChecked="{Binding TimerModels.Timers[5].IsOn}" />
IsChecked="{Binding TimerModels.Timers[5].IsOn}"
MouseRightButtonUp="{s:Action ToggleCheckBoxNullOnRightClick,
Target={x:Type helper:CheckBoxHelper}}"
ToolTip="{DynamicResource CheckBoxesNotSaved}" />
<StackPanel Orientation="Horizontal">
<hc:NumericUpDown
Width="55"
@@ -363,7 +381,10 @@
<CheckBox
Margin="10"
Content="{Binding TimerModels.Timers[6].TimerName}"
IsChecked="{Binding TimerModels.Timers[6].IsOn}" />
IsChecked="{Binding TimerModels.Timers[6].IsOn}"
MouseRightButtonUp="{s:Action ToggleCheckBoxNullOnRightClick,
Target={x:Type helper:CheckBoxHelper}}"
ToolTip="{DynamicResource CheckBoxesNotSaved}" />
<StackPanel Orientation="Horizontal">
<hc:NumericUpDown
Width="55"
@@ -409,7 +430,10 @@
<CheckBox
Margin="10"
Content="{Binding TimerModels.Timers[7].TimerName}"
IsChecked="{Binding TimerModels.Timers[7].IsOn}" />
IsChecked="{Binding TimerModels.Timers[7].IsOn}"
MouseRightButtonUp="{s:Action ToggleCheckBoxNullOnRightClick,
Target={x:Type helper:CheckBoxHelper}}"
ToolTip="{DynamicResource CheckBoxesNotSaved}" />
<StackPanel Orientation="Horizontal">
<hc:NumericUpDown
Width="55"