mirror of
https://github.com/Hofknecht/SystemTrayMenu.git
synced 2024-06-16 01:14:54 +12:00
[Feature] Show menu faster (load icons in background and update UI later) #196, 1.0.18.2
This commit is contained in:
parent
cc70299972
commit
bf7a92f6b9
|
@ -60,8 +60,6 @@ namespace SystemTrayMenu.DataClasses
|
||||||
|
|
||||||
internal int MenuLevel { get; set; }
|
internal int MenuLevel { get; set; }
|
||||||
|
|
||||||
internal Icon Icon => icon;
|
|
||||||
|
|
||||||
internal bool IconLoading { get; set; }
|
internal bool IconLoading { get; set; }
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
|
@ -82,11 +80,6 @@ namespace SystemTrayMenu.DataClasses
|
||||||
DataRow row = dataTable.Rows.Add();
|
DataRow row = dataTable.Rows.Add();
|
||||||
data.RowIndex = dataTable.Rows.IndexOf(row);
|
data.RowIndex = dataTable.Rows.IndexOf(row);
|
||||||
|
|
||||||
if (icon == null)
|
|
||||||
{
|
|
||||||
icon = NotFoundIcon;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (HiddenEntry)
|
if (HiddenEntry)
|
||||||
{
|
{
|
||||||
row[0] = IconReader.AddIconOverlay(
|
row[0] = IconReader.AddIconOverlay(
|
||||||
|
@ -179,6 +172,11 @@ namespace SystemTrayMenu.DataClasses
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (icon == null)
|
||||||
|
{
|
||||||
|
icon = NotFoundIcon;
|
||||||
|
}
|
||||||
|
|
||||||
return isLnkDirectory;
|
return isLnkDirectory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -242,6 +240,36 @@ namespace SystemTrayMenu.DataClasses
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal Icon ReadLoadedIcon()
|
||||||
|
{
|
||||||
|
bool showOverlay = false;
|
||||||
|
string fileExtension = Path.GetExtension(TargetFilePath);
|
||||||
|
if (fileExtension == ".lnk" || fileExtension == ".url")
|
||||||
|
{
|
||||||
|
showOverlay = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
string path = TargetFilePath;
|
||||||
|
if (ContainsMenu)
|
||||||
|
{
|
||||||
|
path = TargetFilePathOrig;
|
||||||
|
}
|
||||||
|
|
||||||
|
icon = IconReader.GetFileIconWithCache(
|
||||||
|
path,
|
||||||
|
showOverlay,
|
||||||
|
false,
|
||||||
|
out bool loading);
|
||||||
|
IconLoading = loading;
|
||||||
|
|
||||||
|
if (!loading && icon == null)
|
||||||
|
{
|
||||||
|
icon = NotFoundIcon;
|
||||||
|
}
|
||||||
|
|
||||||
|
return icon;
|
||||||
|
}
|
||||||
|
|
||||||
protected virtual void Dispose(bool disposing)
|
protected virtual void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
if (!isDisposed)
|
if (!isDisposed)
|
||||||
|
|
|
@ -703,13 +703,6 @@ namespace SystemTrayMenu.UserInterface
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
filesCount++;
|
filesCount++;
|
||||||
|
|
||||||
if (rowData.IconLoading)
|
|
||||||
{
|
|
||||||
string resolvedLnkPath = string.Empty;
|
|
||||||
rowData.ReadIcon(rowData.ContainsMenu, ref resolvedLnkPath);
|
|
||||||
row.Cells[0].Value = rowData.Icon;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -816,9 +809,7 @@ namespace SystemTrayMenu.UserInterface
|
||||||
if (rowData.IconLoading)
|
if (rowData.IconLoading)
|
||||||
{
|
{
|
||||||
iconsToUpdate++;
|
iconsToUpdate++;
|
||||||
string resolvedLnkPath = string.Empty;
|
row.Cells[0].Value = rowData.ReadLoadedIcon();
|
||||||
rowData.ReadIcon(rowData.ContainsMenu, ref resolvedLnkPath);
|
|
||||||
row.Cells[0].Value = rowData.Icon;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@ namespace SystemTrayMenu.Utilities
|
||||||
public static class IconReader
|
public static class IconReader
|
||||||
{
|
{
|
||||||
private static readonly ConcurrentDictionary<string, Icon> DictIconCache = new ConcurrentDictionary<string, Icon>();
|
private static readonly ConcurrentDictionary<string, Icon> DictIconCache = new ConcurrentDictionary<string, Icon>();
|
||||||
|
private static readonly Icon LoadingIcon = Properties.Resources.Loading;
|
||||||
|
|
||||||
// private static readonly object ReadIcon = new object();
|
// private static readonly object ReadIcon = new object();
|
||||||
public enum IconSize
|
public enum IconSize
|
||||||
|
@ -67,7 +68,7 @@ namespace SystemTrayMenu.Utilities
|
||||||
{
|
{
|
||||||
if (!DictIconCache.TryGetValue(filePath, out icon))
|
if (!DictIconCache.TryGetValue(filePath, out icon))
|
||||||
{
|
{
|
||||||
icon = Properties.Resources.Loading;
|
icon = LoadingIcon;
|
||||||
loading = true;
|
loading = true;
|
||||||
|
|
||||||
if (updateIconInBackground)
|
if (updateIconInBackground)
|
||||||
|
|
Loading…
Reference in a new issue