Skip to content
This repository was archived by the owner on Jul 24, 2025. It is now read-only.

Commit 06a3708

Browse files
Fix #999
1 parent 90e5775 commit 06a3708

File tree

11 files changed

+153
-2
lines changed

11 files changed

+153
-2
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System.Threading.Tasks;
2+
using Newtonsoft.Json;
3+
4+
namespace LenovoLegionToolkit.Lib.Automation.Steps;
5+
6+
public class NotificationAutomationStep : IAutomationStep
7+
{
8+
public string? Text { get; }
9+
10+
[JsonConstructor]
11+
public NotificationAutomationStep(string? text)
12+
{
13+
Text = text;
14+
}
15+
16+
public Task<bool> IsSupportedAsync() => Task.FromResult(true);
17+
18+
public Task RunAsync(AutomationEnvironment environment)
19+
{
20+
if (!string.IsNullOrWhiteSpace(Text))
21+
MessagingCenter.Publish(new Notification(NotificationType.AutomationNotification, Text));
22+
return Task.CompletedTask;
23+
}
24+
25+
IAutomationStep IAutomationStep.DeepCopy() => new NotificationAutomationStep(Text);
26+
}

LenovoLegionToolkit.Lib/Enums.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ public enum NotificationType
211211
ACAdapterConnected,
212212
ACAdapterConnectedLowWattage,
213213
ACAdapterDisconnected,
214+
AutomationNotification,
214215
CameraOn,
215216
CameraOff,
216217
CapsLockOn,

LenovoLegionToolkit.Lib/Settings/ApplicationSettings.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public class Notifications
1919
public bool RefreshRate { get; set; } = true;
2020
public bool ACAdapter { get; set; }
2121
public bool SmartKey { get; set; }
22+
public bool AutomationNotification { get; set; } = true;
2223
}
2324

2425
public class ApplicationSettingsStore

LenovoLegionToolkit.WPF/Controls/Automation/AutomationPipelineControl.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ private async Task<AbstractAutomationStepControl> GenerateStepControlAsync(IAuto
326326
HybridModeAutomationStep s => await HybridModeAutomationStepControlFactory.GetControlAsync(s),
327327
InstantBootAutomationStep s => new InstantBootAutomationStepControl(s),
328328
MicrophoneAutomationStep s => new MicrophoneAutomationStepControl(s),
329+
NotificationAutomationStep s => new NotificationAutomationStepControl(s),
329330
OneLevelWhiteKeyboardBacklightAutomationStep s => new OneLevelWhiteKeyboardBacklightAutomationStepControl(s),
330331
OverDriveAutomationStep s => new OverDriveAutomationStepControl(s),
331332
OverclockDiscreteGPUAutomationStep s => new OverclockDiscreteGPUAutomationStepControl(s),
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
using System.Threading.Tasks;
2+
using System.Windows;
3+
using System.Windows.Controls;
4+
using LenovoLegionToolkit.Lib.Automation.Steps;
5+
using LenovoLegionToolkit.WPF.Resources;
6+
using Wpf.Ui.Common;
7+
using TextBox = Wpf.Ui.Controls.TextBox;
8+
9+
namespace LenovoLegionToolkit.WPF.Controls.Automation.Steps;
10+
11+
public class NotificationAutomationStepControl : AbstractAutomationStepControl<NotificationAutomationStep>
12+
{
13+
private readonly TextBox _scriptPath = new()
14+
{
15+
PlaceholderText = Resource.NotificationAutomationStepControl_NotificationText,
16+
Width = 300
17+
};
18+
19+
private readonly StackPanel _stackPanel = new();
20+
21+
public NotificationAutomationStepControl(NotificationAutomationStep step) : base(step)
22+
{
23+
Icon = SymbolRegular.Rocket24;
24+
Title = Resource.NotificationAutomationStepControl_Title;
25+
26+
SizeChanged += RunAutomationStepControl_SizeChanged;
27+
}
28+
29+
private void RunAutomationStepControl_SizeChanged(object sender, SizeChangedEventArgs e)
30+
{
31+
if (!e.WidthChanged)
32+
return;
33+
34+
var newWidth = e.NewSize.Width / 3;
35+
_scriptPath.Width = newWidth;
36+
}
37+
38+
public override IAutomationStep CreateAutomationStep() => new NotificationAutomationStep(_scriptPath.Text);
39+
40+
protected override UIElement GetCustomControl()
41+
{
42+
_scriptPath.TextChanged += (_, _) =>
43+
{
44+
if (_scriptPath.Text != AutomationStep.Text)
45+
RaiseChanged();
46+
};
47+
48+
_stackPanel.Children.Add(_scriptPath);
49+
50+
return _stackPanel;
51+
}
52+
53+
protected override void OnFinishedLoading() { }
54+
55+
protected override Task RefreshAsync()
56+
{
57+
_scriptPath.Text = AutomationStep.Text;
58+
return Task.CompletedTask;
59+
}
60+
}

LenovoLegionToolkit.WPF/Pages/AutomationPage.xaml.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ private static async Task<IAutomationStep[]> GetSupportedAutomationStepsAsync()
172172
new HDRAutomationStep(default),
173173
new InstantBootAutomationStep(default),
174174
new MicrophoneAutomationStep(default),
175+
new NotificationAutomationStep(default),
175176
new OneLevelWhiteKeyboardBacklightAutomationStep(default),
176177
new OverclockDiscreteGPUAutomationStep(default),
177178
new OverDriveAutomationStep(default),

LenovoLegionToolkit.WPF/Resources/Resource.Designer.cs

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

LenovoLegionToolkit.WPF/Resources/Resource.resx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1919,4 +1919,13 @@ Requires restart.</value>
19191919
<data name="BootLogoWindow_Customize" xml:space="preserve">
19201920
<value>Customize</value>
19211921
</data>
1922+
<data name="NotificationsSettingsWindow_Automation" xml:space="preserve">
1923+
<value>Actions</value>
1924+
</data>
1925+
<data name="NotificationAutomationStepControl_NotificationText" xml:space="preserve">
1926+
<value>Notification Text</value>
1927+
</data>
1928+
<data name="NotificationAutomationStepControl_Title" xml:space="preserve">
1929+
<value>Show notification</value>
1930+
</data>
19221931
</root>

LenovoLegionToolkit.WPF/Utils/NotificationsManager.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ private void OnNotificationReceived(Notification notification)
5757
NotificationType.ACAdapterConnected => _settings.Store.Notifications.ACAdapter,
5858
NotificationType.ACAdapterConnectedLowWattage => _settings.Store.Notifications.ACAdapter,
5959
NotificationType.ACAdapterDisconnected => _settings.Store.Notifications.ACAdapter,
60+
NotificationType.AutomationNotification => _settings.Store.Notifications.AutomationNotification,
6061
NotificationType.CapsLockOn => _settings.Store.Notifications.CapsNumLock,
6162
NotificationType.CapsLockOff => _settings.Store.Notifications.CapsNumLock,
6263
NotificationType.CameraOn => _settings.Store.Notifications.CameraLock,
@@ -104,6 +105,7 @@ private void OnNotificationReceived(Notification notification)
104105
NotificationType.ACAdapterConnected => SymbolRegular.BatteryCharge24,
105106
NotificationType.ACAdapterConnectedLowWattage => SymbolRegular.BatteryCharge24,
106107
NotificationType.ACAdapterDisconnected => SymbolRegular.BatteryCharge24,
108+
NotificationType.AutomationNotification => SymbolRegular.Rocket24,
107109
NotificationType.CapsLockOn => SymbolRegular.KeyboardShiftUppercase24,
108110
NotificationType.CapsLockOff => SymbolRegular.KeyboardShiftUppercase24,
109111
NotificationType.CameraOn => SymbolRegular.Camera24,
@@ -160,6 +162,7 @@ private void OnNotificationReceived(Notification notification)
160162
NotificationType.ACAdapterConnected => Resource.Notification_ACAdapterConnected,
161163
NotificationType.ACAdapterConnectedLowWattage => Resource.Notification_ACAdapterConnectedLowWattage,
162164
NotificationType.ACAdapterDisconnected => Resource.Notification_ACAdapterDisconnected,
165+
NotificationType.AutomationNotification => string.Format("{0}", notification.Args),
163166
NotificationType.CapsLockOn => Resource.Notification_CapsLockOn,
164167
NotificationType.CapsLockOff => Resource.Notification_CapsLockOff,
165168
NotificationType.CameraOn => Resource.Notification_CameraOn,

LenovoLegionToolkit.WPF/Windows/Settings/NotificationsSettingsWindow.xaml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
SelectionChanged="NotificationDurationComboBox_SelectionChanged" />
8585
</wpfui:CardControl>
8686

87-
<wpfui:CardControl x:Name="_updateAvailableCard" Margin="0,0,0,24">
87+
<wpfui:CardControl x:Name="_updateAvailableCard" Margin="0,0,0,8">
8888
<wpfui:CardControl.Header>
8989
<controls:CardHeaderControl Title="{x:Static resources:Resource.NotificationsSettingsWindow_Updates_Title}" />
9090
</wpfui:CardControl.Header>
@@ -94,6 +94,16 @@
9494
Click="UpdateAvailableToggle_Click" />
9595
</wpfui:CardControl>
9696

97+
<wpfui:CardControl x:Name="_automationCard" Margin="0,0,0,24">
98+
<wpfui:CardControl.Header>
99+
<controls:CardHeaderControl Title="{x:Static resources:Resource.NotificationsSettingsWindow_Automation}" />
100+
</wpfui:CardControl.Header>
101+
<wpfui:ToggleSwitch
102+
x:Name="_automationToggle"
103+
Margin="0,0,0,8"
104+
Click="AutomationToggle_Click" />
105+
</wpfui:CardControl>
106+
97107
<wpfui:CardControl x:Name="_capsNumLockCard" Margin="0,0,0,8">
98108
<wpfui:CardControl.Header>
99109
<controls:CardHeaderControl Title="{x:Static resources:Resource.NotificationsSettingsWindow_CapsAndNumLock}" />

0 commit comments

Comments
 (0)