diff --git a/LightController.cs b/LightController.cs index 8193ae0..cab8a3f 100644 --- a/LightController.cs +++ b/LightController.cs @@ -27,17 +27,25 @@ namespace WorkIndicator _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(); } @@ -77,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); diff --git a/Options/GeneralOptionsPanel.xaml b/Options/GeneralOptionsPanel.xaml index 199b3af..5b9e09c 100644 --- a/Options/GeneralOptionsPanel.xaml +++ b/Options/GeneralOptionsPanel.xaml @@ -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}}"> + + + + + @@ -18,5 +24,19 @@ VerticalAlignment="Top" VerticalContentAlignment="Center" Grid.ColumnSpan="2" /> + diff --git a/Options/GeneralOptionsPanel.xaml.cs b/Options/GeneralOptionsPanel.xaml.cs index dd34f50..c10e5e9 100644 --- a/Options/GeneralOptionsPanel.xaml.cs +++ b/Options/GeneralOptionsPanel.xaml.cs @@ -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 DefaultStatusList => new ObservableCollection + { + 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) + }; } } diff --git a/Properties/Resources.Designer.cs b/Properties/Resources.Designer.cs index 77b8ca0..fa43575 100644 --- a/Properties/Resources.Designer.cs +++ b/Properties/Resources.Designer.cs @@ -169,6 +169,15 @@ namespace WorkIndicator.Properties { } } + /// + /// Looks up a localized string similar to _Default status:. + /// + public static string DefaultStatus { + get { + return ResourceManager.GetString("DefaultStatus", resourceCulture); + } + } + /// /// Looks up a localized string similar to Delete. /// diff --git a/Properties/Resources.resx b/Properties/Resources.resx index 1263abc..36d8537 100644 --- a/Properties/Resources.resx +++ b/Properties/Resources.resx @@ -244,4 +244,7 @@ _Check for Update + + _Default status: + \ No newline at end of file diff --git a/Properties/Settings.Designer.cs b/Properties/Settings.Designer.cs index adff8ca..3b2abfc 100644 --- a/Properties/Settings.Designer.cs +++ b/Properties/Settings.Designer.cs @@ -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; + } + } } } diff --git a/Properties/Settings.settings b/Properties/Settings.settings index 7cd4587..2423daf 100644 --- a/Properties/Settings.settings +++ b/Properties/Settings.settings @@ -14,5 +14,8 @@ + + Free + \ No newline at end of file diff --git a/app.config b/app.config index 3607178..5fb5825 100644 --- a/app.config +++ b/app.config @@ -16,6 +16,9 @@ + + Free +