From 8870cbc799b88f4350cd5ed5d882648c3d5c7496 Mon Sep 17 00:00:00 2001 From: listenerri Date: Fri, 14 Dec 2018 14:09:42 +0800 Subject: [PATCH] fix: sni tray context menu can not be initialize correctly after reboot https://github.com/linuxdeepin/internal-discussion/issues/660 Change-Id: I51d95b7acf58d9550d1646a0d64ebfc8e952f918 --- plugins/tray/snitraywidget.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/plugins/tray/snitraywidget.cpp b/plugins/tray/snitraywidget.cpp index 378ca12c5..78c425078 100644 --- a/plugins/tray/snitraywidget.cpp +++ b/plugins/tray/snitraywidget.cpp @@ -63,7 +63,6 @@ SNITrayWidget::SNITrayWidget(const QString &sniServicePath, QWidget *parent) connect(m_sniInter, &StatusNotifierItem::NewAttentionIcon, this, &SNITrayWidget::refreshAttentionIcon); QTimer::singleShot(0, this, &SNITrayWidget::refreshIcon); - QTimer::singleShot(300, this, &SNITrayWidget::initMenu); } SNITrayWidget::~SNITrayWidget() @@ -114,9 +113,19 @@ bool SNITrayWidget::isValid() void SNITrayWidget::initMenu() { + qDebug() << "using sni service path:" << m_dbusService; + const QString &menuPath = m_sniInter->menu().path(); - m_dbusMenuImporter = new DBusMenuImporter(m_dbusService, menuPath, SYNCHRONOUS, this); + + qDebug() << "using sni menu path:" << menuPath; + + m_dbusMenuImporter = new DBusMenuImporter(m_dbusService, menuPath, ASYNCHRONOUS, this); + + qDebug() << "generate the sni menu object"; + m_menu = m_dbusMenuImporter->menu(); + + qDebug() << "the sni menu obect is:" << m_menu; } /* @@ -197,6 +206,10 @@ void SNITrayWidget::showContextMenu(int x, int y) if (m_sniInter->menu().path().startsWith("/NO_DBUSMENU")) { m_sniInter->ContextMenu(x, y); } else { + if (!m_menu) { + qDebug() << "context menu has not be ready, init menu"; + initMenu(); + } m_menu->popup(QPoint(x, y)); } }