mirror of
https://github.com/ckaczor/WorkIndicator.git
synced 2026-02-11 10:38:37 -05:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 42301d5242 | |||
| 3d10cc9635 | |||
| 714bd0384a |
52
App.xaml.cs
52
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,30 +36,39 @@ 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));
|
Task.Factory.StartNew(CheckUpdate).ContinueWith(task => StartApplication(task.Result.Result));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void StartUpdate(bool updateRequired)
|
private void StartApplication(bool updateRequired)
|
||||||
{
|
{
|
||||||
if (updateRequired)
|
if (updateRequired)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Task.Factory.StartNew(() =>
|
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
|
// Set automatic start into the registry
|
||||||
Current.SetStartWithWindows(Settings.Default.StartWithWindows);
|
Current.SetStartWithWindows(Settings.Default.StartWithWindows);
|
||||||
|
|
||||||
@@ -66,17 +77,22 @@ 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);
|
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnExit(ExitEventArgs e)
|
protected override void OnExit(ExitEventArgs e)
|
||||||
@@ -88,7 +104,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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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(250, Resources.ApplicationName, text, ToolTipIcon.None);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void HandleContextMenuStripOpening(object sender, System.ComponentModel.CancelEventArgs e)
|
static void HandleContextMenuStripOpening(object sender, System.ComponentModel.CancelEventArgs e)
|
||||||
|
|||||||
Reference in New Issue
Block a user