mirror of
https://github.com/ckaczor/WorkIndicator.git
synced 2026-02-11 02:32:38 -05:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 287c008117 | |||
| 42301d5242 | |||
| 3d10cc9635 | |||
| 714bd0384a | |||
| fbb797968d |
54
App.xaml.cs
54
App.xaml.cs
@@ -3,6 +3,7 @@ using Common.IO;
|
||||
using Common.Wpf.Extensions;
|
||||
using Squirrel;
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Threading;
|
||||
@@ -17,6 +18,7 @@ namespace WorkIndicator
|
||||
public static string UpdateUrl = "https://github.com/ckaczor/WorkIndicator";
|
||||
|
||||
private Dispatcher _dispatcher;
|
||||
private InterprocessMessageListener _commandLineListener;
|
||||
|
||||
[STAThread]
|
||||
public static void Main(string[] args)
|
||||
@@ -34,30 +36,39 @@ namespace WorkIndicator
|
||||
|
||||
_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
|
||||
TrayIcon.Initialize();
|
||||
|
||||
Task.Factory.StartNew(UpdateApp).ContinueWith(task => StartUpdate(task.Result.Result));
|
||||
Task.Factory.StartNew(CheckUpdate).ContinueWith(task => StartApplication(task.Result.Result));
|
||||
}
|
||||
|
||||
private void StartUpdate(bool updateRequired)
|
||||
private void StartApplication(bool updateRequired)
|
||||
{
|
||||
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);
|
||||
|
||||
@@ -66,17 +77,24 @@ namespace WorkIndicator
|
||||
});
|
||||
}
|
||||
|
||||
private async Task<bool> UpdateApp()
|
||||
private void HandleCommandLine(object sender, InterprocessMessageListener.InterprocessMessageEventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private async Task<bool> CheckUpdate()
|
||||
{
|
||||
return await UpdateCheck.CheckUpdate(HandleUpdateStatus);
|
||||
}
|
||||
|
||||
private void HandleUpdateStatus(UpdateCheck.UpdateStatus status, string message)
|
||||
{
|
||||
if (status == UpdateCheck.UpdateStatus.None)
|
||||
message = WorkIndicator.Properties.Resources.Loading;
|
||||
if (status != UpdateCheck.UpdateStatus.Installing)
|
||||
return;
|
||||
|
||||
_dispatcher.Invoke(() => TrayIcon.SetText(message));
|
||||
_dispatcher.Invoke(() => TrayIcon.ShowUpdateMessage(message));
|
||||
|
||||
TrayIcon.Dispose();
|
||||
}
|
||||
|
||||
protected override void OnExit(ExitEventArgs e)
|
||||
@@ -88,7 +106,7 @@ namespace WorkIndicator
|
||||
TrayIcon.Dispose();
|
||||
|
||||
// Get rid of the isolation handle
|
||||
_isolationHandle.Dispose();
|
||||
_isolationHandle?.Dispose();
|
||||
|
||||
base.OnExit(e);
|
||||
}
|
||||
|
||||
@@ -4,21 +4,43 @@
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:windows="clr-namespace:Common.Wpf.Windows;assembly=Common.Wpf"
|
||||
xmlns:properties="clr-namespace:WorkIndicator.Properties"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="300"
|
||||
d:DesignWidth="300">
|
||||
<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]"
|
||||
Name="ApplicationNameLabel"
|
||||
VerticalAlignment="Top"
|
||||
FontWeight="Bold" />
|
||||
FontWeight="Bold"
|
||||
Grid.Row="0" />
|
||||
<TextBlock Text="[Application Version]"
|
||||
Margin="0,22,0,0"
|
||||
Margin="0,6,0,0"
|
||||
Name="VersionLabel"
|
||||
VerticalAlignment="Top" />
|
||||
VerticalAlignment="Top"
|
||||
Grid.Row="1" />
|
||||
<TextBlock Text="[Company]"
|
||||
Margin="0,44,0,0"
|
||||
Margin="0,6,0,0"
|
||||
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>
|
||||
</windows:CategoryPanel>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Common.Update;
|
||||
using System.Reflection;
|
||||
using System.Windows;
|
||||
|
||||
namespace WorkIndicator.Options
|
||||
{
|
||||
@@ -32,5 +33,10 @@ namespace WorkIndicator.Options
|
||||
}
|
||||
|
||||
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>
|
||||
/// Looks up a localized string similar to Enabled.
|
||||
/// </summary>
|
||||
|
||||
@@ -241,4 +241,7 @@
|
||||
<data name="Loading" xml:space="preserve">
|
||||
<value>Loading...</value>
|
||||
</data>
|
||||
<data name="CheckUpdate" xml:space="preserve">
|
||||
<value>_Check for Update</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -68,9 +68,9 @@ namespace WorkIndicator
|
||||
_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)
|
||||
@@ -136,7 +136,7 @@ namespace WorkIndicator
|
||||
|
||||
if (dialogResult.HasValue && dialogResult.Value)
|
||||
{
|
||||
Properties.Settings.Default.Save();
|
||||
Settings.Default.Save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user