Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions Actions/AdvancedShutdownAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ public class AdvancedShutdownAction(ILogger<AdvancedShutdownAction> logger) : Ac
private static bool _allowMainDialogClose;
private static bool _allowFloatingWindowClose;

public static void CancelPlanOnAppStopping()
{
StopCountdownProcess();
TryAbortSystemShutdown();
}

protected override async Task OnInvoke()
{
_logger.LogDebug("AdvancedShutdownAction OnInvoke 开始");
Expand Down Expand Up @@ -180,6 +186,26 @@ private static void StopCountdownProcess()
}
}

private static void TryAbortSystemShutdown()
{
try
{
var psi = new ProcessStartInfo
{
FileName = "shutdown",
Arguments = "/a",
UseShellExecute = false,
CreateNoWindow = true,
WindowStyle = ProcessWindowStyle.Hidden
};
using var process = Process.Start(psi);
process?.WaitForExit(1000);
}
catch
{
}
}

private static int GetRemainingSeconds()
{
lock (StateLock)
Expand Down Expand Up @@ -255,6 +281,7 @@ private void StopWatchdog()
private void StopAllStates()
{
StopCountdownProcess();
TryAbortSystemShutdown();
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Avoid aborting unrelated system shutdowns

StopAllStates now always calls shutdown /a, which cancels any pending Windows shutdown globally, not just one started by this action. That means stopping this action (or app shutdown via CancelPlanOnAppStopping) can unexpectedly cancel a shutdown scheduled by another tool/admin process, which is a functional regression outside this feature's scope.

Useful? React with 👍 / 👎.


lock (StateLock)
{
Expand Down
30 changes: 30 additions & 0 deletions Actions/LoadTemporaryClassPlanAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using ClassIsland.Core.Attributes;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Concurrent;
using System.Threading.Tasks;
using SystemTools.Settings;

Expand All @@ -18,6 +19,8 @@ public class LoadTemporaryClassPlanAction(
private readonly IProfileService _profileService = profileService;
private readonly IExactTimeService _exactTimeService = exactTimeService;

private static readonly ConcurrentDictionary<Guid, TempClassPlanSnapshot> PreviousSnapshots = new();

protected override async Task OnInvoke()
{
if (!Guid.TryParse(Settings.ClassPlanId, out var classPlanId))
Expand All @@ -32,11 +35,38 @@ protected override async Task OnInvoke()
return;
}

if (IsRevertable)
{
PreviousSnapshots[ActionSet.Guid] = new TempClassPlanSnapshot(
_profileService.Profile.TempClassPlanId,
_profileService.Profile.TempClassPlanSetupTime);
}

_profileService.Profile.TempClassPlanId = classPlanId;
_profileService.Profile.TempClassPlanSetupTime = _exactTimeService.GetCurrentLocalDateTime();
_profileService.SaveProfile();
_logger.LogInformation("已加载临时课表:{ClassPlanName} ({ClassPlanId})", classPlan.Name, classPlanId);

await base.OnInvoke();
}

protected override async Task OnRevert()
{
await base.OnRevert();

if (PreviousSnapshots.TryRemove(ActionSet.Guid, out var snapshot))
{
_profileService.Profile.TempClassPlanId = snapshot.TempClassPlanId;
_profileService.Profile.TempClassPlanSetupTime = snapshot.TempClassPlanSetupTime;
_profileService.SaveProfile();
_logger.LogInformation("已恢复临时课表为触发前状态。ActionSet={ActionSetGuid}", ActionSet.Guid);
return;
}

_profileService.Profile.TempClassPlanId = null;
_profileService.SaveProfile();
_logger.LogInformation("未找到触发前状态,已清除临时课表。ActionSet={ActionSetGuid}", ActionSet.Guid);
}

private readonly record struct TempClassPlanSnapshot(Guid? TempClassPlanId, DateTime TempClassPlanSetupTime);
}
14 changes: 14 additions & 0 deletions ConfigHandlers/MainConfigData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,20 @@ public bool EnableFaceRecognition
RestartPropertyChanged?.Invoke(this, EventArgs.Empty);
}
}

bool _autoMatchMainBackgroundTheme;

[JsonPropertyName("autoMatchMainBackgroundTheme")]
public bool AutoMatchMainBackgroundTheme
{
get => _autoMatchMainBackgroundTheme;
set
{
if (value == _autoMatchMainBackgroundTheme) return;
_autoMatchMainBackgroundTheme = value;
OnPropertyChanged();
}
}

// ========== 公告相关 ==========
/*string _lastAcceptedAnnouncement = string.Empty;
Expand Down
9 changes: 1 addition & 8 deletions Controls/AdvancedShutdownSettingsControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,6 @@ public AdvancedShutdownSettingsControl()
{
var panel = new StackPanel { Spacing = 10, Margin = new(10) };

panel.Children.Add(new TextBlock
{
Text = "高级计时关机设置",
FontWeight = Avalonia.Media.FontWeight.Bold,
FontSize = 14
});

var minutesPanel = new StackPanel
{
Orientation = Avalonia.Layout.Orientation.Horizontal,
Expand All @@ -45,7 +38,7 @@ public AdvancedShutdownSettingsControl()

panel.Children.Add(new TextBlock
{
Text = "触发后会弹出独立对话框,可已阅、取消计划或延长时间。",
Text = "拥有独立对话框,可已阅、取消计划、延长时间或立即关机。",
TextWrapping = Avalonia.Media.TextWrapping.Wrap,
Foreground = Avalonia.Media.Brushes.Gray
});
Expand Down
39 changes: 25 additions & 14 deletions Controls/Components/BetterCarouselContainerComponent.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,30 @@
</Setter>
</Style>

<Style Selector="local|BetterCarouselContainerComponent ProgressBar#DisplayProgressBar">
<Setter Property="IsVisible" Value="False" />
<Setter Property="MinWidth" Value="0" />
</Style>

<Style Selector="local|BetterCarouselContainerComponent:progress-visible ProgressBar#DisplayProgressBar">
<Setter Property="IsVisible" Value="True" />
</Style>
</ci:ComponentBase.Styles>

<Grid DataContext="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=local:BetterCarouselContainerComponent}}"
x:Name="GridRoot">


<ProgressBar x:Name="DisplayProgressBarTop"
VerticalAlignment="Top"
HorizontalAlignment="Stretch"
Margin="0"
Height="4"
MinWidth="0"
Minimum="0"
Maximum="100"
IsVisible="{Binding ShowTopProgressBar, Mode=OneWay}"
Value="{Binding CurrentProgressPercent, Mode=OneWay}" />

<StackPanel Orientation="Horizontal"
Spacing="0"
VerticalAlignment="Center"
HorizontalAlignment="Stretch">

<TextBlock Text=">"
IsVisible="{Binding Settings.ShowSideSeparators}"
VerticalAlignment="Center"
Margin="0,0,4,0" />
<ListBox x:Name="CarouselListBox"
Background="Transparent"
BorderThickness="0"
Expand Down Expand Up @@ -102,21 +108,26 @@
HidingRules="{Binding HidingRules, Mode=OneWay}"
HideOnRule="{Binding HideOnRule, Mode=OneWay}"
VerticalAlignment="Center"
Margin="0" />
Margin="0" />
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<TextBlock Text="&lt;"
IsVisible="{Binding Settings.ShowSideSeparators}"
VerticalAlignment="Center"
Margin="4,0,0,0" />
</StackPanel>

<ProgressBar x:Name="DisplayProgressBar"
<ProgressBar x:Name="DisplayProgressBarBottom"
VerticalAlignment="Bottom"
HorizontalAlignment="Stretch"
Margin="0,6,0,0"
Margin="0"
Height="4"
MinWidth="0"
Minimum="0"
Maximum="100"
IsVisible="{Binding ShowBottomProgressBar, Mode=OneWay}"
Value="{Binding CurrentProgressPercent, Mode=OneWay}" />
</Grid>
</ci:ComponentBase>
</ci:ComponentBase>
13 changes: 7 additions & 6 deletions Controls/Components/BetterCarouselContainerComponent.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ public int SelectedIndex
public double CurrentProgressPercent { get; private set; }

public int AnimationStyleValue => (int)Settings.AnimationStyle;
public bool ShowTopProgressBar => Settings.ShowProgressBar && Settings.ProgressBarPosition == BetterCarouselProgressBarPosition.Top;
public bool ShowBottomProgressBar => Settings.ShowProgressBar && Settings.ProgressBarPosition == BetterCarouselProgressBarPosition.Bottom;

public new event PropertyChangedEventHandler? PropertyChanged;

Expand Down Expand Up @@ -323,22 +325,23 @@ private void OnSettingsPropertyChanged(object? sender, PropertyChangedEventArgs
OnPropertyChanged(nameof(AnimationStyleValue));
}

if (e.PropertyName is nameof(Settings.ShowProgressBar))
if (e.PropertyName is nameof(Settings.ShowProgressBar) or nameof(Settings.ProgressBarPosition))
{
PseudoClasses.Set(":progress-visible", Settings.ShowProgressBar);
OnPropertyChanged(nameof(ShowTopProgressBar));
OnPropertyChanged(nameof(ShowBottomProgressBar));
}

if (e.PropertyName is nameof(Settings.RotationMode) or nameof(Settings.IsAnimationEnabled) or nameof(Settings.ShowProgressBar))
{
UpdateProgressState(resetWhenIdle: true);
return;
}

if (e.PropertyName == nameof(Settings.ComponentDisplayDurations))
{
Settings.NormalizeDisplayDurations();
RestartProgress();
}

}

private void OnChildrenCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
Expand Down Expand Up @@ -416,8 +419,6 @@ private void EnsureSelectedIndexValid()

private void UpdateProgressState(bool resetWhenIdle = false)
{
PseudoClasses.Set(":progress-visible", Settings.ShowProgressBar);

var displayable = GetDisplayableIndexes();
if (displayable.Length == 0)
{
Expand Down Expand Up @@ -551,4 +552,4 @@ protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}
24 changes: 22 additions & 2 deletions Controls/Components/BetterCarouselContainerSettingsControl.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,27 @@
Description="显示当前组件剩余显示时长的进度条"
IconSource="{ci:FluentIconSource &#xE093;}">
<controls:SettingsExpander.Footer>
<ToggleSwitch IsChecked="{Binding Settings.ShowProgressBar, Mode=TwoWay}" />
<StackPanel Orientation="Horizontal" Spacing="8">
<ToggleSwitch IsChecked="{Binding Settings.ShowProgressBar, Mode=TwoWay}" />
<ComboBox Width="140"
IsVisible="{Binding Settings.ShowProgressBar}"
SelectedItem="{Binding Settings.ProgressBarPosition, Mode=TwoWay}"
ItemsSource="{Binding ProgressBarPositions}">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Converter={StaticResource EnumDescriptionConverter}}" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</StackPanel>
</controls:SettingsExpander.Footer>
</controls:SettingsExpander>

<controls:SettingsExpander Header="添加分隔符样式"
Description="在容器左右两侧固定显示“&lt;”和“&gt;”"
IconSource="{ci:FluentIconSource &#xEEDF;}">
<controls:SettingsExpander.Footer>
<ToggleSwitch IsChecked="{Binding Settings.ShowSideSeparators, Mode=TwoWay}" />
</controls:SettingsExpander.Footer>
</controls:SettingsExpander>

Expand Down Expand Up @@ -113,4 +133,4 @@
</StackPanel>
</ScrollViewer>
</Grid>
</ci:ComponentBase>
</ci:ComponentBase>
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public partial class BetterCarouselContainerSettingsControl : ComponentBase<Bett

public Array RotationModes { get; } = Enum.GetValues(typeof(BetterCarouselRotationMode));
public Array AnimationStyles { get; } = Enum.GetValues(typeof(BetterCarouselAnimationStyle));
public Array ProgressBarPositions { get; } = Enum.GetValues(typeof(BetterCarouselProgressBarPosition));

public bool HasDurationItems => DurationItems.Count > 0;

Expand Down Expand Up @@ -141,4 +142,4 @@ protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}
2 changes: 1 addition & 1 deletion Controls/Components/LocalQuoteComponent.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ private void OnCarouselTicked(object? sender, EventArgs e)

private void RefreshTimerInterval()
{
var interval = Math.Max(1, Settings.CarouselIntervalSeconds);
var interval = Math.Clamp(Settings.CarouselIntervalSeconds, 1, 8000);
_carouselTimer.Interval = TimeSpan.FromSeconds(interval);
}

Expand Down
2 changes: 1 addition & 1 deletion Controls/Components/LocalQuoteSettingsControl.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
IconSource="{ci:FluentIconSource &#xEF75;}">
<controls:SettingsExpander.Footer>
<NumericUpDown Minimum="1"
Maximum="600"
Maximum="8000"
Increment="1"
Value="{Binding Settings.CarouselIntervalSeconds, Mode=TwoWay}" />
</controls:SettingsExpander.Footer>
Expand Down
Loading
Loading