Skip to content

Commit

Permalink
Fix #999
Browse files Browse the repository at this point in the history
  • Loading branch information
BartoszCichecki committed Oct 21, 2023
1 parent 90e5775 commit 06a3708
Show file tree
Hide file tree
Showing 11 changed files with 153 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System.Threading.Tasks;
using Newtonsoft.Json;

namespace LenovoLegionToolkit.Lib.Automation.Steps;

public class NotificationAutomationStep : IAutomationStep
{
public string? Text { get; }

[JsonConstructor]
public NotificationAutomationStep(string? text)
{
Text = text;
}

public Task<bool> IsSupportedAsync() => Task.FromResult(true);

public Task RunAsync(AutomationEnvironment environment)
{
if (!string.IsNullOrWhiteSpace(Text))
MessagingCenter.Publish(new Notification(NotificationType.AutomationNotification, Text));
return Task.CompletedTask;
}

IAutomationStep IAutomationStep.DeepCopy() => new NotificationAutomationStep(Text);
}
1 change: 1 addition & 0 deletions LenovoLegionToolkit.Lib/Enums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ public enum NotificationType
ACAdapterConnected,
ACAdapterConnectedLowWattage,
ACAdapterDisconnected,
AutomationNotification,
CameraOn,
CameraOff,
CapsLockOn,
Expand Down
1 change: 1 addition & 0 deletions LenovoLegionToolkit.Lib/Settings/ApplicationSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class Notifications
public bool RefreshRate { get; set; } = true;
public bool ACAdapter { get; set; }
public bool SmartKey { get; set; }
public bool AutomationNotification { get; set; } = true;
}

public class ApplicationSettingsStore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ private async Task<AbstractAutomationStepControl> GenerateStepControlAsync(IAuto
HybridModeAutomationStep s => await HybridModeAutomationStepControlFactory.GetControlAsync(s),
InstantBootAutomationStep s => new InstantBootAutomationStepControl(s),
MicrophoneAutomationStep s => new MicrophoneAutomationStepControl(s),
NotificationAutomationStep s => new NotificationAutomationStepControl(s),
OneLevelWhiteKeyboardBacklightAutomationStep s => new OneLevelWhiteKeyboardBacklightAutomationStepControl(s),
OverDriveAutomationStep s => new OverDriveAutomationStepControl(s),
OverclockDiscreteGPUAutomationStep s => new OverclockDiscreteGPUAutomationStepControl(s),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using LenovoLegionToolkit.Lib.Automation.Steps;
using LenovoLegionToolkit.WPF.Resources;
using Wpf.Ui.Common;
using TextBox = Wpf.Ui.Controls.TextBox;

namespace LenovoLegionToolkit.WPF.Controls.Automation.Steps;

public class NotificationAutomationStepControl : AbstractAutomationStepControl<NotificationAutomationStep>
{
private readonly TextBox _scriptPath = new()
{
PlaceholderText = Resource.NotificationAutomationStepControl_NotificationText,
Width = 300
};

private readonly StackPanel _stackPanel = new();

public NotificationAutomationStepControl(NotificationAutomationStep step) : base(step)
{
Icon = SymbolRegular.Rocket24;
Title = Resource.NotificationAutomationStepControl_Title;

SizeChanged += RunAutomationStepControl_SizeChanged;
}

private void RunAutomationStepControl_SizeChanged(object sender, SizeChangedEventArgs e)
{
if (!e.WidthChanged)
return;

var newWidth = e.NewSize.Width / 3;
_scriptPath.Width = newWidth;
}

public override IAutomationStep CreateAutomationStep() => new NotificationAutomationStep(_scriptPath.Text);

protected override UIElement GetCustomControl()
{
_scriptPath.TextChanged += (_, _) =>
{
if (_scriptPath.Text != AutomationStep.Text)
RaiseChanged();
};

_stackPanel.Children.Add(_scriptPath);

return _stackPanel;
}

protected override void OnFinishedLoading() { }

protected override Task RefreshAsync()
{
_scriptPath.Text = AutomationStep.Text;
return Task.CompletedTask;
}
}
1 change: 1 addition & 0 deletions LenovoLegionToolkit.WPF/Pages/AutomationPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ private static async Task<IAutomationStep[]> GetSupportedAutomationStepsAsync()
new HDRAutomationStep(default),
new InstantBootAutomationStep(default),
new MicrophoneAutomationStep(default),
new NotificationAutomationStep(default),
new OneLevelWhiteKeyboardBacklightAutomationStep(default),
new OverclockDiscreteGPUAutomationStep(default),
new OverDriveAutomationStep(default),
Expand Down
27 changes: 27 additions & 0 deletions LenovoLegionToolkit.WPF/Resources/Resource.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions LenovoLegionToolkit.WPF/Resources/Resource.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1919,4 +1919,13 @@ Requires restart.</value>
<data name="BootLogoWindow_Customize" xml:space="preserve">
<value>Customize</value>
</data>
<data name="NotificationsSettingsWindow_Automation" xml:space="preserve">
<value>Actions</value>
</data>
<data name="NotificationAutomationStepControl_NotificationText" xml:space="preserve">
<value>Notification Text</value>
</data>
<data name="NotificationAutomationStepControl_Title" xml:space="preserve">
<value>Show notification</value>
</data>
</root>
3 changes: 3 additions & 0 deletions LenovoLegionToolkit.WPF/Utils/NotificationsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ private void OnNotificationReceived(Notification notification)
NotificationType.ACAdapterConnected => _settings.Store.Notifications.ACAdapter,
NotificationType.ACAdapterConnectedLowWattage => _settings.Store.Notifications.ACAdapter,
NotificationType.ACAdapterDisconnected => _settings.Store.Notifications.ACAdapter,
NotificationType.AutomationNotification => _settings.Store.Notifications.AutomationNotification,
NotificationType.CapsLockOn => _settings.Store.Notifications.CapsNumLock,
NotificationType.CapsLockOff => _settings.Store.Notifications.CapsNumLock,
NotificationType.CameraOn => _settings.Store.Notifications.CameraLock,
Expand Down Expand Up @@ -104,6 +105,7 @@ private void OnNotificationReceived(Notification notification)
NotificationType.ACAdapterConnected => SymbolRegular.BatteryCharge24,
NotificationType.ACAdapterConnectedLowWattage => SymbolRegular.BatteryCharge24,
NotificationType.ACAdapterDisconnected => SymbolRegular.BatteryCharge24,
NotificationType.AutomationNotification => SymbolRegular.Rocket24,
NotificationType.CapsLockOn => SymbolRegular.KeyboardShiftUppercase24,
NotificationType.CapsLockOff => SymbolRegular.KeyboardShiftUppercase24,
NotificationType.CameraOn => SymbolRegular.Camera24,
Expand Down Expand Up @@ -160,6 +162,7 @@ private void OnNotificationReceived(Notification notification)
NotificationType.ACAdapterConnected => Resource.Notification_ACAdapterConnected,
NotificationType.ACAdapterConnectedLowWattage => Resource.Notification_ACAdapterConnectedLowWattage,
NotificationType.ACAdapterDisconnected => Resource.Notification_ACAdapterDisconnected,
NotificationType.AutomationNotification => string.Format("{0}", notification.Args),
NotificationType.CapsLockOn => Resource.Notification_CapsLockOn,
NotificationType.CapsLockOff => Resource.Notification_CapsLockOff,
NotificationType.CameraOn => Resource.Notification_CameraOn,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
SelectionChanged="NotificationDurationComboBox_SelectionChanged" />
</wpfui:CardControl>

<wpfui:CardControl x:Name="_updateAvailableCard" Margin="0,0,0,24">
<wpfui:CardControl x:Name="_updateAvailableCard" Margin="0,0,0,8">
<wpfui:CardControl.Header>
<controls:CardHeaderControl Title="{x:Static resources:Resource.NotificationsSettingsWindow_Updates_Title}" />
</wpfui:CardControl.Header>
Expand All @@ -94,6 +94,16 @@
Click="UpdateAvailableToggle_Click" />
</wpfui:CardControl>

<wpfui:CardControl x:Name="_automationCard" Margin="0,0,0,24">
<wpfui:CardControl.Header>
<controls:CardHeaderControl Title="{x:Static resources:Resource.NotificationsSettingsWindow_Automation}" />
</wpfui:CardControl.Header>
<wpfui:ToggleSwitch
x:Name="_automationToggle"
Margin="0,0,0,8"
Click="AutomationToggle_Click" />
</wpfui:CardControl>

<wpfui:CardControl x:Name="_capsNumLockCard" Margin="0,0,0,8">
<wpfui:CardControl.Header>
<controls:CardHeaderControl Title="{x:Static resources:Resource.NotificationsSettingsWindow_CapsAndNumLock}" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public partial class NotificationsSettingsWindow
_powerModeCard,
_refreshRateCard,
_acAdapterCard,
_smartKeyCard
_smartKeyCard,
_automationCard
};

public NotificationsSettingsWindow()
Expand All @@ -51,6 +52,7 @@ public NotificationsSettingsWindow()
_refreshRateToggle.IsChecked = _settings.Store.Notifications.RefreshRate;
_acAdapterToggle.IsChecked = _settings.Store.Notifications.ACAdapter;
_smartKeyToggle.IsChecked = _settings.Store.Notifications.SmartKey;
_automationToggle.IsChecked = _settings.Store.Notifications.AutomationNotification;

RefreshCards();
}
Expand Down Expand Up @@ -202,4 +204,14 @@ private void UpdateAvailableToggle_Click(object sender, RoutedEventArgs e)
_settings.Store.Notifications.UpdateAvailable = state.Value;
_settings.SynchronizeStore();
}

private void AutomationToggle_Click(object sender, RoutedEventArgs e)
{
var state = _automationToggle.IsChecked;
if (state is null)
return;

_settings.Store.Notifications.AutomationNotification = state.Value;
_settings.SynchronizeStore();
}
}

0 comments on commit 06a3708

Please sign in to comment.