mirror of
https://github.com/ckaczor/WorkIndicator.git
synced 2026-02-11 10:38:37 -05:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1e0d3928c6 | |||
| 312c4c5c06 | |||
| 287c008117 | |||
| 42301d5242 | |||
| 3d10cc9635 | |||
| 714bd0384a | |||
| fbb797968d |
65
App.xaml.cs
65
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;
|
||||||
@@ -17,6 +18,7 @@ namespace WorkIndicator
|
|||||||
public static string UpdateUrl = "https://github.com/ckaczor/WorkIndicator";
|
public static string UpdateUrl = "https://github.com/ckaczor/WorkIndicator";
|
||||||
|
|
||||||
private Dispatcher _dispatcher;
|
private Dispatcher _dispatcher;
|
||||||
|
private InterprocessMessageListener _commandLineListener;
|
||||||
|
|
||||||
[STAThread]
|
[STAThread]
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
@@ -34,49 +36,56 @@ 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(UpdateApp).ContinueWith(task => StartUpdate(task.Result.Result));
|
// Set automatic start into the registry
|
||||||
|
Current.SetStartWithWindows(Settings.Default.StartWithWindows);
|
||||||
|
|
||||||
|
// Initialize the light controller
|
||||||
|
LightController.Initialize();
|
||||||
|
|
||||||
|
Task.Factory.StartNew(CheckUpdate);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void StartUpdate(bool updateRequired)
|
private void HandleCommandLine(object sender, InterprocessMessageListener.InterprocessMessageEventArgs e)
|
||||||
{
|
{
|
||||||
if (updateRequired)
|
|
||||||
return;
|
|
||||||
|
|
||||||
Task.Factory.StartNew(() =>
|
|
||||||
{
|
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set automatic start into the registry
|
|
||||||
Current.SetStartWithWindows(Settings.Default.StartWithWindows);
|
|
||||||
|
|
||||||
// Initialize the light controller
|
|
||||||
LightController.Initialize();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<bool> UpdateApp()
|
private async Task<bool> CheckUpdate()
|
||||||
{
|
{
|
||||||
return await UpdateCheck.CheckUpdate(HandleUpdateStatus);
|
return await UpdateCheck.CheckUpdate(HandleUpdateStatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void HandleUpdateStatus(UpdateCheck.UpdateStatus status, string message)
|
private void HandleUpdateStatus(UpdateCheck.UpdateStatus status, string message)
|
||||||
{
|
{
|
||||||
if (status == UpdateCheck.UpdateStatus.None)
|
if (status != UpdateCheck.UpdateStatus.Installing)
|
||||||
message = WorkIndicator.Properties.Resources.Loading;
|
return;
|
||||||
|
|
||||||
_dispatcher.Invoke(() => TrayIcon.SetText(message));
|
_dispatcher.Invoke(() => TrayIcon.ShowUpdateMessage(message));
|
||||||
|
|
||||||
|
TrayIcon.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnExit(ExitEventArgs e)
|
protected override void OnExit(ExitEventArgs e)
|
||||||
@@ -88,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,21 +4,43 @@
|
|||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:windows="clr-namespace:Common.Wpf.Windows;assembly=Common.Wpf"
|
xmlns:windows="clr-namespace:Common.Wpf.Windows;assembly=Common.Wpf"
|
||||||
|
xmlns:properties="clr-namespace:WorkIndicator.Properties"
|
||||||
mc:Ignorable="d"
|
mc:Ignorable="d"
|
||||||
d:DesignHeight="300"
|
d:DesignHeight="300"
|
||||||
d:DesignWidth="300">
|
d:DesignWidth="300">
|
||||||
<Grid>
|
<Grid>
|
||||||
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition Height="Auto"></RowDefinition>
|
||||||
|
<RowDefinition Height="Auto"></RowDefinition>
|
||||||
|
<RowDefinition Height="Auto"></RowDefinition>
|
||||||
|
<RowDefinition Height="Auto"></RowDefinition>
|
||||||
|
<RowDefinition Height="*"></RowDefinition>
|
||||||
|
</Grid.RowDefinitions>
|
||||||
<TextBlock Text="[Application Name]"
|
<TextBlock Text="[Application Name]"
|
||||||
Name="ApplicationNameLabel"
|
Name="ApplicationNameLabel"
|
||||||
VerticalAlignment="Top"
|
VerticalAlignment="Top"
|
||||||
FontWeight="Bold" />
|
FontWeight="Bold"
|
||||||
|
Grid.Row="0" />
|
||||||
<TextBlock Text="[Application Version]"
|
<TextBlock Text="[Application Version]"
|
||||||
Margin="0,22,0,0"
|
Margin="0,6,0,0"
|
||||||
Name="VersionLabel"
|
Name="VersionLabel"
|
||||||
VerticalAlignment="Top" />
|
VerticalAlignment="Top"
|
||||||
|
Grid.Row="1" />
|
||||||
<TextBlock Text="[Company]"
|
<TextBlock Text="[Company]"
|
||||||
Margin="0,44,0,0"
|
Margin="0,6,0,0"
|
||||||
Name="CompanyLabel"
|
Name="CompanyLabel"
|
||||||
VerticalAlignment="Top" />
|
VerticalAlignment="Top"
|
||||||
|
Grid.Row="2" />
|
||||||
|
<StackPanel Grid.Row="3"
|
||||||
|
Grid.Column="0"
|
||||||
|
Margin="0,20,0,0"
|
||||||
|
Orientation="Horizontal">
|
||||||
|
<Button Content="{x:Static properties:Resources.CheckUpdate}"
|
||||||
|
HorizontalAlignment="Left"
|
||||||
|
Padding="6,2"
|
||||||
|
Click="HandleCheckForUpdateButtonClick"
|
||||||
|
VerticalContentAlignment="Center" />
|
||||||
|
<Label Name="UpdateMessage" Content="" VerticalContentAlignment="Center" Padding="6,0" />
|
||||||
|
</StackPanel>
|
||||||
</Grid>
|
</Grid>
|
||||||
</windows:CategoryPanel>
|
</windows:CategoryPanel>
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using Common.Update;
|
using Common.Update;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using System.Windows;
|
||||||
|
|
||||||
namespace WorkIndicator.Options
|
namespace WorkIndicator.Options
|
||||||
{
|
{
|
||||||
@@ -32,5 +33,10 @@ namespace WorkIndicator.Options
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override string CategoryName => Properties.Resources.OptionCategory_About;
|
public override string CategoryName => Properties.Resources.OptionCategory_About;
|
||||||
|
|
||||||
|
private async void HandleCheckForUpdateButtonClick(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
await UpdateCheck.CheckUpdate((status, message) => UpdateMessage.Content = message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
9
Properties/Resources.Designer.cs
generated
9
Properties/Resources.Designer.cs
generated
@@ -133,6 +133,15 @@ namespace WorkIndicator.Properties {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to _Check for Update.
|
||||||
|
/// </summary>
|
||||||
|
public static string CheckUpdate {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("CheckUpdate", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to Enabled.
|
/// Looks up a localized string similar to Enabled.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -241,4 +241,7 @@
|
|||||||
<data name="Loading" xml:space="preserve">
|
<data name="Loading" xml:space="preserve">
|
||||||
<value>Loading...</value>
|
<value>Loading...</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="CheckUpdate" xml:space="preserve">
|
||||||
|
<value>_Check for Update</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
@@ -68,9 +68,9 @@ namespace WorkIndicator
|
|||||||
_initialized = true;
|
_initialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SetText(string text)
|
public static void ShowUpdateMessage(string text)
|
||||||
{
|
{
|
||||||
_trayIcon.Text = text;
|
_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)
|
||||||
@@ -136,7 +136,7 @@ namespace WorkIndicator
|
|||||||
|
|
||||||
if (dialogResult.HasValue && dialogResult.Value)
|
if (dialogResult.HasValue && dialogResult.Value)
|
||||||
{
|
{
|
||||||
Properties.Settings.Default.Save();
|
Settings.Default.Save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
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