-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPluginIntegration.cs
More file actions
62 lines (52 loc) · 1.9 KB
/
Copy pathPluginIntegration.cs
File metadata and controls
62 lines (52 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using MacroDeck.Sdk;
using MacroDeck.Sdk.Actions;
using MacroDeck.Sdk.ConfigFlow;
using Serilog;
using SoundBox.Actions;
using SoundBox.Audio;
using SoundBox.ConfigFlow;
namespace SoundBox;
public sealed class PluginIntegration : IPluginIntegration, IConfigFlowProvider, IDisposable
{
private readonly AudioManager _audioManager;
private readonly ILogger _logger;
public PluginIntegration(ILogger logger)
{
_logger = logger.ForContext<PluginIntegration>();
_audioManager = new AudioManager(logger);
Actions =
[
new PlaySoundAction(_audioManager, logger),
new StopSoundAction(_audioManager, logger)
];
}
public IReadOnlyList<IActionDefinition> Actions { get; }
public async Task InitializeAsync(IIntegrationContext context)
{
var entries = await context.Config.GetEntriesAsync();
if (entries.Count == 0)
{
return;
}
var entry = entries[0];
var deviceId = await context.Config.GetStringAsync(entry.Id, MonitorSettingsFlow.MonitorDeviceIdField);
var volume = await context.Config.GetStringAsync(entry.Id, MonitorSettingsFlow.MonitorVolumeField);
_audioManager.SetMonitorSettings(
deviceId,
int.TryParse(volume, out var parsedVolume) ? parsedVolume : 100);
}
public Task ShutdownAsync()
{
_audioManager.Dispose();
return Task.CompletedTask;
}
public bool AllowsMultipleConfigurations => false;
public IConfigFlow CreateConfigFlow()
{
_logger.Information("[SoundBox-Config] Reconfigure requested");
_logger.Information("[SoundBox-Config] Creating fresh configuration");
_logger.Information("[SoundBox-Config] Configuration initialized successfully");
return new MonitorSettingsFlow(_audioManager, _logger);
}
public void Dispose() => _audioManager.Dispose();
}