More modernization
This commit is contained in:
@@ -0,0 +1,36 @@
|
|||||||
|
name: Deploy to Gitea Releases
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
deploy-to-gitea-releases:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
container:
|
||||||
|
image: ghcr.io/catthehacker/ubuntu:dotnet-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout Repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Get next version
|
||||||
|
uses: reecetech/version-increment@2024.4.3
|
||||||
|
id: version
|
||||||
|
with:
|
||||||
|
scheme: calver
|
||||||
|
|
||||||
|
- name: Publish Application
|
||||||
|
run: dotnet publish WorkIndicator.csproj -r win-x86 -c Release -o publish
|
||||||
|
|
||||||
|
- name: Create Velopack Release
|
||||||
|
run: |
|
||||||
|
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 }}
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
name: Deploy to GitHub Releases
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
|
|
||||||
workflow_dispatch:
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
deploy-to-github-releases:
|
|
||||||
runs-on: windows-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout Repository
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Get next version
|
|
||||||
uses: reecetech/version-increment@2024.4.3
|
|
||||||
id: version
|
|
||||||
with:
|
|
||||||
scheme: calver
|
|
||||||
|
|
||||||
- name: Install .NET
|
|
||||||
uses: actions/setup-dotnet@v4
|
|
||||||
with:
|
|
||||||
dotnet-version: 10.0.x
|
|
||||||
|
|
||||||
- name: Publish Application
|
|
||||||
run: dotnet publish WorkIndicator.csproj -c Release -o publish
|
|
||||||
|
|
||||||
- name: Create Velopack Release
|
|
||||||
run: |
|
|
||||||
dotnet tool install -g vpk
|
|
||||||
vpk download github --repoUrl https://github.com/ckaczor/WorkIndicator
|
|
||||||
vpk pack -u WorkIndicator -v ${{ steps.version.outputs.version }} -p publish --packTitle "Work Indicator" --shortcuts StartMenuRoot --framework net10.0-x64-desktop
|
|
||||||
vpk upload github --repoUrl https://github.com/ckaczor/WorkIndicator --publish --releaseName "${{ steps.version.outputs.version }}" --tag v${{ steps.version.outputs.version }} --token ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
+104
@@ -0,0 +1,104 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
+97
-7
@@ -1,21 +1,111 @@
|
|||||||
namespace WorkIndicator;
|
using NAudio.CoreAudioApi;
|
||||||
|
using NAudio.CoreAudioApi.Interfaces;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Serilog;
|
||||||
|
|
||||||
internal static class AudioWatcher
|
namespace WorkIndicator;
|
||||||
|
|
||||||
|
internal class AudioWatcher : IMMNotificationClient
|
||||||
{
|
{
|
||||||
|
private readonly ILogger _logger = Log.ForContext<AudioWatcher>();
|
||||||
|
private readonly MMDeviceEnumerator _deviceEnumerator = new();
|
||||||
|
private readonly Dictionary<string, AudioDevice> _inputDevices = new();
|
||||||
|
|
||||||
public delegate void MicrophoneInUseChangedDelegate(bool microphoneInUse);
|
public delegate void MicrophoneInUseChangedDelegate(bool microphoneInUse);
|
||||||
|
|
||||||
public static event MicrophoneInUseChangedDelegate MicrophoneInUseChanged;
|
public event MicrophoneInUseChangedDelegate MicrophoneInUseChanged;
|
||||||
|
|
||||||
public static void Start()
|
public void Start()
|
||||||
{
|
{
|
||||||
|
_logger.Information("Start");
|
||||||
|
|
||||||
|
_deviceEnumerator.RegisterEndpointNotificationCallback(this);
|
||||||
|
|
||||||
|
_logger.Information("Getting capture devices");
|
||||||
|
|
||||||
|
var captureDevices = _deviceEnumerator.EnumerateAudioEndPoints(DataFlow.Capture, DeviceState.Active);
|
||||||
|
|
||||||
|
foreach (var captureDevice in captureDevices)
|
||||||
|
{
|
||||||
|
_logger.Information("Capture device: {name}", captureDevice.DeviceFriendlyName);
|
||||||
|
|
||||||
|
HandleAddedDevice(captureDevice);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Stop()
|
private void HandleAddedDevice(MMDevice captureDevice)
|
||||||
{
|
{
|
||||||
|
_logger.Information("Device added: {name}", captureDevice.DeviceFriendlyName);
|
||||||
|
|
||||||
|
var audioDevice = new AudioDevice(captureDevice);
|
||||||
|
audioDevice.AudioSessionsChanged += AudioDevice_AudioSessionsChanged;
|
||||||
|
|
||||||
|
_inputDevices[captureDevice.ID] = audioDevice;
|
||||||
|
|
||||||
|
MicrophoneInUseChanged?.Invoke(MicrophoneInUse());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool MicrophoneInUse()
|
private void AudioDevice_AudioSessionsChanged()
|
||||||
{
|
{
|
||||||
return false;
|
MicrophoneInUseChanged?.Invoke(MicrophoneInUse());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void HandleRemovedDevice(string deviceId)
|
||||||
|
{
|
||||||
|
_logger.Information("Device removed: {id}", deviceId);
|
||||||
|
|
||||||
|
_inputDevices.Remove(deviceId);
|
||||||
|
|
||||||
|
MicrophoneInUseChanged?.Invoke(MicrophoneInUse());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Stop()
|
||||||
|
{
|
||||||
|
_logger.Information("Stop");
|
||||||
|
|
||||||
|
_deviceEnumerator.UnregisterEndpointNotificationCallback(this);
|
||||||
|
_deviceEnumerator.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool MicrophoneInUse()
|
||||||
|
{
|
||||||
|
var totalActiveSessionCount = _inputDevices.Sum(i => i.Value.ActiveSessionCount);
|
||||||
|
|
||||||
|
return totalActiveSessionCount > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void IMMNotificationClient.OnDeviceStateChanged(string deviceId, DeviceState newState)
|
||||||
|
{
|
||||||
|
_logger.Information("OnDeviceStateChanged: {deviceId} {newState}", deviceId, newState);
|
||||||
|
}
|
||||||
|
|
||||||
|
void IMMNotificationClient.OnDeviceAdded(string deviceId)
|
||||||
|
{
|
||||||
|
_logger.Information("OnDeviceAdded: {deviceId}", deviceId);
|
||||||
|
|
||||||
|
var device = _deviceEnumerator.GetDevice(deviceId);
|
||||||
|
|
||||||
|
if (device.DataFlow is DataFlow.Capture or DataFlow.All)
|
||||||
|
{
|
||||||
|
HandleAddedDevice(device);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void IMMNotificationClient.OnDeviceRemoved(string deviceId)
|
||||||
|
{
|
||||||
|
_logger.Information("OnDeviceRemoved: {deviceId}", deviceId);
|
||||||
|
|
||||||
|
HandleRemovedDevice(deviceId);
|
||||||
|
}
|
||||||
|
|
||||||
|
void IMMNotificationClient.OnDefaultDeviceChanged(DataFlow flow, Role role, string defaultDeviceId)
|
||||||
|
{
|
||||||
|
_logger.Information("OnDefaultDeviceChanged: {defaultDeviceId} {flow} {role}", defaultDeviceId, flow, role);
|
||||||
|
}
|
||||||
|
|
||||||
|
void IMMNotificationClient.OnPropertyValueChanged(string pwstrDeviceId, PropertyKey key)
|
||||||
|
{
|
||||||
|
_logger.Debug("OnPropertyValueChanged: {deviceId} {propertyId}", pwstrDeviceId, key.propertyId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -14,6 +14,7 @@ namespace WorkIndicator
|
|||||||
|
|
||||||
public static class LightController
|
public static class LightController
|
||||||
{
|
{
|
||||||
|
private static readonly AudioWatcher AudioWatcher = new();
|
||||||
private static StoplightIndicator _stoplightIndicator;
|
private static StoplightIndicator _stoplightIndicator;
|
||||||
private static UsbService _usbService;
|
private static UsbService _usbService;
|
||||||
private static bool _initialized;
|
private static bool _initialized;
|
||||||
|
|||||||
+4
-1
@@ -10,7 +10,10 @@ internal static class Program
|
|||||||
[STAThread]
|
[STAThread]
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
Log.Logger = new LoggerConfiguration().WriteTo.File("log.txt").CreateLogger();
|
Log.Logger = new LoggerConfiguration()
|
||||||
|
.WriteTo.File("log.txt")
|
||||||
|
.WriteTo.Debug(outputTemplate: "{Timestamp:u} [{Level}] ({SourceContext}) {Message}{NewLine}{Exception}")
|
||||||
|
.CreateLogger();
|
||||||
|
|
||||||
Log.Logger.Information("Start");
|
Log.Logger.Information("Start");
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
<StartupObject>WorkIndicator.Program</StartupObject>
|
<StartupObject>WorkIndicator.Program</StartupObject>
|
||||||
<ApplicationIcon>Resources\Application.ico</ApplicationIcon>
|
<ApplicationIcon>Resources\Application.ico</ApplicationIcon>
|
||||||
<UseWindowsForms>true</UseWindowsForms>
|
<UseWindowsForms>true</UseWindowsForms>
|
||||||
<Platforms>AnyCPU;x86</Platforms>
|
<Platforms>x86</Platforms>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<AppDesigner Include="Properties\" />
|
<AppDesigner Include="Properties\" />
|
||||||
@@ -22,9 +22,11 @@
|
|||||||
<PackageReference Include="ChrisKaczor.Wpf.Validation" Version="1.0.4" />
|
<PackageReference Include="ChrisKaczor.Wpf.Validation" Version="1.0.4" />
|
||||||
<PackageReference Include="ChrisKaczor.Wpf.Windows.CategoryWindow" Version="1.0.2" />
|
<PackageReference Include="ChrisKaczor.Wpf.Windows.CategoryWindow" Version="1.0.2" />
|
||||||
<PackageReference Include="H.NotifyIcon.Wpf" Version="2.4.1" />
|
<PackageReference Include="H.NotifyIcon.Wpf" Version="2.4.1" />
|
||||||
|
<PackageReference Include="NAudio.Wasapi" Version="2.3.0" />
|
||||||
<PackageReference Include="Serilog" Version="4.0.2" />
|
<PackageReference Include="Serilog" Version="4.0.2" />
|
||||||
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
|
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
|
||||||
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
|
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
|
||||||
|
<PackageReference Include="Serilog.Sinks.Debug" Version="3.0.0" />
|
||||||
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
|
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
|
||||||
<PackageReference Include="Velopack" Version="0.0.626" />
|
<PackageReference Include="Velopack" Version="0.0.626" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
+1
-3
@@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
# Visual Studio Version 18
|
# Visual Studio Version 18
|
||||||
VisualStudioVersion = 18.9.12023.133 insiders
|
VisualStudioVersion = 18.9.12023.133
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WorkIndicator", "WorkIndicator.csproj", "{B4A9FB98-C873-487F-AC4B-9B4356491DE3}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WorkIndicator", "WorkIndicator.csproj", "{B4A9FB98-C873-487F-AC4B-9B4356491DE3}"
|
||||||
EndProject
|
EndProject
|
||||||
@@ -14,11 +14,9 @@ Global
|
|||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
{B4A9FB98-C873-487F-AC4B-9B4356491DE3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{B4A9FB98-C873-487F-AC4B-9B4356491DE3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{B4A9FB98-C873-487F-AC4B-9B4356491DE3}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{B4A9FB98-C873-487F-AC4B-9B4356491DE3}.Debug|x86.ActiveCfg = Debug|x86
|
{B4A9FB98-C873-487F-AC4B-9B4356491DE3}.Debug|x86.ActiveCfg = Debug|x86
|
||||||
{B4A9FB98-C873-487F-AC4B-9B4356491DE3}.Debug|x86.Build.0 = Debug|x86
|
{B4A9FB98-C873-487F-AC4B-9B4356491DE3}.Debug|x86.Build.0 = Debug|x86
|
||||||
{B4A9FB98-C873-487F-AC4B-9B4356491DE3}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{B4A9FB98-C873-487F-AC4B-9B4356491DE3}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{B4A9FB98-C873-487F-AC4B-9B4356491DE3}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
{B4A9FB98-C873-487F-AC4B-9B4356491DE3}.Release|x86.ActiveCfg = Release|x86
|
{B4A9FB98-C873-487F-AC4B-9B4356491DE3}.Release|x86.ActiveCfg = Release|x86
|
||||||
{B4A9FB98-C873-487F-AC4B-9B4356491DE3}.Release|x86.Build.0 = Release|x86
|
{B4A9FB98-C873-487F-AC4B-9B4356491DE3}.Release|x86.Build.0 = Release|x86
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
|
|||||||
Reference in New Issue
Block a user