Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a55ef1f27e | ||
|
|
46fce20771 | ||
|
|
d28f421ea3 | ||
|
|
5aeefebc47 | ||
|
|
ca956f207b | ||
|
|
ad212e7416 | ||
|
|
8c63b93d09 | ||
|
|
6ba4854bd8 | ||
|
|
2be5b86b17 |
@@ -32,5 +32,5 @@ jobs:
|
||||
export PATH="$PATH:/root/.dotnet/tools"
|
||||
dotnet tool install -g vpk
|
||||
vpk [win] download gitea --channel win-x86 --repoUrl https://gitea.kaczorzoo.net/ckaczor/WorkIndicator
|
||||
vpk [win] pack --channel win-x64 -u WorkIndicator -v ${{ steps.version.outputs.version }} -p publish --packTitle "Work Indicator" --shortcuts StartMenuRoot --framework net10.0-x64-desktop
|
||||
vpk [win] upload gitea --channel win-x64 --repoUrl https://gitea.kaczorzoo.net/ckaczor/WorkIndicator --publish --releaseName "${{ steps.version.outputs.version }}" --token ${{ secrets.VPK_TOKEN }}
|
||||
vpk [win] pack --channel win-x86 -u WorkIndicator -v ${{ steps.version.outputs.version }} -p publish --packTitle "Work Indicator" --shortcuts StartMenuRoot --framework net10.0-x86-desktop
|
||||
vpk [win] upload gitea --channel win-x86 --repoUrl https://gitea.kaczorzoo.net/ckaczor/WorkIndicator --publish --releaseName "${{ steps.version.outputs.version }}" --token ${{ secrets.VPK_TOKEN }}
|
||||
@@ -0,0 +1,88 @@
|
||||
using NAudio.CoreAudioApi;
|
||||
using NAudio.CoreAudioApi.Interfaces;
|
||||
using Serilog;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace WorkIndicator.Audio;
|
||||
|
||||
internal class AudioDevice
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public delegate void AudioSessionsChangedDelegate();
|
||||
|
||||
public event AudioSessionsChangedDelegate AudioSessionsChanged;
|
||||
|
||||
public bool IsMuted { get; private set; }
|
||||
|
||||
public string FriendlyName { get; }
|
||||
|
||||
public Dictionary<string, AudioSession> Sessions { get; } = new();
|
||||
|
||||
public AudioDevice(MMDevice device)
|
||||
{
|
||||
_logger = Log.ForContext<AudioDevice>();
|
||||
|
||||
FriendlyName = device.DeviceFriendlyName;
|
||||
IsMuted = device.AudioEndpointVolume.Mute;
|
||||
|
||||
_logger.Information("AudioDevice: {name} {muted}", FriendlyName, IsMuted);
|
||||
|
||||
device.AudioEndpointVolume.OnVolumeNotification += AudioEndpointVolume_OnVolumeNotification;
|
||||
device.AudioSessionManager.OnSessionCreated += AudioSessionManager_OnSessionCreated;
|
||||
|
||||
device.AudioSessionManager.RefreshSessions();
|
||||
var sessions = device.AudioSessionManager.Sessions;
|
||||
|
||||
for (var i = 0; i < sessions.Count; i++)
|
||||
{
|
||||
SetupSession(sessions[i]);
|
||||
}
|
||||
}
|
||||
|
||||
private void AudioEndpointVolume_OnVolumeNotification(AudioVolumeNotificationData data)
|
||||
{
|
||||
_logger.Information("AudioEndpointVolume_OnVolumeNotification: {name} {muted}", FriendlyName, data.Muted);
|
||||
|
||||
IsMuted = data.Muted;
|
||||
|
||||
AudioSessionsChanged?.Invoke();
|
||||
}
|
||||
|
||||
private void AudioSessionManager_OnSessionCreated(object sender, IAudioSessionControl newSession)
|
||||
{
|
||||
var session = new AudioSessionControl(newSession);
|
||||
|
||||
_logger.Information("OnSessionCreated: {name}", session.GetSessionIdentifier);
|
||||
|
||||
SetupSession(session);
|
||||
}
|
||||
|
||||
private void SetupSession(AudioSessionControl session)
|
||||
{
|
||||
_logger.Information("SetupSession: {name}", session.GetSessionIdentifier);
|
||||
|
||||
var audioSession = new AudioSession(session, FriendlyName);
|
||||
|
||||
Sessions[session.GetSessionIdentifier] = audioSession;
|
||||
|
||||
audioSession.AudioSessionChanged += AudioSession_AudioSessionChanged;
|
||||
|
||||
AudioSessionsChanged?.Invoke();
|
||||
}
|
||||
|
||||
private void AudioSession_AudioSessionChanged(string id, AudioSessionState state)
|
||||
{
|
||||
_logger.Information("AudioSessionChanged: {id} {state}", id, state);
|
||||
|
||||
AudioSessionsChanged?.Invoke();
|
||||
|
||||
if (state == AudioSessionState.AudioSessionStateExpired)
|
||||
{
|
||||
Sessions.Remove(id);
|
||||
}
|
||||
}
|
||||
|
||||
public int ActiveSessionCount => Sessions.Values.Count(s => s.State == AudioSessionState.AudioSessionStateActive);
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
using NAudio.CoreAudioApi;
|
||||
using NAudio.CoreAudioApi.Interfaces;
|
||||
using Serilog;
|
||||
using System;
|
||||
|
||||
namespace WorkIndicator.Audio;
|
||||
|
||||
internal class AudioSession : IAudioSessionEventsHandler
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly AudioSessionControl _audioSessionControl;
|
||||
|
||||
public string Id { get; }
|
||||
public string FriendlyName { get; }
|
||||
|
||||
public delegate void AudioSessionChangedDelegate(string id, AudioSessionState state);
|
||||
|
||||
public event AudioSessionChangedDelegate AudioSessionChanged;
|
||||
|
||||
public AudioSession(AudioSessionControl audioSessionControl, string friendlyName)
|
||||
{
|
||||
_logger = Log.ForContext<AudioSession>();
|
||||
|
||||
_audioSessionControl = audioSessionControl;
|
||||
|
||||
Id = audioSessionControl.GetSessionIdentifier;
|
||||
FriendlyName = friendlyName;
|
||||
|
||||
audioSessionControl.RegisterEventClient(this);
|
||||
}
|
||||
|
||||
public AudioSessionState State => _audioSessionControl.State;
|
||||
|
||||
void IAudioSessionEventsHandler.OnVolumeChanged(float volume, bool isMuted)
|
||||
{
|
||||
_logger.Information("OnVolumeChanged: {name} {volume} {isMuted}", FriendlyName, volume, isMuted);
|
||||
}
|
||||
|
||||
void IAudioSessionEventsHandler.OnDisplayNameChanged(string displayName)
|
||||
{
|
||||
_logger.Information("OnDisplayNameChanged: {name}", displayName);
|
||||
}
|
||||
|
||||
void IAudioSessionEventsHandler.OnIconPathChanged(string iconPath)
|
||||
{
|
||||
_logger.Information("OnIconPathChanged: {path}", iconPath);
|
||||
}
|
||||
|
||||
void IAudioSessionEventsHandler.OnChannelVolumeChanged(uint channelCount, IntPtr newVolumes, uint channelIndex)
|
||||
{
|
||||
_logger.Information("OnChannelVolumeChanged: {channelCount} {newVolumes} {channelIndex}", channelCount, newVolumes, channelIndex);
|
||||
}
|
||||
|
||||
void IAudioSessionEventsHandler.OnGroupingParamChanged(ref Guid groupingId)
|
||||
{
|
||||
_logger.Information("OnGroupingParamChanged: {groupingId}", groupingId);
|
||||
}
|
||||
|
||||
void IAudioSessionEventsHandler.OnStateChanged(AudioSessionState state)
|
||||
{
|
||||
_logger.Information("OnStateChanged: {state}", state);
|
||||
|
||||
AudioSessionChanged?.Invoke(Id, state);
|
||||
}
|
||||
|
||||
void IAudioSessionEventsHandler.OnSessionDisconnected(AudioSessionDisconnectReason disconnectReason)
|
||||
{
|
||||
_logger.Information("OnSessionDisconnected: {disconnectReason}", disconnectReason);
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,16 @@
|
||||
using NAudio.CoreAudioApi;
|
||||
using NAudio.CoreAudioApi.Interfaces;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Serilog;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace WorkIndicator;
|
||||
namespace WorkIndicator.Audio;
|
||||
|
||||
internal enum MicrophoneStatus
|
||||
{
|
||||
NotUsed,
|
||||
UsedMuted,
|
||||
UsedNotMuted
|
||||
}
|
||||
|
||||
internal class AudioWatcher : IMMNotificationClient
|
||||
{
|
||||
@@ -12,9 +18,9 @@ internal class AudioWatcher : IMMNotificationClient
|
||||
private readonly MMDeviceEnumerator _deviceEnumerator = new();
|
||||
private readonly Dictionary<string, AudioDevice> _inputDevices = new();
|
||||
|
||||
public delegate void MicrophoneInUseChangedDelegate(bool microphoneInUse);
|
||||
public delegate void MicrophoneStatusChangedDelegate(MicrophoneStatus microphoneStatus);
|
||||
|
||||
public event MicrophoneInUseChangedDelegate MicrophoneInUseChanged;
|
||||
public event MicrophoneStatusChangedDelegate MicrophoneStatusChanged;
|
||||
|
||||
public void Start()
|
||||
{
|
||||
@@ -34,6 +40,25 @@ internal class AudioWatcher : IMMNotificationClient
|
||||
}
|
||||
}
|
||||
|
||||
public void LogState()
|
||||
{
|
||||
_logger.Information("---");
|
||||
|
||||
foreach (var inputDevicePair in _inputDevices)
|
||||
{
|
||||
_logger.Information("Device: {name} {muted}", inputDevicePair.Value.FriendlyName, inputDevicePair.Value.IsMuted);
|
||||
|
||||
foreach (var sessionPair in inputDevicePair.Value.Sessions)
|
||||
{
|
||||
var session = sessionPair.Value;
|
||||
|
||||
_logger.Information("Session: {id} {friendlyName} {state}", session.Id, session.FriendlyName, session.State);
|
||||
}
|
||||
}
|
||||
|
||||
_logger.Information("---");
|
||||
}
|
||||
|
||||
private void HandleAddedDevice(MMDevice captureDevice)
|
||||
{
|
||||
_logger.Information("Device added: {name}", captureDevice.DeviceFriendlyName);
|
||||
@@ -43,12 +68,12 @@ internal class AudioWatcher : IMMNotificationClient
|
||||
|
||||
_inputDevices[captureDevice.ID] = audioDevice;
|
||||
|
||||
MicrophoneInUseChanged?.Invoke(MicrophoneInUse());
|
||||
MicrophoneStatusChanged?.Invoke(GetMicrophoneStatus());
|
||||
}
|
||||
|
||||
private void AudioDevice_AudioSessionsChanged()
|
||||
{
|
||||
MicrophoneInUseChanged?.Invoke(MicrophoneInUse());
|
||||
MicrophoneStatusChanged?.Invoke(GetMicrophoneStatus());
|
||||
}
|
||||
|
||||
private void HandleRemovedDevice(string deviceId)
|
||||
@@ -57,7 +82,7 @@ internal class AudioWatcher : IMMNotificationClient
|
||||
|
||||
_inputDevices.Remove(deviceId);
|
||||
|
||||
MicrophoneInUseChanged?.Invoke(MicrophoneInUse());
|
||||
MicrophoneStatusChanged?.Invoke(GetMicrophoneStatus());
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
@@ -68,11 +93,15 @@ internal class AudioWatcher : IMMNotificationClient
|
||||
_deviceEnumerator.Dispose();
|
||||
}
|
||||
|
||||
public bool MicrophoneInUse()
|
||||
public MicrophoneStatus GetMicrophoneStatus()
|
||||
{
|
||||
var totalActiveSessionCount = _inputDevices.Sum(i => i.Value.ActiveSessionCount);
|
||||
foreach (var inputDevice in _inputDevices.Values)
|
||||
{
|
||||
if (inputDevice.ActiveSessionCount > 0)
|
||||
return inputDevice.IsMuted ? MicrophoneStatus.UsedMuted : MicrophoneStatus.UsedNotMuted;
|
||||
}
|
||||
|
||||
return totalActiveSessionCount > 0;
|
||||
return MicrophoneStatus.NotUsed;
|
||||
}
|
||||
|
||||
void IMMNotificationClient.OnDeviceStateChanged(string deviceId, DeviceState newState)
|
||||
-104
@@ -1,104 +0,0 @@
|
||||
using NAudio.CoreAudioApi;
|
||||
using NAudio.CoreAudioApi.Interfaces;
|
||||
using Serilog;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Windows.Threading;
|
||||
|
||||
namespace WorkIndicator;
|
||||
|
||||
internal class AudioDevice : IAudioSessionEventsHandler
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly MMDevice _device;
|
||||
private readonly Dispatcher _dispatcher;
|
||||
private readonly Dictionary<string, AudioSessionControl> _sessions = new();
|
||||
|
||||
public delegate void AudioSessionsChangedDelegate();
|
||||
|
||||
public event AudioSessionsChangedDelegate AudioSessionsChanged;
|
||||
|
||||
public AudioDevice(MMDevice device)
|
||||
{
|
||||
_logger = Log.ForContext<AudioDevice>();
|
||||
|
||||
_dispatcher = Dispatcher.CurrentDispatcher;
|
||||
|
||||
_device = device;
|
||||
|
||||
_device.AudioSessionManager.AudioSessionControl.RegisterEventClient(this);
|
||||
_device.AudioSessionManager.OnSessionCreated += AudioSessionManager_OnSessionCreated;
|
||||
|
||||
_device.AudioSessionManager.RefreshSessions();
|
||||
var sessions = _device.AudioSessionManager.Sessions;
|
||||
|
||||
for (var i = 0; i < sessions.Count; i++)
|
||||
{
|
||||
SetupSession(sessions[i]);
|
||||
}
|
||||
}
|
||||
|
||||
private void AudioSessionManager_OnSessionCreated(object sender, IAudioSessionControl newSession)
|
||||
{
|
||||
var session = new AudioSessionControl(newSession);
|
||||
|
||||
_logger.Information("OnSessionCreated: {name}", session.GetSessionIdentifier);
|
||||
|
||||
SetupSession(session);
|
||||
}
|
||||
|
||||
private void SetupSession(AudioSessionControl session)
|
||||
{
|
||||
_logger.Information("SetupSession: {name}", session.GetSessionIdentifier);
|
||||
|
||||
_sessions[session.GetSessionIdentifier] = session;
|
||||
session.RegisterEventClient(this);
|
||||
|
||||
AudioSessionsChanged?.Invoke();
|
||||
}
|
||||
|
||||
public int ActiveSessionCount => _sessions.Values.Count(s => s.State == AudioSessionState.AudioSessionStateActive);
|
||||
|
||||
void IAudioSessionEventsHandler.OnVolumeChanged(float volume, bool isMuted)
|
||||
{
|
||||
_dispatcher.Invoke(() => { Debug.WriteLine($"{_device.DeviceFriendlyName}: {volume} {isMuted} {_device.AudioEndpointVolume.Mute}"); });
|
||||
}
|
||||
|
||||
void IAudioSessionEventsHandler.OnDisplayNameChanged(string displayName)
|
||||
{
|
||||
_logger.Information("OnDisplayNameChanged: {name}", displayName);
|
||||
}
|
||||
|
||||
void IAudioSessionEventsHandler.OnIconPathChanged(string iconPath)
|
||||
{
|
||||
_logger.Information("OnIconPathChanged: {path}", iconPath);
|
||||
}
|
||||
|
||||
void IAudioSessionEventsHandler.OnChannelVolumeChanged(uint channelCount, IntPtr newVolumes, uint channelIndex)
|
||||
{
|
||||
_logger.Information("OnChannelVolumeChanged: {channelCount} {newVolumes} {channelIndex}", channelCount, newVolumes, channelIndex);
|
||||
}
|
||||
|
||||
void IAudioSessionEventsHandler.OnGroupingParamChanged(ref Guid groupingId)
|
||||
{
|
||||
_logger.Information("OnGroupingParamChanged: {groupingId}", groupingId);
|
||||
}
|
||||
|
||||
void IAudioSessionEventsHandler.OnStateChanged(AudioSessionState state)
|
||||
{
|
||||
_logger.Information("OnStateChanged: {state}", state);
|
||||
|
||||
AudioSessionsChanged?.Invoke();
|
||||
|
||||
if (state == AudioSessionState.AudioSessionStateExpired)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
void IAudioSessionEventsHandler.OnSessionDisconnected(AudioSessionDisconnectReason disconnectReason)
|
||||
{
|
||||
_logger.Information("OnSessionDisconnected: {disconnectReason}", disconnectReason);
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,13 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using Serilog;
|
||||
|
||||
namespace WorkIndicator.Delcom
|
||||
{
|
||||
public class StoplightIndicator : IDisposable
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public enum Light
|
||||
{
|
||||
Green,
|
||||
@@ -25,6 +28,8 @@ namespace WorkIndicator.Delcom
|
||||
|
||||
public StoplightIndicator()
|
||||
{
|
||||
_logger = Log.ForContext<StoplightIndicator>();
|
||||
|
||||
Device = new Delcom();
|
||||
Device.Open();
|
||||
|
||||
@@ -74,7 +79,7 @@ namespace WorkIndicator.Delcom
|
||||
_yellow = yellow;
|
||||
_green = green;
|
||||
|
||||
Debug.WriteLine($"Red: {_red}, Yellow: {_yellow}, Green: {_green}");
|
||||
_logger.Information("Red: {red}, Yellow: {yellow}, Green: {green}", _red, _yellow, _green);
|
||||
|
||||
port1 = port1.SetBitValue((int) Light.Green, green == LightState.Off);
|
||||
port1 = port1.SetBitValue((int) Light.Yellow, yellow == LightState.Off);
|
||||
|
||||
+12
-4
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using WorkIndicator.Audio;
|
||||
using WorkIndicator.Delcom;
|
||||
|
||||
namespace WorkIndicator
|
||||
@@ -30,7 +31,7 @@ namespace WorkIndicator
|
||||
|
||||
Properties.Settings.Default.PropertyChanged += HandleSettingChange;
|
||||
|
||||
AudioWatcher.MicrophoneInUseChanged += AudioWatcher_MicrophoneInUseChanged;
|
||||
AudioWatcher.MicrophoneStatusChanged += AudioWatcher_MicrophoneStatusChanged;
|
||||
AudioWatcher.Start();
|
||||
|
||||
_initialized = true;
|
||||
@@ -50,7 +51,7 @@ namespace WorkIndicator
|
||||
UpdateLights();
|
||||
}
|
||||
|
||||
private static void AudioWatcher_MicrophoneInUseChanged(bool microphoneInUse)
|
||||
private static void AudioWatcher_MicrophoneStatusChanged(MicrophoneStatus microphoneStatus)
|
||||
{
|
||||
UpdateLights();
|
||||
}
|
||||
@@ -90,9 +91,11 @@ namespace WorkIndicator
|
||||
|
||||
if (status == Status.Auto)
|
||||
{
|
||||
if (AudioWatcher.MicrophoneInUse())
|
||||
var microphoneStatus = AudioWatcher.GetMicrophoneStatus();
|
||||
|
||||
if (microphoneStatus != MicrophoneStatus.NotUsed)
|
||||
{
|
||||
status = Status.OnPhone;
|
||||
status = microphoneStatus == MicrophoneStatus.UsedMuted ? Status.OnPhone : Status.Talking;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -120,5 +123,10 @@ namespace WorkIndicator
|
||||
|
||||
_stoplightIndicator.SetLights(red, yellow, green);
|
||||
}
|
||||
|
||||
public static void LogAudioState()
|
||||
{
|
||||
AudioWatcher.LogState();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ using H.NotifyIcon;
|
||||
using System.Collections.Generic;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using WorkIndicator.Audio;
|
||||
using WorkIndicator.Properties;
|
||||
using WorkIndicator.SettingsWindow;
|
||||
|
||||
@@ -17,6 +18,7 @@ internal static class NotificationIcon
|
||||
{
|
||||
// Create the notification icon
|
||||
_notificationIcon = new TaskbarIcon { Icon = Resources.ApplicationIcon };
|
||||
_notificationIcon.TrayMouseDoubleClick += _notificationIcon_TrayMouseDoubleClick;
|
||||
|
||||
// Set up the menu
|
||||
var contextMenu = new ContextMenu();
|
||||
@@ -53,6 +55,11 @@ internal static class NotificationIcon
|
||||
_notificationIcon.ForceCreate(false);
|
||||
}
|
||||
|
||||
private static void _notificationIcon_TrayMouseDoubleClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
LightController.LogAudioState();
|
||||
}
|
||||
|
||||
private static void ShowSettings(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var categoryPanels = new List<CategoryPanelBase>
|
||||
|
||||
@@ -15,6 +15,7 @@ internal static class Program
|
||||
.WriteTo.Debug(outputTemplate: "{Timestamp:u} [{Level}] ({SourceContext}) {Message}{NewLine}{Exception}")
|
||||
.CreateLogger();
|
||||
|
||||
Log.Logger.Information("");
|
||||
Log.Logger.Information("Start");
|
||||
|
||||
var loggerFactory = new LoggerFactory().AddSerilog(Log.Logger);
|
||||
|
||||
Generated
+1
-1
@@ -188,7 +188,7 @@ namespace WorkIndicator.Properties {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Settings.
|
||||
/// Looks up a localized string similar to Settings....
|
||||
/// </summary>
|
||||
public static string NotificationIconContextMenuSettings {
|
||||
get {
|
||||
|
||||
@@ -201,7 +201,7 @@ Would you like to download and install it now?</value>
|
||||
<value>Talking</value>
|
||||
</data>
|
||||
<data name="NotificationIconContextMenuSettings" xml:space="preserve">
|
||||
<value>Settings</value>
|
||||
<value>Settings...</value>
|
||||
</data>
|
||||
<data name="StatusFree" xml:space="preserve">
|
||||
<value>Free</value>
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@ internal static class UpdateCheck
|
||||
{
|
||||
private static UpdateManager _updateManager;
|
||||
|
||||
public static UpdateManager UpdateManager => _updateManager ??= new UpdateManager(new GithubSource("https://github.com/ckaczor/WorkIndicator", null, false));
|
||||
public static UpdateManager UpdateManager => _updateManager ??= new UpdateManager(new GiteaSource("https://gitea.kaczorzoo.net/ckaczor/WorkIndicator", null, false));
|
||||
|
||||
public static string LocalVersion => (UpdateManager.CurrentVersion ?? new SemanticVersion(0, 0, 0)).ToString();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user