Skip to content

Commit

Permalink
Don't load/show icons for Open Recent and Open With menus. Lazy worka…
Browse files Browse the repository at this point in the history
…round for memory leak on macOS.
  • Loading branch information
jdpurcell committed Aug 12, 2023
1 parent cb29eef commit 401fbd3
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 30 deletions.
22 changes: 11 additions & 11 deletions src/actionmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,27 +431,27 @@ void ActionManager::updateRecentsMenu()
auto recent = recentsList.value(i);

action->setVisible(true);
action->setIconVisibleInMenu(false); // Hide icon temporarily to speed up updates in certain cases
//action->setIconVisibleInMenu(false); // Hide icon temporarily to speed up updates in certain cases
action->setText(recent.fileName);

#if defined Q_OS_UNIX && !defined Q_OS_MACOS
// set icons for linux users
QMimeDatabase mimedb;
QMimeType type = mimedb.mimeTypeForFile(recent.filePath);
action->setIcon(QIcon::fromTheme(type.iconName(), QIcon::fromTheme(type.genericIconName())));
//QMimeDatabase mimedb;
//QMimeType type = mimedb.mimeTypeForFile(recent.filePath);
//action->setIcon(QIcon::fromTheme(type.iconName(), QIcon::fromTheme(type.genericIconName())));
#else
// set icons for mac/windows users
QFileInfo fileInfo(recent.filePath);
QFileIconProvider provider;
QIcon icon = provider.icon(fileInfo);
//QFileInfo fileInfo(recent.filePath);
//QFileIconProvider provider;
//QIcon icon = provider.icon(fileInfo);
#ifdef Q_OS_MACOS
// Workaround for native menu slowness
if (!fileInfo.suffix().isEmpty())
icon = getCacheableIcon("filetype:" + fileInfo.suffix(), icon);
//if (!fileInfo.suffix().isEmpty())
// icon = getCacheableIcon("filetype:" + fileInfo.suffix(), icon);
#endif
action->setIcon(icon);
//action->setIcon(icon);
#endif
action->setIconVisibleInMenu(true);
//action->setIconVisibleInMenu(true);
}
else
{
Expand Down
12 changes: 6 additions & 6 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,16 +416,16 @@ void MainWindow::populateOpenWithMenu(const QList<OpenWith::OpenWithItem> openWi
auto openWithItem = openWithItems.value(i);

action->setVisible(true);
action->setIconVisibleInMenu(false); // Hide icon temporarily to speed up updates in certain cases
//action->setIconVisibleInMenu(false); // Hide icon temporarily to speed up updates in certain cases
action->setText(openWithItem.name);
if (!openWithItem.iconName.isEmpty())
action->setIcon(QIcon::fromTheme(openWithItem.iconName));
else
action->setIcon(openWithItem.icon);
//if (!openWithItem.iconName.isEmpty())
// action->setIcon(QIcon::fromTheme(openWithItem.iconName));
//else
// action->setIcon(openWithItem.icon);
auto data = action->data().toList();
data.replace(1, QVariant::fromValue(openWithItem));
action->setData(data);
action->setIconVisibleInMenu(true);
//action->setIconVisibleInMenu(true);
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions src/qvcocoafunctions.mm
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ static void fixNativeMenuEccentricities(QMenu *menu, NSMenu *nativeMenu)
openWithItem.name = QString::fromNSString(appName);

QFileIconProvider fiProvider;
QIcon icon = fiProvider.icon(QFileInfo(QString::fromNSString(absolutePath)));
openWithItem.icon = ActionManager::getCacheableIcon("application:" + QString::fromNSString(appId), icon);
//QIcon icon = fiProvider.icon(QFileInfo(QString::fromNSString(absolutePath)));
//openWithItem.icon = ActionManager::getCacheableIcon("application:" + QString::fromNSString(appId), icon);

// If the program is the default program, save it to add to the beginning after sorting
if ([appId isEqualToString:defaultApplication])
Expand Down
22 changes: 11 additions & 11 deletions src/qvwin32functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,17 @@ QList<OpenWith::OpenWithItem> QVWin32Functions::getOpenWithItems(const QString &
openWithItem.name.replace("&", "&&");

// Set an icon
if (isAppx)
{
WCHAR realIconPath[MAX_PATH];
SHLoadIndirectString(icon, realIconPath, MAX_PATH, NULL);
openWithItem.icon = QIcon(QString::fromWCharArray(realIconPath));
}
else
{
QFileIconProvider iconProvider;
openWithItem.icon = iconProvider.icon(QFileInfo(iconLocation));
}
// if (isAppx)
// {
// WCHAR realIconPath[MAX_PATH];
// SHLoadIndirectString(icon, realIconPath, MAX_PATH, NULL);
// openWithItem.icon = QIcon(QString::fromWCharArray(realIconPath));
// }
// else
// {
// QFileIconProvider iconProvider;
// openWithItem.icon = iconProvider.icon(QFileInfo(iconLocation));
// }

listOfOpenWithItems.append(openWithItem);
}
Expand Down

0 comments on commit 401fbd3

Please sign in to comment.