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
11 changes: 10 additions & 1 deletion Controls/Components/LocalQuoteComponent.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public partial class LocalQuoteComponent : ComponentBase<LocalQuoteSettings>, IN
private readonly List<string> _quotes = [];
private readonly Animation _swapOutAnimation;
private readonly Animation _swapInAnimation;
private readonly Random _random = new();
private int _currentIndex = -1;
private string _loadedPath = string.Empty;
private bool _isAnimating;
Expand Down Expand Up @@ -174,6 +175,12 @@ private void OnSettingsPropertyChanged(object? sender, PropertyChangedEventArgs
LoadQuotesFromFile(Settings.QuotesFilePath, showFirstQuote: true);
EnsureTimersForQuoteState();
}

if (e.PropertyName == nameof(Settings.PlaybackOrder))
{
ShowNextQuote();
EnsureTimersForQuoteState();
}
}

/// <summary>
Expand Down Expand Up @@ -323,7 +330,9 @@ private async void ShowNextQuote()
// 因此需要在当前轮换开始时立即重置,而不是等动画播放完成后再重置。
RestartProgressCycle(_carouselTimer.Interval.TotalSeconds);

_currentIndex = (_currentIndex + 1) % _quotes.Count;
_currentIndex = Settings.PlaybackOrder == LocalQuotePlaybackOrder.Random
? _random.Next(_quotes.Count)
: (_currentIndex + 1) % _quotes.Count;
var next = _quotes[_currentIndex];

// 更新持久化数据
Expand Down
16 changes: 16 additions & 0 deletions Controls/Components/LocalQuoteSettingsControl.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,22 @@
Value="{Binding Settings.CarouselIntervalSeconds, Mode=TwoWay}" />
</controls:SettingsExpander.Footer>
</controls:SettingsExpander>

<controls:SettingsExpander
Header="轮播顺序"
Description="设置一言文本的轮播方式"
IconSource="{ci:FluentIconSource &#xE143;}">
<controls:SettingsExpander.Footer>
<ComboBox SelectedItem="{Binding Settings.PlaybackOrder, Mode=TwoWay}"
ItemsSource="{Binding PlaybackOrders}">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Converter={StaticResource EnumDescriptionConverter}}" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</controls:SettingsExpander.Footer>
</controls:SettingsExpander>

<controls:SettingsExpander
Header="记忆轮播行"
Expand Down
1 change: 1 addition & 0 deletions Controls/Components/LocalQuoteSettingsControl.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace SystemTools.Controls.Components;
public partial class LocalQuoteSettingsControl : ComponentBase<LocalQuoteSettings>
{
public Array ProgressBarPositions { get; } = Enum.GetValues(typeof(LocalQuoteProgressBarPosition));
public Array PlaybackOrders { get; } = Enum.GetValues(typeof(LocalQuotePlaybackOrder));

public LocalQuoteSettingsControl()
{
Expand Down
11 changes: 11 additions & 0 deletions Models/ComponentSettings/LocalQuoteSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ public enum LocalQuoteProgressBarPosition
Top = 1
}

public enum LocalQuotePlaybackOrder
{
[Description("逐行播放")]
Sequential = 0,
[Description("随机播放")]
Random = 1
}

public partial class LocalQuoteSettings : ObservableObject
{
[ObservableProperty]
Expand All @@ -37,4 +45,7 @@ public partial class LocalQuoteSettings : ObservableObject

[ObservableProperty]
private LocalQuoteProgressBarPosition _progressBarPosition = LocalQuoteProgressBarPosition.Bottom;

[ObservableProperty]
private LocalQuotePlaybackOrder _playbackOrder = LocalQuotePlaybackOrder.Sequential;
}
87 changes: 87 additions & 0 deletions Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.ComponentModel;
using SystemTools.Actions;
using SystemTools.ConfigHandlers;
using SystemTools.Controls;
Expand Down Expand Up @@ -128,7 +129,7 @@
_logger?.LogWarning("[SystemTools]FFmpeg 功能已自动关闭:缺少依赖文件 ffmpeg.exe。");
}

if (GlobalConstants.MainConfig.Data.EnableFaceRecognition)

Check warning on line 132 in Plugin.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.
{
if (_faceRecognitionRegistered)
{
Expand All @@ -144,6 +145,7 @@
_logger?.LogWarning("[SystemTools]人脸识别功能已自动关闭:缺少 runtimes、Models 或 OpenCvSharp/Dlib 依赖,并已清理对应验证器配置。");
}
_logger?.LogInformation("[SystemTools]SystemTools 启动完成");
RegisterOrUpdateFloatingWindowTrayMenu();
};

// ========== 注册实验性功能 ==========
Expand Down Expand Up @@ -900,6 +902,91 @@
IAppHost.GetService<FloatingWindowService>().Stop();
}
_logger?.LogInformation("[SystemTools]关闭插件SystemTools,保存配置...");
UnregisterFloatingWindowTrayMenu();
GlobalConstants.MainConfig?.Save();
}

private void RegisterOrUpdateFloatingWindowTrayMenu()
{
var config = GlobalConstants.MainConfig?.Data;
if (config == null)
{
return;
}

if (_toggleFloatingWindowMenuItem == null)
{
_toggleFloatingWindowMenuItem = new NativeMenuItem();
_toggleFloatingWindowMenuItem.Click += (_, _) =>
{
var data = GlobalConstants.MainConfig?.Data;
if (data == null || !data.EnableFloatingWindowFeature)
{
return;
}

data.ShowFloatingWindow = !data.ShowFloatingWindow;
IAppHost.GetService<FloatingWindowService>().UpdateWindowState();
UpdateFloatingWindowTrayMenuHeader();
GlobalConstants.MainConfig?.Save();
};

config.PropertyChanged += OnMainConfigDataPropertyChanged;
}

if (!config.EnableFloatingWindowFeature)
{
UnregisterFloatingWindowTrayMenu();
return;
}

var trayService = IAppHost.TryGetService<ITaskBarIconService>();
if (trayService == null)
{
return;
Comment on lines +943 to +946
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Retry tray menu registration when service is temporarily null

RegisterOrUpdateFloatingWindowTrayMenu exits immediately when IAppHost.TryGetService<ITaskBarIconService>() returns null, but this method is only invoked at startup and on floating-window config changes. In startup orders where the tray service is not ready yet, the menu item is never added for the entire session unless the user later toggles ShowFloatingWindow/EnableFloatingWindowFeature, so the new tray toggle silently disappears for affected users.

Useful? React with 👍 / 👎.

}

if (!trayService.MoreOptionsMenuItems.Contains(_toggleFloatingWindowMenuItem))
{
trayService.MoreOptionsMenuItems.Add(_toggleFloatingWindowMenuItem);
}

UpdateFloatingWindowTrayMenuHeader();
}

private void UnregisterFloatingWindowTrayMenu()
{
var trayService = IAppHost.TryGetService<ITaskBarIconService>();
if (trayService == null || _toggleFloatingWindowMenuItem == null)
{
return;
}

if (trayService.MoreOptionsMenuItems.Contains(_toggleFloatingWindowMenuItem))
{
trayService.MoreOptionsMenuItems.Remove(_toggleFloatingWindowMenuItem);
}
}

private void OnMainConfigDataPropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (e.PropertyName is not (nameof(MainConfigData.ShowFloatingWindow) or nameof(MainConfigData.EnableFloatingWindowFeature)))
{
return;
}

Dispatcher.UIThread.Post(RegisterOrUpdateFloatingWindowTrayMenu);
}

private void UpdateFloatingWindowTrayMenuHeader()
{
if (_toggleFloatingWindowMenuItem == null)
{
return;
}

_toggleFloatingWindowMenuItem.Header = GlobalConstants.MainConfig?.Data.ShowFloatingWindow == true
? "隐藏悬浮窗"
: "显示悬浮窗";
}
}
2 changes: 1 addition & 1 deletion manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ name: SystemTools
description: 提供多彩而丰富的更多 组件/行动/触发器/实用工具
entranceAssembly: "SystemTools.dll"
url: https://github.com/Programmer-MrWang/SystemTools
version: 2.5.0.105
version: 2.5.0.106
apiVersion: 2.0.0.0
author: Programmer-MrWang
readme: README.md
Expand Down
Loading