diff --git a/EgwControlCenter.App/BlazorForm.Designer.cs b/EgwControlCenter.App/BlazorForm.Designer.cs index f2107b5..db03166 100644 --- a/EgwControlCenter.App/BlazorForm.Designer.cs +++ b/EgwControlCenter.App/BlazorForm.Designer.cs @@ -50,7 +50,7 @@ // notifyIcon1.ContextMenuStrip = trayMenu; notifyIcon1.Icon = (Icon)resources.GetObject("notifyIcon1.Icon"); - notifyIcon1.Text = "notifyIcon1"; + notifyIcon1.Text = "EgwControlCenter.App"; notifyIcon1.Visible = true; notifyIcon1.BalloonTipClicked += NotifyIcon1_BalloonTipClicked; notifyIcon1.DoubleClick += notifyIcon1_DoubleClick; @@ -77,7 +77,7 @@ MaximizeBox = false; Name = "BlazorForm"; ShowInTaskbar = false; - Text = "EgalWare's AppControlCenter"; + Text = "EgalWare AppControlCenter"; FormClosing += BlazorForm_FormClosing; Load += BlazorForm_Load; Resize += BlazorForm_Resize; diff --git a/EgwControlCenter.App/BlazorForm.cs b/EgwControlCenter.App/BlazorForm.cs index 7ffbea0..298c59b 100644 --- a/EgwControlCenter.App/BlazorForm.cs +++ b/EgwControlCenter.App/BlazorForm.cs @@ -3,6 +3,7 @@ using EgwControlCenter.Core; using Microsoft.AspNetCore.Components.WebView.WindowsForms; using Microsoft.Extensions.DependencyInjection; using Microsoft.VisualBasic.Logging; +using Microsoft.Win32; using NLog; using System.Data; using System.Reflection; @@ -17,11 +18,50 @@ namespace EgwControlCenter.App public BlazorForm() { InitializeComponent(); - FormInit(); + ServiceInit(); + CleanOldTrayIcons(); InitBlazorView(); + StartTimer(); ForceReload(); } + private void CleanOldTrayIcons() + { + string registryPath = @"HKEY_CURRENT_USER\Control Panel\NotifyIconSettings"; + Assembly assembly = Assembly.GetExecutingAssembly(); + string startDir = Path.GetDirectoryName(assembly.Location)!; + string appPath = assembly.ManifestModule.FullyQualifiedName.Replace("dll", "exe"); + RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Control Panel\NotifyIconSettings", true); + + if (key != null) + { + foreach (string subKeyName in key.GetSubKeyNames()) + { + RegistryKey subKey = key.OpenSubKey(subKeyName); + if (subKey != null) + { + string executablePath = subKey.GetValue("ExecutablePath") as string; + // cerco solo le chaivi di EgwControlCenter.App.exe + if (!string.IsNullOrEmpty(executablePath)) + { + if (executablePath.EndsWith("EgwControlCenter.App.exe") || executablePath.Contains("EgwControlCenter")) + { + // se il path NON E' quello da cui sta girando il software --> elimino chiave registro... + if (!executablePath.Equals(appPath)) + { + key.DeleteSubKey(subKeyName); + } + } + } + } + } + } + else + { + Console.WriteLine("NotifyIconSettings key not found."); + } + } + #endregion Public Constructors #region Private Fields @@ -130,10 +170,13 @@ namespace EgwControlCenter.App MainAppControlService.DoFullCheck(true); } - private void FormInit() + private void ServiceInit() { //init preliminare servizio controllo MainAppControlService = new AppControlService(); + } + private void StartTimer() + { timerCheck.Interval = (MainAppControlService.RefreshPeriod * 1000); MainAppControlService.EA_StatusUpdated += MainAppControlService_EA_StatusUpdated; // sistemo timer