mirror of
https://github.com/ckaczor/WorkIndicator.git
synced 2026-02-11 10:38:37 -05:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1e0d3928c6 | |||
| 312c4c5c06 | |||
| 287c008117 | |||
| 42301d5242 | |||
| 3d10cc9635 |
63
App.xaml.cs
63
App.xaml.cs
@@ -3,6 +3,7 @@ using Common.IO;
|
|||||||
using Common.Wpf.Extensions;
|
using Common.Wpf.Extensions;
|
||||||
using Squirrel;
|
using Squirrel;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Reflection;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Threading;
|
using System.Windows.Threading;
|
||||||
@@ -35,45 +36,41 @@ namespace WorkIndicator
|
|||||||
|
|
||||||
_dispatcher = Dispatcher.CurrentDispatcher;
|
_dispatcher = Dispatcher.CurrentDispatcher;
|
||||||
|
|
||||||
|
// Create an isolation handle to see if we are already running
|
||||||
|
_isolationHandle = ApplicationIsolation.GetIsolationHandle();
|
||||||
|
|
||||||
|
// If there is another copy then pass it the command line and exit
|
||||||
|
if (_isolationHandle == null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
InterprocessMessageSender.SendMessage(Environment.CommandLine);
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
|
||||||
|
Shutdown();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialize the command line listener
|
||||||
|
_commandLineListener = new InterprocessMessageListener(Assembly.GetEntryAssembly().GetName().Name);
|
||||||
|
_commandLineListener.MessageReceived += HandleCommandLine;
|
||||||
|
|
||||||
// Initialize the tray icon
|
// Initialize the tray icon
|
||||||
TrayIcon.Initialize();
|
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)
|
// Initialize the light controller
|
||||||
{
|
LightController.Initialize();
|
||||||
if (updateRequired)
|
|
||||||
return;
|
|
||||||
|
|
||||||
Task.Factory.StartNew(() =>
|
Task.Factory.StartNew(CheckUpdate);
|
||||||
{
|
|
||||||
// Create an isolation handle to see if we are already running
|
|
||||||
_isolationHandle = ApplicationIsolation.GetIsolationHandle();
|
|
||||||
|
|
||||||
// If there is another copy then pass it the command line and exit
|
|
||||||
if (_isolationHandle == null)
|
|
||||||
{
|
|
||||||
InterprocessMessageSender.SendMessage(Environment.CommandLine);
|
|
||||||
Shutdown();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initialize the command line listener
|
|
||||||
_commandLineListener = new InterprocessMessageListener(WorkIndicator.Properties.Resources.ApplicationName);
|
|
||||||
_commandLineListener.MessageReceived += HandleCommandLine;
|
|
||||||
|
|
||||||
// Set automatic start into the registry
|
|
||||||
Current.SetStartWithWindows(Settings.Default.StartWithWindows);
|
|
||||||
|
|
||||||
// Initialize the light controller
|
|
||||||
LightController.Initialize();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void HandleCommandLine(object sender, InterprocessMessageListener.InterprocessMessageEventArgs e)
|
private void HandleCommandLine(object sender, InterprocessMessageListener.InterprocessMessageEventArgs e)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<bool> CheckUpdate()
|
private async Task<bool> CheckUpdate()
|
||||||
@@ -83,10 +80,12 @@ 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)
|
||||||
@@ -98,7 +97,7 @@ namespace WorkIndicator
|
|||||||
TrayIcon.Dispose();
|
TrayIcon.Dispose();
|
||||||
|
|
||||||
// Get rid of the isolation handle
|
// Get rid of the isolation handle
|
||||||
_isolationHandle.Dispose();
|
_isolationHandle?.Dispose();
|
||||||
|
|
||||||
base.OnExit(e);
|
base.OnExit(e);
|
||||||
}
|
}
|
||||||
|
|||||||
2
Common
2
Common
Submodule Common updated: 81856b2700...4da8f426c0
@@ -15,11 +15,15 @@ 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);
|
||||||
|
|
||||||
@@ -29,6 +33,14 @@ namespace WorkIndicator
|
|||||||
_initialized = true;
|
_initialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 +56,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|||||||
Reference in New Issue
Block a user