Skip to content

Commit

Permalink
[Feature] Show menu faster (load icons in background and update UI la…
Browse files Browse the repository at this point in the history
…ter) #196, 1.0.18.2
  • Loading branch information
Hofknecht committed Sep 24, 2021
1 parent cc70299 commit bf7a92f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 18 deletions.
42 changes: 35 additions & 7 deletions DataClasses/RowData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ internal RowData()

internal int MenuLevel { get; set; }

internal Icon Icon => icon;

internal bool IconLoading { get; set; }

public void Dispose()
Expand All @@ -82,11 +80,6 @@ internal void SetData(RowData data, DataTable dataTable)
DataRow row = dataTable.Rows.Add();
data.RowIndex = dataTable.Rows.IndexOf(row);

if (icon == null)
{
icon = NotFoundIcon;
}

if (HiddenEntry)
{
row[0] = IconReader.AddIconOverlay(
Expand Down Expand Up @@ -179,6 +172,11 @@ ex is PathTooLongException ||
}
}

if (icon == null)
{
icon = NotFoundIcon;
}

return isLnkDirectory;
}

Expand Down Expand Up @@ -242,6 +240,36 @@ internal void DoubleClick(MouseEventArgs e, out bool toCloseByDoubleClick)
}
}

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)
{
if (!isDisposed)
Expand Down
11 changes: 1 addition & 10 deletions UserInterface/Menu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -703,13 +703,6 @@ private void TextBoxSearch_TextChanged(object sender, EventArgs e)
else
{
filesCount++;

if (rowData.IconLoading)
{
string resolvedLnkPath = string.Empty;
rowData.ReadIcon(rowData.ContainsMenu, ref resolvedLnkPath);
row.Cells[0].Value = rowData.Icon;
}
}
}

Expand Down Expand Up @@ -816,9 +809,7 @@ private void TimerUpdateIcons_Tick(object sender, EventArgs e)
if (rowData.IconLoading)
{
iconsToUpdate++;
string resolvedLnkPath = string.Empty;
rowData.ReadIcon(rowData.ContainsMenu, ref resolvedLnkPath);
row.Cells[0].Value = rowData.Icon;
row.Cells[0].Value = rowData.ReadLoadedIcon();
}
}

Expand Down
3 changes: 2 additions & 1 deletion Utilities/File/IconReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ namespace SystemTrayMenu.Utilities
public static class IconReader
{
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();
public enum IconSize
Expand Down Expand Up @@ -67,7 +68,7 @@ public static Icon GetFileIconWithCache(string filePath, bool linkOverlay, bool
{
if (!DictIconCache.TryGetValue(filePath, out icon))
{
icon = Properties.Resources.Loading;
icon = LoadingIcon;
loading = true;

if (updateIconInBackground)
Expand Down

0 comments on commit bf7a92f

Please sign in to comment.