From 0867a659ecba352bface8c84ee393a975dfdb713 Mon Sep 17 00:00:00 2001 From: evilhawk00 Date: Tue, 6 Sep 2022 04:00:46 +0800 Subject: [PATCH] Bump 1.0.0.1 UI App now brings the existed instance to front if multi-instances of the UI App is created. --- .gitignore | 12 ++++++ PrintheadMaintainerInstaller/Product.wxs | 12 ++++-- .../PrintheadMaintainer.rc | 10 ++--- .../Utils/PrinterUtils.cpp | 4 +- PrintheadMaintainerUI/App.xaml.cs | 42 +++++++++++++++---- PrintheadMaintainerUI/MainWindow.xaml.cs | 15 ++++--- .../Properties/AssemblyInfo.cs | 6 +-- PrintheadMaintainerUI/Views/AboutView.xaml | 2 +- 8 files changed, 74 insertions(+), 29 deletions(-) diff --git a/.gitignore b/.gitignore index dfcfd56..fb3817e 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,18 @@ ## ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore + + +####Custom built files in InstallationFilesSourceDir for project Printhead Maintainer#### +PrintheadMaintainerInstaller/InstallationFilesSourceDir/Microsoft.Toolkit.Uwp.Notifications.dll +PrintheadMaintainerInstaller/InstallationFilesSourceDir/PrintheadMaintainer.exe +PrintheadMaintainerInstaller/InstallationFilesSourceDir/PrintheadMaintainSvc.exe +PrintheadMaintainerInstaller/InstallationFilesSourceDir/System.ValueTuple.dll + + + + + # User-specific files *.rsuser *.suo diff --git a/PrintheadMaintainerInstaller/Product.wxs b/PrintheadMaintainerInstaller/Product.wxs index e2b977d..2094038 100644 --- a/PrintheadMaintainerInstaller/Product.wxs +++ b/PrintheadMaintainerInstaller/Product.wxs @@ -1,11 +1,17 @@ - + - + + + + + + + @@ -108,6 +114,4 @@ - - diff --git a/PrintheadMaintainerService/PrintheadMaintainer/PrintheadMaintainer.rc b/PrintheadMaintainerService/PrintheadMaintainer/PrintheadMaintainer.rc index 0cacc40..1d44333 100644 --- a/PrintheadMaintainerService/PrintheadMaintainer/PrintheadMaintainer.rc +++ b/PrintheadMaintainerService/PrintheadMaintainer/PrintheadMaintainer.rc @@ -61,8 +61,8 @@ END // VS_VERSION_INFO VERSIONINFO - FILEVERSION 1,0,0,0 - PRODUCTVERSION 1,0,0,0 + FILEVERSION 1,0,0,1 + PRODUCTVERSION 1,0,0,1 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -79,11 +79,11 @@ BEGIN BEGIN VALUE "CompanyName", "evilhawk00" VALUE "FileDescription", "Printhead Maintenance Service" - VALUE "FileVersion", "1.0.0.0" - VALUE "LegalCopyright", "Copyright (C) 2021 YAN-LIN, CHEN" + VALUE "FileVersion", "1.0.0.1" + VALUE "LegalCopyright", "Copyright (C) 2022 YAN-LIN, CHEN" VALUE "OriginalFilename", "PrintheadMaintainSvc.exe" VALUE "ProductName", "Printhead Maintainer" - VALUE "ProductVersion", "1.0.0.0" + VALUE "ProductVersion", "1.0.0.1" END END BLOCK "VarFileInfo" diff --git a/PrintheadMaintainerService/PrintheadMaintainer/Utils/PrinterUtils.cpp b/PrintheadMaintainerService/PrintheadMaintainer/Utils/PrinterUtils.cpp index 2a808cf..8a78f26 100644 --- a/PrintheadMaintainerService/PrintheadMaintainer/Utils/PrinterUtils.cpp +++ b/PrintheadMaintainerService/PrintheadMaintainer/Utils/PrinterUtils.cpp @@ -229,7 +229,7 @@ int intIfPrinterHasError(const std::wstring& wsPrinterName) { //printer handle is no longer needed ClosePrinter(hPrinter); - for (int i = 0; i < dwJobsReturned; i++) + for (unsigned int i = 0; i < dwJobsReturned; i++) { if (pJobs[i].Status & JOB_STATUS_PRINTING) { @@ -350,7 +350,7 @@ int intIfJobStillInQueueWithOptionalDelete(const std::wstring& wsDocumentNameDis return -1; } - for (int i = 0; i < dwJobsInQueue; i++) + for (unsigned int i = 0; i < dwJobsInQueue; i++) { if (pJobs[i].pDocument == wsDocumentNameDisplayedInQueue) { diff --git a/PrintheadMaintainerUI/App.xaml.cs b/PrintheadMaintainerUI/App.xaml.cs index d4a586d..9dca3ba 100644 --- a/PrintheadMaintainerUI/App.xaml.cs +++ b/PrintheadMaintainerUI/App.xaml.cs @@ -26,17 +26,23 @@ namespace PrintheadMaintainerUI /// public partial class App : Application { + #pragma warning disable IDE0052 private static Mutex _mutex = null; + #pragma warning restore IDE0052 + private EventWaitHandle _eventWaitHandle; public bool bStartupMinimized = false; protected override void OnStartup(StartupEventArgs e) { - const string appName = "PrintheadMaintainer"; - bool createdNew; + const string strAppName = "PrintheadMaintainer"; + const string strUniqueEventName = "{2C4150D2-F22B-4F1D-97FC-7B68EE70FEA6}"; + + bool bCreatedNew; + + _mutex = new Mutex(true, strAppName, out bCreatedNew); + _eventWaitHandle = new EventWaitHandle(false, EventResetMode.AutoReset, strUniqueEventName); - _mutex = new Mutex(true, appName, out createdNew); - for (int i = 0; i != e.Args.Length; ++i) { if (e.Args[i] == "/silent") @@ -45,14 +51,32 @@ protected override void OnStartup(StartupEventArgs e) } } - - - if (!createdNew) + if (bCreatedNew) { - //app is already running! Exiting the application - Current.Shutdown(); + //create a thread to wait for the event + Thread thread = new Thread( + () => + { + while (_eventWaitHandle.WaitOne()) + { + _ = Current.Dispatcher.BeginInvoke( + (System.Action)(() => ((MainWindow)Current.MainWindow).Void_Public_Restore_Window())); + } + }); + + //Mark it as background otherwise it will prevent app from exiting. + thread.IsBackground = true; + + thread.Start(); + return; } + //Tell other instance to bring window to front. + _ = _eventWaitHandle.Set(); + + //Terminate this instance. + Shutdown(); + base.OnStartup(e); } diff --git a/PrintheadMaintainerUI/MainWindow.xaml.cs b/PrintheadMaintainerUI/MainWindow.xaml.cs index fa16ff8..d293e3f 100644 --- a/PrintheadMaintainerUI/MainWindow.xaml.cs +++ b/PrintheadMaintainerUI/MainWindow.xaml.cs @@ -141,11 +141,7 @@ private void VoidCreateTrayIcon() niNotifyIcon.DoubleClick += delegate (object sender, EventArgs args) { - //switch back to home first - Mediator.Notify("SwitchToHome", ""); - - Show(); - WindowState = WindowState.Normal; + VoidRestoreWindow(sender, args); }; @@ -171,6 +167,11 @@ private void VoidCloseApplication(object Sender, EventArgs e) Close(); } + public void Void_Public_Restore_Window() + { + VoidRestoreWindow(null, null); + } + private void VoidRestoreWindow(object Sender, EventArgs e) { //switch back to home first @@ -178,6 +179,10 @@ private void VoidRestoreWindow(object Sender, EventArgs e) Show(); WindowState = WindowState.Normal; + + //make this window to top + _ = Activate(); + } private void VoidMinimizeWindowToTray(object sender, RoutedEventArgs e) { diff --git a/PrintheadMaintainerUI/Properties/AssemblyInfo.cs b/PrintheadMaintainerUI/Properties/AssemblyInfo.cs index 6742d18..1315871 100644 --- a/PrintheadMaintainerUI/Properties/AssemblyInfo.cs +++ b/PrintheadMaintainerUI/Properties/AssemblyInfo.cs @@ -12,7 +12,7 @@ [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("evilhawk00")] [assembly: AssemblyProduct("Printhead Maintainer")] -[assembly: AssemblyCopyright("Copyright © 2021 YAN-LIN, CHEN")] +[assembly: AssemblyCopyright("Copyright © 2022 YAN-LIN, CHEN")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] @@ -51,5 +51,5 @@ // 您可以指定所有的值,也可以使用 '*' 將組建和修訂編號 // 設為預設,如下所示: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +[assembly: AssemblyVersion("1.0.0.1")] +[assembly: AssemblyFileVersion("1.0.0.1")] diff --git a/PrintheadMaintainerUI/Views/AboutView.xaml b/PrintheadMaintainerUI/Views/AboutView.xaml index 1b06ef5..a8840b1 100644 --- a/PrintheadMaintainerUI/Views/AboutView.xaml +++ b/PrintheadMaintainerUI/Views/AboutView.xaml @@ -84,7 +84,7 @@ along with this program. If not, see . - +