6 Commits

Author SHA1 Message Date
a0eb5e3fbc Fix for release build optimizations 2021-12-22 10:14:51 -05:00
18aae0cef3 Add setting for default status 2021-12-20 17:50:58 -05:00
0c8ec51660 Update submodule 2021-12-20 16:36:07 -05:00
1e0d3928c6 Update submodules 2021-12-20 16:24:21 -05:00
312c4c5c06 Handle device removal/addition 2021-12-20 16:21:01 -05:00
287c008117 Make sure icon gets removed 2021-12-20 14:01:48 -05:00
15 changed files with 196 additions and 44 deletions

View File

@@ -59,22 +59,13 @@ namespace WorkIndicator
// Initialize the tray icon
TrayIcon.Initialize();
Task.Factory.StartNew(CheckUpdate).ContinueWith(task => StartApplication(task.Result.Result));
}
// Set automatic start into the registry
Current.SetStartWithWindows(Settings.Default.StartWithWindows);
private void StartApplication(bool updateRequired)
{
if (updateRequired)
return;
// Initialize the light controller
LightController.Initialize();
Task.Factory.StartNew(() =>
{
// Set automatic start into the registry
Current.SetStartWithWindows(Settings.Default.StartWithWindows);
// Initialize the light controller
LightController.Initialize();
});
Task.Factory.StartNew(CheckUpdate);
}
private void HandleCommandLine(object sender, InterprocessMessageListener.InterprocessMessageEventArgs e)
@@ -93,6 +84,8 @@ namespace WorkIndicator
return;
_dispatcher.Invoke(() => TrayIcon.ShowUpdateMessage(message));
TrayIcon.Dispose();
}
protected override void OnExit(ExitEventArgs e)

View File

@@ -16,11 +16,15 @@ namespace WorkIndicator
public static event MicrophoneInUseChangedDelegate MicrophoneInUseChanged;
private static Thread _thread;
private static readonly List<AudioSessionManager2> _sessionManagers = new List<AudioSessionManager2>();
public static void Start()
{
_manualResetEvent = new ManualResetEvent(false);
var thread = new Thread(delegate ()
_thread = new Thread(delegate ()
{
var deviceEnumerator = new MMDeviceEnumerator();
@@ -28,6 +32,8 @@ namespace WorkIndicator
{
var sessionManager = AudioSessionManager2.FromMMDevice(device);
_sessionManagers.Add(sessionManager);
var sessionEnumerator = sessionManager.GetSessionEnumerator();
sessionManager.SessionCreated += (sessionSender, sessionCreatedEventArgs) => HandleDeviceSession(device, sessionCreatedEventArgs.NewSession);
@@ -41,8 +47,8 @@ namespace WorkIndicator
_manualResetEvent.WaitOne();
});
thread.SetApartmentState(ApartmentState.MTA);
thread.Start();
_thread.SetApartmentState(ApartmentState.MTA);
_thread.Start();
}
private static void HandleDeviceSession(MMDevice device, AudioSessionControl audioSessionControl)
@@ -60,6 +66,8 @@ namespace WorkIndicator
public static void Stop()
{
_sessionManagers.Clear();
_manualResetEvent?.Set();
}

2
Common

Submodule Common updated: 81856b2700...4da8f426c0

View File

@@ -15,20 +15,40 @@ namespace WorkIndicator
public static class LightController
{
private static StoplightIndicator _stoplightIndicator;
private static UsbService _usbService;
private static bool _initialized;
private static Status _status = Status.Auto;
public static void Initialize()
{
_usbService = new UsbService();
_usbService.DevicesChanged += DevicesChanged;
_stoplightIndicator = new StoplightIndicator();
_stoplightIndicator.SetLight(StoplightIndicator.Light.Yellow, StoplightIndicator.LightState.On);
Properties.Settings.Default.PropertyChanged += HandleSettingChange;
AudioWatcher.MicrophoneInUseChanged += AudioWatcher_MicrophoneInUseChanged;
AudioWatcher.Start();
_initialized = true;
}
private static void HandleSettingChange(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(Properties.Settings.Default.DefaultStatus))
UpdateLights();
}
private static void DevicesChanged()
{
_stoplightIndicator?.Dispose();
_stoplightIndicator = new StoplightIndicator();
UpdateLights();
}
private static void AudioWatcher_MicrophoneInUseChanged(bool microphoneInUse)
{
UpdateLights();
@@ -44,6 +64,8 @@ namespace WorkIndicator
_stoplightIndicator.SetLights(StoplightIndicator.LightState.Off, StoplightIndicator.LightState.Off, StoplightIndicator.LightState.Off);
_stoplightIndicator.Dispose();
_usbService.Dispose();
_initialized = false;
}
@@ -63,36 +85,36 @@ namespace WorkIndicator
var yellow = StoplightIndicator.LightState.Off;
var green = StoplightIndicator.LightState.Off;
if (_status == Status.Auto)
var status = _status;
if (status == Status.Auto)
{
if (AudioWatcher.MicrophoneInUse())
{
red = StoplightIndicator.LightState.On;
status = Status.OnPhone;
}
else
{
yellow = StoplightIndicator.LightState.On;
status = (Status) Enum.Parse(typeof(Status), Properties.Settings.Default.DefaultStatus);
}
}
else
switch (status)
{
switch (_status)
{
case Status.Free:
green = StoplightIndicator.LightState.On;
break;
case Status.Working:
yellow = StoplightIndicator.LightState.On;
break;
case Status.OnPhone:
red = StoplightIndicator.LightState.On;
break;
case Status.Talking:
red = StoplightIndicator.LightState.Blink;
break;
default:
throw new ArgumentOutOfRangeException();
}
case Status.Free:
green = StoplightIndicator.LightState.On;
break;
case Status.Working:
yellow = StoplightIndicator.LightState.On;
break;
case Status.OnPhone:
red = StoplightIndicator.LightState.On;
break;
case Status.Talking:
red = StoplightIndicator.LightState.Blink;
break;
default:
throw new ArgumentOutOfRangeException();
}
_stoplightIndicator.SetLights(red, yellow, green);

View File

@@ -7,8 +7,14 @@
xmlns:properties="clr-namespace:WorkIndicator.Properties"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="300">
d:DesignWidth="300"
DataContext="{Binding RelativeSource={RelativeSource Self}}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
@@ -18,5 +24,19 @@
VerticalAlignment="Top"
VerticalContentAlignment="Center"
Grid.ColumnSpan="2" />
<Label Content="{x:Static properties:Resources.DefaultStatus}"
Name="ApplicationNameLabel"
VerticalAlignment="Center"
Padding="0,0,6,0"
Grid.Row="1"
Margin="0,20,0,0" />
<ComboBox Name="DefaultStatus"
Grid.Row="1"
Grid.Column="1"
Margin="0,20,0,0"
ItemsSource="{Binding Path=DefaultStatusList}"
DisplayMemberPath="Text"
SelectedValuePath="Value">
</ComboBox>
</Grid>
</windows:CategoryPanel>

View File

@@ -1,10 +1,24 @@
using Common.Wpf.Extensions;
using System;
using Common.Wpf.Extensions;
using System.Collections.ObjectModel;
using System.Windows;
namespace WorkIndicator.Options
{
public partial class GeneralOptionsPanel
{
public class StatusItem
{
public Status Value { get; set; }
public string Text { get; set; }
public StatusItem(Status value, string text)
{
Value = value;
Text = text;
}
}
public GeneralOptionsPanel()
{
InitializeComponent();
@@ -17,6 +31,8 @@ namespace WorkIndicator.Options
var settings = Properties.Settings.Default;
StartWithWindows.IsChecked = settings.StartWithWindows;
DefaultStatus.SelectedValue = Enum.Parse(typeof(Status), settings.DefaultStatus);
}
public override bool ValidatePanel()
@@ -32,8 +48,18 @@ namespace WorkIndicator.Options
settings.StartWithWindows = StartWithWindows.IsChecked.Value;
Application.Current.SetStartWithWindows(settings.StartWithWindows);
settings.DefaultStatus = DefaultStatus.SelectedValue.ToString();
}
public override string CategoryName => Properties.Resources.OptionCategory_General;
public ObservableCollection<StatusItem> DefaultStatusList => new ObservableCollection<StatusItem>
{
new StatusItem(Status.Free, Properties.Resources.Free),
new StatusItem(Status.Working, Properties.Resources.Working),
new StatusItem(Status.OnPhone, Properties.Resources.OnPhone),
new StatusItem(Status.Talking, Properties.Resources.Talking)
};
}
}

View File

@@ -169,6 +169,15 @@ namespace WorkIndicator.Properties {
}
}
/// <summary>
/// Looks up a localized string similar to _Default status:.
/// </summary>
public static string DefaultStatus {
get {
return ResourceManager.GetString("DefaultStatus", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Delete.
/// </summary>

View File

@@ -244,4 +244,7 @@
<data name="CheckUpdate" xml:space="preserve">
<value>_Check for Update</value>
</data>
<data name="DefaultStatus" xml:space="preserve">
<value>_Default status:</value>
</data>
</root>

View File

@@ -12,7 +12,7 @@ namespace WorkIndicator.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.5.0.0")]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.0.3.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
@@ -64,5 +64,17 @@ namespace WorkIndicator.Properties {
this["WindowPatterns"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("Free")]
public string DefaultStatus {
get {
return ((string)(this["DefaultStatus"]));
}
set {
this["DefaultStatus"] = value;
}
}
}
}

View File

@@ -14,5 +14,8 @@
<Setting Name="WindowPatterns" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="DefaultStatus" Type="System.String" Scope="User">
<Value Profile="(Default)">Free</Value>
</Setting>
</Settings>
</SettingsFile>

View File

@@ -70,7 +70,7 @@ namespace WorkIndicator
public static void ShowUpdateMessage(string text)
{
_trayIcon.ShowBalloonTip(250, Resources.ApplicationName, text, ToolTipIcon.None);
_trayIcon.ShowBalloonTip(200, Resources.ApplicationName, text, ToolTipIcon.None);
}
static void HandleContextMenuStripOpening(object sender, System.ComponentModel.CancelEventArgs e)

52
UsbService.cs Normal file
View File

@@ -0,0 +1,52 @@
using System;
using System.Windows.Forms;
namespace WorkIndicator
{
internal class UsbService : NativeWindow, IDisposable
{
public event Action DevicesChanged;
private const int WM_DEVICECHANGE = 0x0219;
private const int DBT_DEVICEARRIVAL = 0x8000;
private const int DBT_DEVICEREMOVECOMPLETE = 0x8004;
private const int DBT_DEVNODES_CHANGED = 0x0007;
private bool _isDisposed;
internal UsbService()
{
base.CreateHandle(new CreateParams());
}
protected override void WndProc(ref Message msg)
{
base.WndProc(ref msg);
if (msg.Msg == WM_DEVICECHANGE)
{
switch (msg.WParam.ToInt32())
{
case DBT_DEVNODES_CHANGED:
case DBT_DEVICEARRIVAL:
case DBT_DEVICEREMOVECOMPLETE:
DevicesChanged?.Invoke();
break;
}
}
}
public void Dispose()
{
if (!_isDisposed)
{
base.DestroyHandle();
_isDisposed = true;
GC.SuppressFinalize(this);
}
}
}
}

View File

@@ -144,6 +144,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="UpdateCheck.cs" />
<Compile Include="UsbService.cs" />
<Page Include="App.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>

View File

@@ -16,6 +16,9 @@
<setting name="WindowPatterns" serializeAs="String">
<value />
</setting>
<setting name="DefaultStatus" serializeAs="String">
<value>Free</value>
</setting>
</WorkIndicator.Properties.Settings>
</userSettings>
<applicationSettings>