mirror of
https://github.com/ckaczor/WorkIndicator.git
synced 2026-02-10 18:22:39 -05:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 896427ba75 | |||
| a98f87a630 | |||
| a0eb5e3fbc | |||
| 18aae0cef3 | |||
| 0c8ec51660 | |||
| 1e0d3928c6 | |||
| 312c4c5c06 | |||
| 287c008117 | |||
| 42301d5242 |
50
App.xaml.cs
50
App.xaml.cs
@@ -1,8 +1,10 @@
|
|||||||
using Common.Helpers;
|
using Common.Helpers;
|
||||||
using Common.IO;
|
using Common.IO;
|
||||||
using Common.Wpf.Extensions;
|
using Common.Wpf.Extensions;
|
||||||
|
using Serilog;
|
||||||
using Squirrel;
|
using Squirrel;
|
||||||
using System;
|
using System;
|
||||||
|
using System.IO;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
@@ -25,6 +27,19 @@ namespace WorkIndicator
|
|||||||
{
|
{
|
||||||
SquirrelAwareApp.HandleEvents(onAppUpdate: version => Common.Settings.Extensions.RestoreSettings());
|
SquirrelAwareApp.HandleEvents(onAppUpdate: version => Common.Settings.Extensions.RestoreSettings());
|
||||||
|
|
||||||
|
var location = Assembly.GetEntryAssembly().Location;
|
||||||
|
|
||||||
|
var path = Path.GetDirectoryName(location);
|
||||||
|
|
||||||
|
var logFile = Path.Combine(path, "log.txt");
|
||||||
|
|
||||||
|
Log.Logger = new LoggerConfiguration()
|
||||||
|
.MinimumLevel.Debug()
|
||||||
|
.WriteTo.File(logFile, rollingInterval: RollingInterval.Day)
|
||||||
|
.CreateLogger();
|
||||||
|
|
||||||
|
Log.Logger.Debug($"Startup");
|
||||||
|
|
||||||
var application = new App();
|
var application = new App();
|
||||||
application.InitializeComponent();
|
application.InitializeComponent();
|
||||||
application.Run();
|
application.Run();
|
||||||
@@ -36,23 +51,6 @@ namespace WorkIndicator
|
|||||||
|
|
||||||
_dispatcher = Dispatcher.CurrentDispatcher;
|
_dispatcher = Dispatcher.CurrentDispatcher;
|
||||||
|
|
||||||
// Initialize the command line listener
|
|
||||||
_commandLineListener = new InterprocessMessageListener(Assembly.GetEntryAssembly().GetName().Name);
|
|
||||||
_commandLineListener.MessageReceived += HandleCommandLine;
|
|
||||||
|
|
||||||
// Initialize the tray icon
|
|
||||||
TrayIcon.Initialize();
|
|
||||||
|
|
||||||
Task.Factory.StartNew(CheckUpdate).ContinueWith(task => StartApplication(task.Result.Result));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void StartApplication(bool updateRequired)
|
|
||||||
{
|
|
||||||
if (updateRequired)
|
|
||||||
return;
|
|
||||||
|
|
||||||
Task.Factory.StartNew(() =>
|
|
||||||
{
|
|
||||||
// Create an isolation handle to see if we are already running
|
// Create an isolation handle to see if we are already running
|
||||||
_isolationHandle = ApplicationIsolation.GetIsolationHandle();
|
_isolationHandle = ApplicationIsolation.GetIsolationHandle();
|
||||||
|
|
||||||
@@ -65,16 +63,24 @@ namespace WorkIndicator
|
|||||||
}
|
}
|
||||||
catch { }
|
catch { }
|
||||||
|
|
||||||
_dispatcher.Invoke(Shutdown);
|
Shutdown();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Initialize the command line listener
|
||||||
|
_commandLineListener = new InterprocessMessageListener(Assembly.GetEntryAssembly().GetName().Name);
|
||||||
|
_commandLineListener.MessageReceived += HandleCommandLine;
|
||||||
|
|
||||||
|
// Initialize the tray icon
|
||||||
|
TrayIcon.Initialize();
|
||||||
|
|
||||||
// Set automatic start into the registry
|
// Set automatic start into the registry
|
||||||
Current.SetStartWithWindows(Settings.Default.StartWithWindows);
|
Current.SetStartWithWindows(Settings.Default.StartWithWindows);
|
||||||
|
|
||||||
// Initialize the light controller
|
// Initialize the light controller
|
||||||
LightController.Initialize();
|
LightController.Initialize();
|
||||||
});
|
|
||||||
|
Task.Factory.StartNew(CheckUpdate);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void HandleCommandLine(object sender, InterprocessMessageListener.InterprocessMessageEventArgs e)
|
private void HandleCommandLine(object sender, InterprocessMessageListener.InterprocessMessageEventArgs e)
|
||||||
@@ -89,14 +95,18 @@ namespace WorkIndicator
|
|||||||
|
|
||||||
private void HandleUpdateStatus(UpdateCheck.UpdateStatus status, string message)
|
private void HandleUpdateStatus(UpdateCheck.UpdateStatus status, string message)
|
||||||
{
|
{
|
||||||
if (status != UpdateCheck.UpdateStatus.Downloading)
|
if (status != UpdateCheck.UpdateStatus.Installing)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
_dispatcher.Invoke(() => TrayIcon.ShowUpdateMessage(message));
|
_dispatcher.Invoke(() => TrayIcon.ShowUpdateMessage(message));
|
||||||
|
|
||||||
|
TrayIcon.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnExit(ExitEventArgs e)
|
protected override void OnExit(ExitEventArgs e)
|
||||||
{
|
{
|
||||||
|
Log.Logger.Debug($"Exit");
|
||||||
|
|
||||||
// Get rid of the light controller
|
// Get rid of the light controller
|
||||||
LightController.Dispose();
|
LightController.Dispose();
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using CSCore.CoreAudioAPI;
|
using CSCore.CoreAudioAPI;
|
||||||
|
using Serilog;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@@ -16,11 +17,19 @@ namespace WorkIndicator
|
|||||||
|
|
||||||
public static event MicrophoneInUseChangedDelegate MicrophoneInUseChanged;
|
public static event MicrophoneInUseChangedDelegate MicrophoneInUseChanged;
|
||||||
|
|
||||||
|
private static Thread _thread;
|
||||||
|
|
||||||
|
private static readonly List<AudioSessionManager2> _sessionManagers = new List<AudioSessionManager2>();
|
||||||
|
|
||||||
|
private static readonly ILogger Logger = Log.Logger;
|
||||||
|
|
||||||
public static void Start()
|
public static void Start()
|
||||||
{
|
{
|
||||||
|
Logger.Debug("AudioWatcher - Start");
|
||||||
|
|
||||||
_manualResetEvent = new ManualResetEvent(false);
|
_manualResetEvent = new ManualResetEvent(false);
|
||||||
|
|
||||||
var thread = new Thread(delegate ()
|
_thread = new Thread(delegate ()
|
||||||
{
|
{
|
||||||
var deviceEnumerator = new MMDeviceEnumerator();
|
var deviceEnumerator = new MMDeviceEnumerator();
|
||||||
|
|
||||||
@@ -28,11 +37,11 @@ namespace WorkIndicator
|
|||||||
{
|
{
|
||||||
var sessionManager = AudioSessionManager2.FromMMDevice(device);
|
var sessionManager = AudioSessionManager2.FromMMDevice(device);
|
||||||
|
|
||||||
var sessionEnumerator = sessionManager.GetSessionEnumerator();
|
_sessionManagers.Add(sessionManager);
|
||||||
|
|
||||||
sessionManager.SessionCreated += (sessionSender, sessionCreatedEventArgs) => HandleDeviceSession(device, sessionCreatedEventArgs.NewSession);
|
sessionManager.SessionCreated += (sessionSender, sessionCreatedEventArgs) => HandleDeviceSession(device, sessionCreatedEventArgs.NewSession);
|
||||||
|
|
||||||
foreach (var audioSessionControl in sessionEnumerator)
|
foreach (var audioSessionControl in sessionManager.GetSessionEnumerator())
|
||||||
{
|
{
|
||||||
HandleDeviceSession(device, audioSessionControl);
|
HandleDeviceSession(device, audioSessionControl);
|
||||||
}
|
}
|
||||||
@@ -41,14 +50,16 @@ namespace WorkIndicator
|
|||||||
_manualResetEvent.WaitOne();
|
_manualResetEvent.WaitOne();
|
||||||
});
|
});
|
||||||
|
|
||||||
thread.SetApartmentState(ApartmentState.MTA);
|
_thread.SetApartmentState(ApartmentState.MTA);
|
||||||
thread.Start();
|
_thread.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void HandleDeviceSession(MMDevice device, AudioSessionControl audioSessionControl)
|
private static void HandleDeviceSession(MMDevice device, AudioSessionControl audioSessionControl)
|
||||||
{
|
{
|
||||||
var deviceId = device.DeviceID + audioSessionControl.GroupingParam;
|
var deviceId = device.DeviceID + audioSessionControl.GroupingParam;
|
||||||
|
|
||||||
|
Logger.Debug($"AudioWatcher - HandleDeviceSession - {device.FriendlyName}, {deviceId}");
|
||||||
|
|
||||||
if (!ActiveSessions.ContainsKey(deviceId))
|
if (!ActiveSessions.ContainsKey(deviceId))
|
||||||
ActiveSessions[deviceId] = 0;
|
ActiveSessions[deviceId] = 0;
|
||||||
|
|
||||||
@@ -60,11 +71,17 @@ namespace WorkIndicator
|
|||||||
|
|
||||||
public static void Stop()
|
public static void Stop()
|
||||||
{
|
{
|
||||||
|
Logger.Debug("AudioWatcher - Stop");
|
||||||
|
|
||||||
|
_sessionManagers.Clear();
|
||||||
|
|
||||||
_manualResetEvent?.Set();
|
_manualResetEvent?.Set();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void HandleAudioStateChanged(string deviceId, AudioSessionState newState)
|
private static void HandleAudioStateChanged(string deviceId, AudioSessionState newState)
|
||||||
{
|
{
|
||||||
|
Logger.Debug($"AudioWatcher - HandleAudioStateChanged - {deviceId}, {newState}");
|
||||||
|
|
||||||
switch (newState)
|
switch (newState)
|
||||||
{
|
{
|
||||||
case AudioSessionState.AudioSessionStateActive:
|
case AudioSessionState.AudioSessionStateActive:
|
||||||
@@ -75,11 +92,14 @@ namespace WorkIndicator
|
|||||||
ActiveSessions[deviceId]--;
|
ActiveSessions[deviceId]--;
|
||||||
break;
|
break;
|
||||||
case AudioSessionState.AudioSessionStateExpired:
|
case AudioSessionState.AudioSessionStateExpired:
|
||||||
|
ActiveSessions[deviceId] = 0;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new ArgumentOutOfRangeException();
|
throw new ArgumentOutOfRangeException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Logger.Debug($"AudioWatcher - HandleAudioStateChanged - {deviceId} = {ActiveSessions[deviceId]}");
|
||||||
|
|
||||||
MicrophoneInUseChanged?.Invoke(MicrophoneInUse());
|
MicrophoneInUseChanged?.Invoke(MicrophoneInUse());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
2
Common
2
Common
Submodule Common updated: 81856b2700...4da8f426c0
Submodule Common.Wpf updated: 8a82786166...f299c18e22
@@ -15,20 +15,40 @@ namespace WorkIndicator
|
|||||||
public static class LightController
|
public static class LightController
|
||||||
{
|
{
|
||||||
private static StoplightIndicator _stoplightIndicator;
|
private static StoplightIndicator _stoplightIndicator;
|
||||||
|
private static UsbService _usbService;
|
||||||
private static bool _initialized;
|
private static bool _initialized;
|
||||||
private static Status _status = Status.Auto;
|
private static Status _status = Status.Auto;
|
||||||
|
|
||||||
public static void Initialize()
|
public static void Initialize()
|
||||||
{
|
{
|
||||||
|
_usbService = new UsbService();
|
||||||
|
_usbService.DevicesChanged += DevicesChanged;
|
||||||
|
|
||||||
_stoplightIndicator = new StoplightIndicator();
|
_stoplightIndicator = new StoplightIndicator();
|
||||||
_stoplightIndicator.SetLight(StoplightIndicator.Light.Yellow, StoplightIndicator.LightState.On);
|
_stoplightIndicator.SetLight(StoplightIndicator.Light.Yellow, StoplightIndicator.LightState.On);
|
||||||
|
|
||||||
|
Properties.Settings.Default.PropertyChanged += HandleSettingChange;
|
||||||
|
|
||||||
AudioWatcher.MicrophoneInUseChanged += AudioWatcher_MicrophoneInUseChanged;
|
AudioWatcher.MicrophoneInUseChanged += AudioWatcher_MicrophoneInUseChanged;
|
||||||
AudioWatcher.Start();
|
AudioWatcher.Start();
|
||||||
|
|
||||||
_initialized = true;
|
_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)
|
private static void AudioWatcher_MicrophoneInUseChanged(bool microphoneInUse)
|
||||||
{
|
{
|
||||||
UpdateLights();
|
UpdateLights();
|
||||||
@@ -44,6 +64,8 @@ namespace WorkIndicator
|
|||||||
_stoplightIndicator.SetLights(StoplightIndicator.LightState.Off, StoplightIndicator.LightState.Off, StoplightIndicator.LightState.Off);
|
_stoplightIndicator.SetLights(StoplightIndicator.LightState.Off, StoplightIndicator.LightState.Off, StoplightIndicator.LightState.Off);
|
||||||
_stoplightIndicator.Dispose();
|
_stoplightIndicator.Dispose();
|
||||||
|
|
||||||
|
_usbService.Dispose();
|
||||||
|
|
||||||
_initialized = false;
|
_initialized = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,20 +85,21 @@ namespace WorkIndicator
|
|||||||
var yellow = StoplightIndicator.LightState.Off;
|
var yellow = StoplightIndicator.LightState.Off;
|
||||||
var green = StoplightIndicator.LightState.Off;
|
var green = StoplightIndicator.LightState.Off;
|
||||||
|
|
||||||
if (_status == Status.Auto)
|
var status = _status;
|
||||||
|
|
||||||
|
if (status == Status.Auto)
|
||||||
{
|
{
|
||||||
if (AudioWatcher.MicrophoneInUse())
|
if (AudioWatcher.MicrophoneInUse())
|
||||||
{
|
{
|
||||||
red = StoplightIndicator.LightState.On;
|
status = Status.OnPhone;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
yellow = StoplightIndicator.LightState.On;
|
status = (Status) Enum.Parse(typeof(Status), Properties.Settings.Default.DefaultStatus);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
switch (status)
|
||||||
switch (_status)
|
|
||||||
{
|
{
|
||||||
case Status.Free:
|
case Status.Free:
|
||||||
green = StoplightIndicator.LightState.On;
|
green = StoplightIndicator.LightState.On;
|
||||||
@@ -93,7 +116,6 @@ namespace WorkIndicator
|
|||||||
default:
|
default:
|
||||||
throw new ArgumentOutOfRangeException();
|
throw new ArgumentOutOfRangeException();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
_stoplightIndicator.SetLights(red, yellow, green);
|
_stoplightIndicator.SetLights(red, yellow, green);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,8 +7,14 @@
|
|||||||
xmlns:properties="clr-namespace:WorkIndicator.Properties"
|
xmlns:properties="clr-namespace:WorkIndicator.Properties"
|
||||||
mc:Ignorable="d"
|
mc:Ignorable="d"
|
||||||
d:DesignHeight="300"
|
d:DesignHeight="300"
|
||||||
d:DesignWidth="300">
|
d:DesignWidth="300"
|
||||||
|
DataContext="{Binding RelativeSource={RelativeSource Self}}">
|
||||||
<Grid>
|
<Grid>
|
||||||
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition Height="Auto"></RowDefinition>
|
||||||
|
<RowDefinition Height="Auto"></RowDefinition>
|
||||||
|
<RowDefinition Height="*"></RowDefinition>
|
||||||
|
</Grid.RowDefinitions>
|
||||||
<Grid.ColumnDefinitions>
|
<Grid.ColumnDefinitions>
|
||||||
<ColumnDefinition Width="Auto" />
|
<ColumnDefinition Width="Auto" />
|
||||||
<ColumnDefinition Width="*" />
|
<ColumnDefinition Width="*" />
|
||||||
@@ -18,5 +24,19 @@
|
|||||||
VerticalAlignment="Top"
|
VerticalAlignment="Top"
|
||||||
VerticalContentAlignment="Center"
|
VerticalContentAlignment="Center"
|
||||||
Grid.ColumnSpan="2" />
|
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>
|
</Grid>
|
||||||
</windows:CategoryPanel>
|
</windows:CategoryPanel>
|
||||||
|
|||||||
@@ -1,10 +1,24 @@
|
|||||||
using Common.Wpf.Extensions;
|
using System;
|
||||||
|
using Common.Wpf.Extensions;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
|
|
||||||
namespace WorkIndicator.Options
|
namespace WorkIndicator.Options
|
||||||
{
|
{
|
||||||
public partial class GeneralOptionsPanel
|
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()
|
public GeneralOptionsPanel()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
@@ -17,6 +31,8 @@ namespace WorkIndicator.Options
|
|||||||
var settings = Properties.Settings.Default;
|
var settings = Properties.Settings.Default;
|
||||||
|
|
||||||
StartWithWindows.IsChecked = settings.StartWithWindows;
|
StartWithWindows.IsChecked = settings.StartWithWindows;
|
||||||
|
|
||||||
|
DefaultStatus.SelectedValue = Enum.Parse(typeof(Status), settings.DefaultStatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool ValidatePanel()
|
public override bool ValidatePanel()
|
||||||
@@ -32,8 +48,18 @@ namespace WorkIndicator.Options
|
|||||||
settings.StartWithWindows = StartWithWindows.IsChecked.Value;
|
settings.StartWithWindows = StartWithWindows.IsChecked.Value;
|
||||||
|
|
||||||
Application.Current.SetStartWithWindows(settings.StartWithWindows);
|
Application.Current.SetStartWithWindows(settings.StartWithWindows);
|
||||||
|
|
||||||
|
settings.DefaultStatus = DefaultStatus.SelectedValue.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string CategoryName => Properties.Resources.OptionCategory_General;
|
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)
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
9
Properties/Resources.Designer.cs
generated
9
Properties/Resources.Designer.cs
generated
@@ -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>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to Delete.
|
/// Looks up a localized string similar to Delete.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -244,4 +244,7 @@
|
|||||||
<data name="CheckUpdate" xml:space="preserve">
|
<data name="CheckUpdate" xml:space="preserve">
|
||||||
<value>_Check for Update</value>
|
<value>_Check for Update</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="DefaultStatus" xml:space="preserve">
|
||||||
|
<value>_Default status:</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
14
Properties/Settings.Designer.cs
generated
14
Properties/Settings.Designer.cs
generated
@@ -12,7 +12,7 @@ namespace WorkIndicator.Properties {
|
|||||||
|
|
||||||
|
|
||||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
[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 {
|
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
|
||||||
|
|
||||||
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
|
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
|
||||||
@@ -64,5 +64,17 @@ namespace WorkIndicator.Properties {
|
|||||||
this["WindowPatterns"] = value;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,5 +14,8 @@
|
|||||||
<Setting Name="WindowPatterns" Type="System.String" Scope="User">
|
<Setting Name="WindowPatterns" Type="System.String" Scope="User">
|
||||||
<Value Profile="(Default)" />
|
<Value Profile="(Default)" />
|
||||||
</Setting>
|
</Setting>
|
||||||
|
<Setting Name="DefaultStatus" Type="System.String" Scope="User">
|
||||||
|
<Value Profile="(Default)">Free</Value>
|
||||||
|
</Setting>
|
||||||
</Settings>
|
</Settings>
|
||||||
</SettingsFile>
|
</SettingsFile>
|
||||||
@@ -70,7 +70,7 @@ namespace WorkIndicator
|
|||||||
|
|
||||||
public static void ShowUpdateMessage(string text)
|
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)
|
static void HandleContextMenuStripOpening(object sender, System.ComponentModel.CancelEventArgs e)
|
||||||
|
|||||||
52
UsbService.cs
Normal file
52
UsbService.cs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -144,6 +144,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="UpdateCheck.cs" />
|
<Compile Include="UpdateCheck.cs" />
|
||||||
|
<Compile Include="UsbService.cs" />
|
||||||
<Page Include="App.xaml">
|
<Page Include="App.xaml">
|
||||||
<Generator>MSBuild:Compile</Generator>
|
<Generator>MSBuild:Compile</Generator>
|
||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
@@ -237,6 +238,12 @@
|
|||||||
<PackageReference Include="Newtonsoft.Json">
|
<PackageReference Include="Newtonsoft.Json">
|
||||||
<Version>13.0.1</Version>
|
<Version>13.0.1</Version>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
|
<PackageReference Include="Serilog">
|
||||||
|
<Version>2.10.0</Version>
|
||||||
|
</PackageReference>
|
||||||
|
<PackageReference Include="Serilog.Sinks.File">
|
||||||
|
<Version>5.0.0</Version>
|
||||||
|
</PackageReference>
|
||||||
<PackageReference Include="squirrel.windows">
|
<PackageReference Include="squirrel.windows">
|
||||||
<Version>2.0.1</Version>
|
<Version>2.0.1</Version>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
|
|||||||
@@ -16,6 +16,9 @@
|
|||||||
<setting name="WindowPatterns" serializeAs="String">
|
<setting name="WindowPatterns" serializeAs="String">
|
||||||
<value />
|
<value />
|
||||||
</setting>
|
</setting>
|
||||||
|
<setting name="DefaultStatus" serializeAs="String">
|
||||||
|
<value>Free</value>
|
||||||
|
</setting>
|
||||||
</WorkIndicator.Properties.Settings>
|
</WorkIndicator.Properties.Settings>
|
||||||
</userSettings>
|
</userSettings>
|
||||||
<applicationSettings>
|
<applicationSettings>
|
||||||
|
|||||||
Reference in New Issue
Block a user