[Feature] Taskbar with option 'Use Icon from folder' (#239), version 1.0.27.2

This commit is contained in:
Markus Hofknecht 2021-11-17 23:46:43 +01:00
parent fd3cbd1f69
commit 3dce420521
3 changed files with 18 additions and 21 deletions

View file

@ -18,6 +18,9 @@ namespace SystemTrayMenu
public static class Config
{
private static readonly Icon SystemTrayMenu = Properties.Resources.SystemTrayMenu;
private static readonly Icon IconFromRootFolder = IconReader.GetFolderIconSTA(Path, IconReader.FolderType.Closed, false);
private static bool readDarkModeDone;
private static bool isDarkMode;
private static bool readHideFileExtdone;
@ -45,6 +48,18 @@ namespace SystemTrayMenu
AppColors.BitmapFilesCount.Dispose();
}
internal static Icon GetAppIcon()
{
if (Settings.Default.UseIconFromRootFolder)
{
return IconFromRootFolder;
}
else
{
return SystemTrayMenu;
}
}
public static void SetFolderByWindowsContextMenu(string[] args)
{
if (args != null && args.Length > 0)

View file

@ -13,7 +13,6 @@ namespace SystemTrayMenu.UserInterface
internal class AppNotifyIcon : IDisposable
{
private static Icon systemTrayMenu = Properties.Resources.SystemTrayMenu;
private readonly Timer load = new();
private readonly NotifyIcon notifyIcon = new();
private bool threadsLoading;
@ -26,16 +25,8 @@ namespace SystemTrayMenu.UserInterface
load.Interval = 15;
notifyIcon.Text = Translator.GetText("SystemTrayMenu");
notifyIcon.Visible = true;
notifyIcon.Icon = Config.GetAppIcon();
if (Properties.Settings.Default.UseIconFromRootFolder)
{
systemTrayMenu = IconReader.GetFolderIconSTA(
Config.Path,
IconReader.FolderType.Closed,
false);
}
notifyIcon.Icon = systemTrayMenu;
AppContextMenu contextMenus = new();
contextMenus.ClickedOpenLog += ClickedOpenLog;
@ -112,25 +103,15 @@ namespace SystemTrayMenu.UserInterface
rotationAngle += 5;
using Bitmap bitmapLoading = Resources.StaticResources.LoadingIcon.ToBitmap();
using Bitmap bitmapLoadingRotated = new(ImagingHelper.RotateImage(bitmapLoading, rotationAngle));
DisposeIconIfNotDefaultIcon();
IntPtr hIcon = bitmapLoadingRotated.GetHicon();
notifyIcon.Icon = (Icon)Icon.FromHandle(hIcon).Clone();
DllImports.NativeMethods.User32DestroyIcon(hIcon);
}
else
{
DisposeIconIfNotDefaultIcon();
notifyIcon.Icon = systemTrayMenu;
notifyIcon.Icon = Config.GetAppIcon();
load.Stop();
}
void DisposeIconIfNotDefaultIcon()
{
if (notifyIcon.Icon.GetHashCode() != systemTrayMenu.GetHashCode())
{
notifyIcon.Icon?.Dispose();
}
}
}
}
}

View file

@ -12,6 +12,7 @@ namespace SystemTrayMenu.UserInterface
public TaskbarForm()
{
InitializeComponent();
Icon = Config.GetAppIcon();
SetLocation();
}