From 714bd0384afa7613c98695216bd036de0b9e367b Mon Sep 17 00:00:00 2001 From: Chris Kaczor Date: Mon, 20 Dec 2021 13:43:14 -0500 Subject: [PATCH] Add IPC listener and tweak update messages --- App.xaml.cs | 22 ++++++++++++++++------ TrayIcon.cs | 4 ++-- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/App.xaml.cs b/App.xaml.cs index c45a0e6..ee5548d 100644 --- a/App.xaml.cs +++ b/App.xaml.cs @@ -17,6 +17,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) @@ -37,10 +38,10 @@ namespace WorkIndicator // 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; @@ -58,6 +59,10 @@ namespace WorkIndicator 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); @@ -66,17 +71,22 @@ namespace WorkIndicator }); } - private async Task UpdateApp() + private void HandleCommandLine(object sender, InterprocessMessageListener.InterprocessMessageEventArgs e) + { + + } + + private async Task 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.Downloading) + return; - // _dispatcher.Invoke(() => TrayIcon.SetText(message)); + _dispatcher.Invoke(() => TrayIcon.ShowUpdateMessage(message)); } protected override void OnExit(ExitEventArgs e) diff --git a/TrayIcon.cs b/TrayIcon.cs index f743c5d..8d5d9b3 100644 --- a/TrayIcon.cs +++ b/TrayIcon.cs @@ -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(250, Resources.ApplicationName, text, ToolTipIcon.None); } static void HandleContextMenuStripOpening(object sender, System.ComponentModel.CancelEventArgs e)