Skip to content

Commit

Permalink
Fix #653
Browse files Browse the repository at this point in the history
  • Loading branch information
BartoszCichecki committed Apr 24, 2023
1 parent f1b6b01 commit baad4fe
Show file tree
Hide file tree
Showing 30 changed files with 189 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public abstract class AbstractFeatureAutomationStep<T> : IAutomationStep<T> wher

public T State { get; }

public AbstractFeatureAutomationStep(T state) => State = state;
protected AbstractFeatureAutomationStep(T state) => State = state;

public Task<bool> IsSupportedAsync() => _feature.IsSupportedAsync();

Expand All @@ -24,4 +24,4 @@ public virtual async Task RunAsync()
public Task<T[]> GetAllStatesAsync() => _feature.GetAllStatesAsync();

public abstract IAutomationStep DeepCopy();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ public class AlwaysOnUsbAutomationStep : AbstractFeatureAutomationStep<AlwaysOnU
public AlwaysOnUsbAutomationStep(AlwaysOnUSBState state) : base(state) { }

public override IAutomationStep DeepCopy() => new AlwaysOnUsbAutomationStep(State);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ public class BatteryAutomationStep : AbstractFeatureAutomationStep<BatteryState>
public BatteryAutomationStep(BatteryState state) : base(state) { }

public override IAutomationStep DeepCopy() => new BatteryAutomationStep(State);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ public async Task RunAsync()
}

IAutomationStep IAutomationStep.DeepCopy() => new DeactivateGPUAutomationStep(State);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ public class DelayAutomationStep : IAutomationStep<Delay>
public IAutomationStep DeepCopy() => new DelayAutomationStep(State);

public Task RunAsync() => Task.Delay(TimeSpan.FromSeconds(State.DelaySeconds));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ public Task RunAsync()
}

IAutomationStep IAutomationStep.DeepCopy() => new DisplayBrightnessAutomationStep(Brightness);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ public class DpiScaleAutomationStep : AbstractFeatureAutomationStep<DpiScale>
public DpiScaleAutomationStep(DpiScale state) : base(state) { }

public override IAutomationStep DeepCopy() => new DpiScaleAutomationStep(State);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ public class FlipToStartAutomationStep : AbstractFeatureAutomationStep<FlipToSta
public FlipToStartAutomationStep(FlipToStartState state) : base(state) { }

public override IAutomationStep DeepCopy() => new FlipToStartAutomationStep(State);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ public class FnLockAutomationStep : AbstractFeatureAutomationStep<FnLockState>
public FnLockAutomationStep(FnLockState state) : base(state) { }

public override IAutomationStep DeepCopy() => new FnLockAutomationStep(State);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ public async Task RunAsync()
}

public IAutomationStep DeepCopy() => new GodModePresetAutomationStep(PresetId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ public class HDRAutomationStep : AbstractFeatureAutomationStep<HDRState>
public HDRAutomationStep(HDRState state) : base(state) { }

public override IAutomationStep DeepCopy() => new HDRAutomationStep(State);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ public interface IAutomationStep<T> : IAutomationStep where T : struct
T State { get; }

Task<T[]> GetAllStatesAsync();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ public class OverDriveAutomationStep : AbstractFeatureAutomationStep<OverDriveSt
public OverDriveAutomationStep(OverDriveState state) : base(state) { }

public override IAutomationStep DeepCopy() => new OverDriveAutomationStep(State);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ public class PowerModeAutomationStep : AbstractFeatureAutomationStep<PowerModeSt
public PowerModeAutomationStep(PowerModeState state) : base(state) { }

public override IAutomationStep DeepCopy() => new PowerModeAutomationStep(State);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ public async Task RunAsync()
}

IAutomationStep IAutomationStep.DeepCopy() => new RGBKeyboardBacklightAutomationStep(State);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ public class RefreshRateAutomationStep : AbstractFeatureAutomationStep<RefreshRa
public RefreshRateAutomationStep(RefreshRate state) : base(state) { }

public override IAutomationStep DeepCopy() => new RefreshRateAutomationStep(State);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ public class ResolutionAutomationStep : AbstractFeatureAutomationStep<Resolution
public ResolutionAutomationStep(Resolution state) : base(state) { }

public override IAutomationStep DeepCopy() => new ResolutionAutomationStep(State);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ public async Task RunAsync()
}

IAutomationStep IAutomationStep.DeepCopy() => new RunAutomationStep(ScriptPath, ScriptArguments);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Linq;
using System.Threading.Tasks;
using LenovoLegionToolkit.Lib.Controllers;
using Newtonsoft.Json;

namespace LenovoLegionToolkit.Lib.Automation.Steps;

Expand All @@ -13,6 +14,7 @@ public class SpectrumKeyboardBacklightBrightnessAutomationStep : IAutomationStep

public int State { get; }

[JsonConstructor]
public SpectrumKeyboardBacklightBrightnessAutomationStep(int state) => State = state;

public Task<int[]> GetAllStatesAsync() => Task.FromResult(_allStates);
Expand All @@ -31,4 +33,4 @@ public async Task RunAsync()
}

public IAutomationStep DeepCopy() => new SpectrumKeyboardBacklightBrightnessAutomationStep(State);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System.Threading.Tasks;
using LenovoLegionToolkit.Lib.Controllers;
using Newtonsoft.Json;

namespace LenovoLegionToolkit.Lib.Automation.Steps;

public class SpectrumKeyboardBacklightImportProfileAutomationStep : IAutomationStep
{
private readonly SpectrumKeyboardBacklightController _controller = IoCContainer.Resolve<SpectrumKeyboardBacklightController>();

public string? Path { get; }

[JsonConstructor]
public SpectrumKeyboardBacklightImportProfileAutomationStep(string? path)
{
Path = path;
}

public Task<bool> IsSupportedAsync() => _controller.IsSupportedAsync();

public async Task RunAsync()
{
if (Path is null || !await _controller.IsSupportedAsync().ConfigureAwait(false))
return;

var profile = await _controller.GetProfileAsync().ConfigureAwait(false);
await _controller.ImportProfileDescription(profile, Path).ConfigureAwait(false);
}

IAutomationStep IAutomationStep.DeepCopy() => new SpectrumKeyboardBacklightImportProfileAutomationStep(Path);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Linq;
using System.Threading.Tasks;
using LenovoLegionToolkit.Lib.Controllers;
using Newtonsoft.Json;

namespace LenovoLegionToolkit.Lib.Automation.Steps;

Expand All @@ -13,6 +14,7 @@ public class SpectrumKeyboardBacklightProfileAutomationStep : IAutomationStep<in

public int State { get; }

[JsonConstructor]
public SpectrumKeyboardBacklightProfileAutomationStep(int state) => State = state;

public Task<int[]> GetAllStatesAsync() => Task.FromResult(_allStates);
Expand All @@ -31,4 +33,4 @@ public async Task RunAsync()
}

public IAutomationStep DeepCopy() => new SpectrumKeyboardBacklightProfileAutomationStep(State);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ public class TouchpadLockAutomationStep : AbstractFeatureAutomationStep<Touchpad
public TouchpadLockAutomationStep(TouchpadLockState state) : base(state) { }

public override IAutomationStep DeepCopy() => new TouchpadLockAutomationStep(State);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ public class WhiteKeyboardBacklightAutomationStep : AbstractFeatureAutomationSte
public WhiteKeyboardBacklightAutomationStep(WhiteKeyboardBacklightState state) : base(state) { }

public override IAutomationStep DeepCopy() => new WhiteKeyboardBacklightAutomationStep(State);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ public class WinKeyAutomationStep : AbstractFeatureAutomationStep<WinKeyState>
public WinKeyAutomationStep(WinKeyState state) : base(state) { }

public override IAutomationStep DeepCopy() => new WinKeyAutomationStep(State);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ private AbstractAutomationStepControl GenerateStepControl(IAutomationStep automa
RGBKeyboardBacklightAutomationStep s => new RGBKeyboardBacklightAutomationStepControl(s),
RunAutomationStep s => new RunAutomationStepControl(s),
SpectrumKeyboardBacklightBrightnessAutomationStep s => new SpectrumKeyboardBacklightBrightnessAutomationStepControl(s),
SpectrumKeyboardBacklightImportProfileAutomationStep s => new SpectrumKeyboardBacklightImportProfileAutomationStepControl(s),
SpectrumKeyboardBacklightProfileAutomationStep s => new SpectrumKeyboardBacklightProfileAutomationStepControl(s),
TurnOffMonitorsAutomationStep s => new TurnOffMonitorsAutomationStepControl(s),
TouchpadLockAutomationStep s => new TouchpadLockAutomationStepControl(s),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using LenovoLegionToolkit.Lib.Automation.Steps;
using LenovoLegionToolkit.WPF.Resources;
using Microsoft.Win32;
using Wpf.Ui.Common;
using Button = Wpf.Ui.Controls.Button;
using TextBox = Wpf.Ui.Controls.TextBox;

namespace LenovoLegionToolkit.WPF.Controls.Automation.Steps;

public class SpectrumKeyboardBacklightImportProfileAutomationStepControl : AbstractAutomationStepControl<SpectrumKeyboardBacklightImportProfileAutomationStep>
{
private readonly TextBox _path = new()
{
PlaceholderText = Resource.SpectrumKeyboardBacklightImportProfileAutomationStepControl_Path,
Width = 300
};

private readonly Button _openButton = new()
{
Icon = SymbolRegular.MoreHorizontal24,
MinWidth = 34,
Height = 34,
Margin = new(8, 0, 0, 0)
};

private readonly StackPanel _stackPanel = new()
{
Orientation = Orientation.Horizontal
};

public SpectrumKeyboardBacklightImportProfileAutomationStepControl(SpectrumKeyboardBacklightImportProfileAutomationStep step) : base(step)
{
Icon = SymbolRegular.BrightnessHigh24;
Title = Resource.SpectrumKeyboardBacklightImportProfileAutomationStepControl_Title;
Subtitle = Resource.SpectrumKeyboardBacklightImportProfileAutomationStepControl_Message;

SizeChanged += RunAutomationStepControl_SizeChanged;
}

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

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

public override IAutomationStep CreateAutomationStep() => new SpectrumKeyboardBacklightImportProfileAutomationStep(_path.Text);

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

_openButton.Click += (_, _) =>
{
var ofd = new OpenFileDialog
{
Title = Resource.Import,
InitialDirectory = "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}",
Filter = "Json Files (.json)|*.json",
CheckFileExists = true,
};
var result = ofd.ShowDialog();
if (!result.HasValue || !result.Value)
return;
_path.Text = ofd.FileName;
};

_stackPanel.Children.Add(_path);
_stackPanel.Children.Add(_openButton);

return _stackPanel;
}

protected override void OnFinishedLoading() { }

protected override Task RefreshAsync()
{
_path.Text = AutomationStep.Path;
return Task.CompletedTask;
}
}
2 changes: 0 additions & 2 deletions LenovoLegionToolkit.WPF/Controls/Packages/PackageControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@
TextTrimming="CharacterEllipsis" />
</StackPanel>



</StackPanel>

<TextBlock
Expand Down
1 change: 1 addition & 0 deletions LenovoLegionToolkit.WPF/Pages/AutomationPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ private async Task<IAutomationStep[]> GetSupportedAutomationStepsAsync()
new RunAutomationStep(default, default),
new SpectrumKeyboardBacklightBrightnessAutomationStep(0),
new SpectrumKeyboardBacklightProfileAutomationStep(1),
new SpectrumKeyboardBacklightImportProfileAutomationStep(default),
new TouchpadLockAutomationStep(default),
new TurnOffMonitorsAutomationStep(),
new WhiteKeyboardBacklightAutomationStep(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.

Loading

0 comments on commit baad4fe

Please sign in to comment.