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
3 changes: 0 additions & 3 deletions Actions/AltF4Action.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ public class AltF4Action(ILogger<AltF4Action> logger) : ActionBase
{
private readonly ILogger<AltF4Action> _logger = logger;

//[DllImport("user32.dll", SetLastError = true)]
//private static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, UIntPtr dwExtraInfo);

private const byte VK_MENU = 0x12; // Alt 键
private const byte VK_F4 = 0x73; // F4 键

Expand Down
3 changes: 0 additions & 3 deletions Actions/AltTabAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ public class AltTabAction(ILogger<AltTabAction> logger) : ActionBase
{
private readonly ILogger<AltTabAction> _logger = logger;

//[DllImport("user32.dll", SetLastError = true)]
//private static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, UIntPtr dwExtraInfo);

private const byte VK_MENU = 0x12; // Alt 键
private const byte VK_TAB = 0x09; // Tab 键

Expand Down
52 changes: 52 additions & 0 deletions Actions/CtrlZAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using ClassIsland.Core.Abstractions.Automation;
using ClassIsland.Core.Attributes;
using Microsoft.Extensions.Logging;
using Windows.Win32;

namespace SystemTools.Actions;

[ActionInfo("SystemTools.CtrlZ", "按下 Ctrl+Z", "\uEA0B", false)]
public class CtrlZAction(ILogger<CtrlZAction> logger) : ActionBase
{
private readonly ILogger<CtrlZAction> _logger = logger;

private const byte VK_CONTROL = 0x11; // Ctrl 键
private const byte VK_Z = 0x5A; // Z 键

protected override async Task OnInvoke()
{
try
{
_logger.LogInformation("正在模拟按下 Ctrl+Z");

// 按下 Ctrl
PInvoke.keybd_event(VK_CONTROL, 0, 0, UIntPtr.Zero);
await Task.Delay(20);

// 按下 Z
PInvoke.keybd_event(VK_Z, 0, 0, UIntPtr.Zero);
await Task.Delay(20);

// 释放 Z
PInvoke.keybd_event(VK_Z, 0, Windows.Win32.UI.Input.KeyboardAndMouse.KEYBD_EVENT_FLAGS.KEYEVENTF_KEYUP,
UIntPtr.Zero);
await Task.Delay(20);

// 释放 Ctrl
PInvoke.keybd_event(VK_CONTROL, 0, Windows.Win32.UI.Input.KeyboardAndMouse.KEYBD_EVENT_FLAGS.KEYEVENTF_KEYUP,
UIntPtr.Zero);

_logger.LogInformation("Ctrl+Z 已成功发送");
}
catch (Exception ex)
{
_logger.LogError(ex, "发送 Ctrl+Z 失败");
throw;
}

await base.OnInvoke();
}
}
5 changes: 0 additions & 5 deletions Actions/EnterKeyAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ public class EnterKeyAction(ILogger<EnterKeyAction> logger) : ActionBase
{
private readonly ILogger<EnterKeyAction> _logger = logger;

// Windows API 导入
//[DllImport("user32.dll", SetLastError = true)]
//private static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, UIntPtr dwExtraInfo);

// 常量定义
private const byte VK_RETURN = 0x0D; // Enter 键的虚拟键码

protected override async Task OnInvoke()
Expand Down
3 changes: 0 additions & 3 deletions Actions/EscAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ public class EscAction(ILogger<EscAction> logger) : ActionBase
{
private readonly ILogger<EscAction> _logger = logger;

//[DllImport("user32.dll", SetLastError = true)]
//private static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, UIntPtr dwExtraInfo);

private const byte VK_ESCAPE = 0x1B;

protected override async Task OnInvoke()
Expand Down
3 changes: 0 additions & 3 deletions Actions/F11Action.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ public class F11Action(ILogger<F11Action> logger) : ActionBase
{
private readonly ILogger<F11Action> _logger = logger;

//[DllImport("user32.dll", SetLastError = true)]
//private static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, UIntPtr dwExtraInfo);

private const byte VK_F11 = 0x7A;

protected override async Task OnInvoke()
Expand Down
24 changes: 24 additions & 0 deletions Actions/OpenAppSettingsAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using ClassIsland.Core.Abstractions.Automation;
using ClassIsland.Core.Abstractions.Services;
using ClassIsland.Core.Attributes;
using Microsoft.Extensions.Logging;
using System;
using System.Threading.Tasks;

namespace SystemTools.Actions;

[ActionInfo("SystemTools.OpenAppSettings", "打开应用设置", "\uEF27", false)]
public class OpenAppSettingsAction(
ILogger<OpenAppSettingsAction> logger,
IUriNavigationService uriNavigationService) : ActionBase
{
private readonly ILogger<OpenAppSettingsAction> _logger = logger;
private readonly IUriNavigationService _uriNavigationService = uriNavigationService;

protected override Task OnInvoke()
{
_logger.LogInformation("正在打开 ClassIsland 应用设置窗口");
_uriNavigationService.NavigateWrapped(new Uri("classisland://app/settings"));
return base.OnInvoke();
}
}
24 changes: 24 additions & 0 deletions Actions/OpenClassSwapWindowAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using ClassIsland.Core.Abstractions.Automation;
using ClassIsland.Core.Abstractions.Services;
using ClassIsland.Core.Attributes;
using Microsoft.Extensions.Logging;
using System;
using System.Threading.Tasks;

namespace SystemTools.Actions;

[ActionInfo("SystemTools.OpenClassSwapWindow", "打开换课窗口", "\uE13B", false)]
public class OpenClassSwapWindowAction(
ILogger<OpenClassSwapWindowAction> logger,
IUriNavigationService uriNavigationService) : ActionBase
{
private readonly ILogger<OpenClassSwapWindowAction> _logger = logger;
private readonly IUriNavigationService _uriNavigationService = uriNavigationService;

protected override Task OnInvoke()
{
_logger.LogInformation("正在打开 ClassIsland 换课窗口");
_uriNavigationService.NavigateWrapped(new Uri("classisland://app/class-swap"));
return base.OnInvoke();
}
}
24 changes: 24 additions & 0 deletions Actions/OpenProfileEditorAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using ClassIsland.Core.Abstractions.Automation;
using ClassIsland.Core.Abstractions.Services;
using ClassIsland.Core.Attributes;
using Microsoft.Extensions.Logging;
using System;
using System.Threading.Tasks;

namespace SystemTools.Actions;

[ActionInfo("SystemTools.OpenProfileEditor", "打开档案编辑", "\uE699", false)]
public class OpenProfileEditorAction(
ILogger<OpenProfileEditorAction> logger,
IUriNavigationService uriNavigationService) : ActionBase
{
private readonly ILogger<OpenProfileEditorAction> _logger = logger;
private readonly IUriNavigationService _uriNavigationService = uriNavigationService;

protected override Task OnInvoke()
{
_logger.LogInformation("正在打开 ClassIsland 档案编辑窗口");
_uriNavigationService.NavigateWrapped(new Uri("classisland://app/profile"));
return base.OnInvoke();
}
}
45 changes: 45 additions & 0 deletions Actions/ShowDesktopAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using ClassIsland.Core.Abstractions.Automation;
using ClassIsland.Core.Attributes;
using Microsoft.Extensions.Logging;
using System;
using System.Threading.Tasks;
using Windows.Win32;
using Windows.Win32.UI.Input.KeyboardAndMouse;

namespace SystemTools.Actions;

[ActionInfo("SystemTools.ShowDesktop", "显示桌面", "\uE62F", false)]
public class ShowDesktopAction(ILogger<ShowDesktopAction> logger) : ActionBase
{
private readonly ILogger<ShowDesktopAction> _logger = logger;

private const byte VK_LWIN = 0x5B;
private const byte VK_D = 0x44;

protected override async Task OnInvoke()
{
try
{
_logger.LogInformation("正在模拟按下 Win+D 显示桌面");

PInvoke.keybd_event(VK_LWIN, 0, 0, UIntPtr.Zero);
await Task.Delay(20);

PInvoke.keybd_event(VK_D, 0, 0, UIntPtr.Zero);
Comment on lines +25 to +28
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 Make Show Desktop action one-way instead of toggle

This sends Win+D, which toggles the desktop state rather than always revealing it, so if the action runs while the desktop is already shown (for example via repeated automation) it will restore all previously open windows and undo the intended outcome. For an action named ShowDesktop, this non-idempotent behavior is surprising and can break automations; use a one-way minimize-all approach instead.

Useful? React with 👍 / 👎.

await Task.Delay(20);

PInvoke.keybd_event(VK_D, 0, KEYBD_EVENT_FLAGS.KEYEVENTF_KEYUP, UIntPtr.Zero);
await Task.Delay(20);

PInvoke.keybd_event(VK_LWIN, 0, KEYBD_EVENT_FLAGS.KEYEVENTF_KEYUP, UIntPtr.Zero);
_logger.LogInformation("Win+D 已成功发送");
}
catch (Exception ex)
{
_logger.LogError(ex, "发送 Win+D 失败");
throw;
}

await base.OnInvoke();
}
}
13 changes: 6 additions & 7 deletions Controls/Components/BetterCarouselContainerComponent.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using Avalonia.Controls;
using Avalonia.Media;
using Avalonia.Styling;
using Avalonia.Threading;
using Avalonia.VisualTree;
using ClassIsland.Core.Abstractions.Controls;
using ClassIsland.Core.Abstractions.Services;
Expand All @@ -23,7 +22,7 @@ namespace SystemTools.Controls.Components;
[ComponentInfo("A7C3455E-6A4E-4D4D-9D0D-7C6FCB5E1E3A", "更好的轮播容器", "\uF0DB", "带有可单独设置组件显示时长等高级功能的轮播容器")]
public partial class BetterCarouselContainerComponent : ComponentBase<BetterCarouselContainerSettings>, INotifyPropertyChanged
{
private readonly DispatcherTimer _timer = new() { Interval = TimeSpan.FromMilliseconds(100) };
private readonly ILessonsService _lessonsService;
private readonly IRulesetService _rulesetService;
private readonly Random _random = new();

Expand Down Expand Up @@ -83,12 +82,12 @@ public int SelectedIndex

public new event PropertyChangedEventHandler? PropertyChanged;

public BetterCarouselContainerComponent(IRulesetService rulesetService)
public BetterCarouselContainerComponent(IRulesetService rulesetService, ILessonsService lessonsService)
{
_rulesetService = rulesetService;
_lessonsService = lessonsService;
InitializeComponent();
InitializeAnimations();
_timer.Tick += OnTimerTick;
}

private void InitializeAnimations()
Expand Down Expand Up @@ -338,11 +337,11 @@ private void BetterCarouselContainerComponent_OnAttachedToVisualTree(object? sen
Settings.Children.CollectionChanged += OnChildrenCollectionChanged;
Settings.ComponentDisplayDurations.CollectionChanged += OnDurationCollectionChanged;
_rulesetService.StatusUpdated += OnRulesetStatusUpdated;
_lessonsService.PreMainTimerTicked += OnLessonsServicePreMainTimerTicked;
SubscribeChildren(Settings.Children);
Settings.NormalizeDisplayDurations();
EnsureSelectedIndexValid();
UpdateProgressState();
_timer.Start();
}

private void BetterCarouselContainerComponent_OnDetachedFromVisualTree(object? sender, VisualTreeAttachmentEventArgs e)
Expand All @@ -353,15 +352,15 @@ private void BetterCarouselContainerComponent_OnDetachedFromVisualTree(object? s
}

_isLoaded = false;
_timer.Stop();
Settings.PropertyChanged -= OnSettingsPropertyChanged;
Settings.Children.CollectionChanged -= OnChildrenCollectionChanged;
Settings.ComponentDisplayDurations.CollectionChanged -= OnDurationCollectionChanged;
_rulesetService.StatusUpdated -= OnRulesetStatusUpdated;
_lessonsService.PreMainTimerTicked -= OnLessonsServicePreMainTimerTicked;
UnsubscribeChildren(Settings.Children);
}

private void OnTimerTick(object? sender, EventArgs e)
private void OnLessonsServicePreMainTimerTicked(object? sender, EventArgs e)
{
UpdateProgressState();
}
Expand Down
Loading
Loading