diff --git a/Lib.Audio/Controllable.cs b/Lib.Audio/Controllable.cs index 0169b8b..6bc4c37 100644 --- a/Lib.Audio/Controllable.cs +++ b/Lib.Audio/Controllable.cs @@ -5,7 +5,6 @@ using System.Collections.Generic; using System.Linq; using Lib.Audio.Interfaces; -using Lib.ProcessManaging.Interfaces; using NAudio.CoreAudioApi; namespace Lib.Audio @@ -14,15 +13,24 @@ namespace Lib.Audio { private readonly List _audioSessionControls; - public Controllable(List audioSessionControls, IObservedProcess? process, string name) + public Controllable(List audioSessionControls, string executablePath, string name) { _audioSessionControls = audioSessionControls; - Process = process; + ExecutablePath = executablePath; Name = name; } + public Controllable(string executablePath) + { + IsValid = false; + + ExecutablePath = executablePath; + Name = ""; + _audioSessionControls = new List(); + } + public bool IsValid { get; set; } = true; - public IObservedProcess? Process { get; } + public string ExecutablePath { get; } public string Name { get; } public string? IconPath => _audioSessionControls.FirstOrDefault(c => !string.IsNullOrEmpty(c.IconPath))?.IconPath; //FixMe diff --git a/Lib.Audio/ControllableCollector.cs b/Lib.Audio/ControllableCollector.cs index 45c8a21..3708d34 100644 --- a/Lib.Audio/ControllableCollector.cs +++ b/Lib.Audio/ControllableCollector.cs @@ -7,6 +7,7 @@ using System.Collections.Generic; using System.Linq; using Lib.Audio.Factories; using Lib.Audio.Interfaces; +using Lib.Logging; using Lib.ProcessManaging.Interfaces; using NAudio.CoreAudioApi; using NAudio.CoreAudioApi.Interfaces; @@ -26,8 +27,8 @@ namespace Lib.Audio public List Controllables => CreateControllables(); - public IControllable? GetControllableForProcess(IObservedProcess process) => - Controllables.FirstOrDefault(c => c.Process != null && c.Process.IsSameExecutable(process)); + public IControllable? GetControllableForExecutable(string executablePath) => + Controllables.FirstOrDefault(c => c.ExecutablePath.Equals(executablePath)); private List CreateControllables() { @@ -74,8 +75,14 @@ namespace Lib.Audio name = process.Name; else name = id; + + if (process == null) + { + Log.Write($"Could not find process for session id {id}."); + continue; + } - controllables.Add(_controllableFactory.Create(idSessions, process, name)); + controllables.Add(_controllableFactory.Create(idSessions, process.FileName, name)); } return controllables; diff --git a/Lib.Audio/Factories/IControllableFactory.cs b/Lib.Audio/Factories/IControllableFactory.cs index 36ff770..e42a7fb 100644 --- a/Lib.Audio/Factories/IControllableFactory.cs +++ b/Lib.Audio/Factories/IControllableFactory.cs @@ -4,14 +4,15 @@ using System.Collections.Generic; using Lib.Audio.Interfaces; -using Lib.ProcessManaging.Interfaces; using NAudio.CoreAudioApi; namespace Lib.Audio.Factories { public interface IControllableFactory { - IControllable Create(List audioSessionControls, IObservedProcess? process, string name); + IControllable Create(List audioSessionControls, string executablePath, string name); + IControllable Create(string executablePath); + IMasterControllable Create(AudioEndpointVolume audioEndpointVolume, string name); } } \ No newline at end of file diff --git a/Lib.Audio/Interfaces/IControllable.cs b/Lib.Audio/Interfaces/IControllable.cs index 421f8fc..93fd0f8 100644 --- a/Lib.Audio/Interfaces/IControllable.cs +++ b/Lib.Audio/Interfaces/IControllable.cs @@ -2,14 +2,12 @@ // Created: 2021-04-07 // Copyright(c) 2021 SimonG. All Rights Reserved. -using Lib.ProcessManaging.Interfaces; - namespace Lib.Audio.Interfaces { public interface IControllable { bool IsValid { get; set; } - IObservedProcess? Process { get; } + string ExecutablePath { get; } string Name { get; } string? IconPath { get; } diff --git a/Lib.Audio/Interfaces/IControllableCollector.cs b/Lib.Audio/Interfaces/IControllableCollector.cs index 91782e8..d97bfcc 100644 --- a/Lib.Audio/Interfaces/IControllableCollector.cs +++ b/Lib.Audio/Interfaces/IControllableCollector.cs @@ -3,7 +3,6 @@ // Copyright(c) 2021 SimonG. All Rights Reserved. using System.Collections.Generic; -using Lib.ProcessManaging.Interfaces; namespace Lib.Audio.Interfaces { @@ -11,6 +10,6 @@ namespace Lib.Audio.Interfaces { List Controllables { get; } - IControllable? GetControllableForProcess(IObservedProcess process); + IControllable? GetControllableForExecutable(string executablePath); } } \ No newline at end of file diff --git a/Lib.Audio/MasterControllable.cs b/Lib.Audio/MasterControllable.cs index aa7f34b..e13981b 100644 --- a/Lib.Audio/MasterControllable.cs +++ b/Lib.Audio/MasterControllable.cs @@ -3,7 +3,6 @@ // Copyright(c) 2021 SimonG. All Rights Reserved. using Lib.Audio.Interfaces; -using Lib.ProcessManaging.Interfaces; using NAudio.CoreAudioApi; namespace Lib.Audio @@ -21,7 +20,7 @@ namespace Lib.Audio } public bool IsValid { get; set; } - public IObservedProcess? Process { get; } + public string ExecutablePath { get; } = ""; public string Name { get; } public string? IconPath => null;