-
-
Notifications
You must be signed in to change notification settings - Fork 262
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
60c33d8
commit 9913fda
Showing
6 changed files
with
143 additions
and
4 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
LenovoLegionToolkit.Lib.Automation/Steps/PlaySoundAutomationStep.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System.Media; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Newtonsoft.Json; | ||
|
||
namespace LenovoLegionToolkit.Lib.Automation.Steps; | ||
|
||
[method: JsonConstructor] | ||
public class PlaySoundAutomationStep(string? path) : IAutomationStep | ||
{ | ||
public string? Path { get; } = path; | ||
|
||
public Task<bool> IsSupportedAsync() => Task.FromResult(true); | ||
|
||
public Task RunAsync(AutomationContext context, AutomationEnvironment environment, CancellationToken token) | ||
{ | ||
if (Path is null) | ||
return Task.CompletedTask; | ||
|
||
return Task.Run(() => | ||
{ | ||
var player = new SoundPlayer(Path); | ||
player.PlaySync(); | ||
}, token); | ||
} | ||
|
||
public IAutomationStep DeepCopy() => new PlaySoundAutomationStep(Path); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
LenovoLegionToolkit.WPF/Controls/Automation/Steps/PlaySoundAutomationStepControl.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
using System.IO; | ||
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 Orientation = System.Windows.Controls.Orientation; | ||
|
||
namespace LenovoLegionToolkit.WPF.Controls.Automation.Steps; | ||
|
||
public class PlaySoundAutomationStepControl : AbstractAutomationStepControl<PlaySoundAutomationStep> | ||
{ | ||
private string? _path; | ||
|
||
private readonly TextBlock _titleTextBlock = new() | ||
{ | ||
VerticalAlignment = VerticalAlignment.Center, | ||
}; | ||
|
||
private readonly Button _openButton = new() | ||
{ | ||
Icon = SymbolRegular.Folder20, | ||
MinWidth = 34, | ||
Height = 34, | ||
Margin = new(8, 0, 0, 0) | ||
}; | ||
|
||
private readonly StackPanel _stackPanel = new() | ||
{ | ||
Orientation = Orientation.Horizontal | ||
}; | ||
|
||
public PlaySoundAutomationStepControl(PlaySoundAutomationStep automationStep) : base(automationStep) | ||
{ | ||
Icon = SymbolRegular.MusicNote2Play20; | ||
Title = Resource.PlaySoundAutomationStepControl_Title; | ||
Subtitle = Resource.PlaySoundAutomationStepControl_Message; | ||
} | ||
|
||
public override IAutomationStep CreateAutomationStep() | ||
{ | ||
return new PlaySoundAutomationStep(_path); | ||
} | ||
|
||
protected override UIElement? GetCustomControl() | ||
{ | ||
|
||
_openButton.Click += (_, _) => | ||
{ | ||
var ofd = new OpenFileDialog | ||
{ | ||
Title = Resource.Import, | ||
InitialDirectory = @"C:\Windows\Media", | ||
CheckFileExists = true, | ||
}; | ||
|
||
var result = ofd.ShowDialog() ?? false; | ||
if (!result) | ||
return; | ||
|
||
_path = ofd.FileName; | ||
_titleTextBlock.Text = Path.GetFileName(_path); | ||
|
||
RaiseChanged(); | ||
}; | ||
|
||
_stackPanel.Children.Add(_titleTextBlock); | ||
_stackPanel.Children.Add(_openButton); | ||
|
||
return _stackPanel; | ||
} | ||
|
||
protected override void OnFinishedLoading() { } | ||
|
||
protected override Task RefreshAsync() | ||
{ | ||
_path = AutomationStep.Path; | ||
_titleTextBlock.Text = Path.GetFileName(_path) ?? "-"; | ||
return Task.CompletedTask; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters