Skip to content

Commit

Permalink
fix: the daemon restarts repeatedly when there is no network
Browse files Browse the repository at this point in the history
daemon会因为窗口的接口调用反复异常重启
这会导致托盘图标出现闪烁在没有网络时

Log:
Issues: linuxdeepin/developer-center#7936
  • Loading branch information
myml committed May 9, 2024
1 parent 6c962f6 commit 4032fb7
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/dbusservice/com.deepin.Home.Daemon.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,8 @@
<method name="getVersion">
<arg type="s" direction="out"/>
</method>
<method name="isReady">
<arg type="b" direction="out"/>
</method>
</interface>
</node>
25 changes: 21 additions & 4 deletions src/main/homeDaemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ HomeDaemon::HomeDaemon(QObject *parent)
{
// 网络请求
m_api = new API("http_cache", this);
m_am_app_home = new ApplicationManager1Application("org.desktopspec.ApplicationManager1",
"/org/desktopspec/ApplicationManager1/deepin_2dhome",
QDBusConnection::sessionBus(),
this);
m_am_app_home
= new ApplicationManager1Application("org.desktopspec.ApplicationManager1",
"/org/desktopspec/ApplicationManager1/deepin_2dhome",
QDBusConnection::sessionBus(),
this);
qCDebug(logger) << m_am_app_home->service() << "isValid" << m_am_app_home->isValid();
// 初始化系统托盘
m_menu = new QMenu();
Expand Down Expand Up @@ -198,6 +199,7 @@ void HomeDaemon::run()
refreshChannel(cronID, channel);
});
}
m_isReady = true;
} catch (APIException exp) {
qCWarning(logger) << "Refresh Node Error" << exp.err_code << exp.err_msg;
} catch (...) {
Expand Down Expand Up @@ -501,4 +503,19 @@ void HomeDaemon::activeMainWindows()
QString HomeDaemon::getVersion()
{
return APP_VERSION;
}

// 返回daemon是否准备好
bool HomeDaemon::isReady()
{
if (m_isReady) {
return true;
}
try {
refreshNode();
m_isReady = true;
return true;
} catch (...) {
return false;
}
}
4 changes: 4 additions & 0 deletions src/main/homeDaemon.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,14 @@ class HomeDaemon : public QObject, protected QDBusContext
Account *m_account = nullptr;
QLoggingCategory logger = QLoggingCategory("daemon");
ApplicationManager1Application *m_am_app_home = nullptr;
bool m_isReady = false;

public:
explicit HomeDaemon(QObject *parent = nullptr);
~HomeDaemon();
// 启动定时器,循环刷新消息
void start();

private:
// 初始化托盘
void initSysTrayIcon();
Expand Down Expand Up @@ -130,6 +132,8 @@ public slots:
void activeMainWindows();
// 获取当前应用版本信息
QString getVersion();
// 获取daemon是否准备好了
bool isReady();
signals:
// 用户登录状态变动,客户端收到通知后,可以调用daemon获取新的用户状态
void userInfoChanged();
Expand Down
15 changes: 14 additions & 1 deletion src/maincomponentplugin/worker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ Worker::Worker(QObject *parent)
connect(m_daemon, &HomeDaemonProxy::showMainWindow, this, &Worker::showMainWindow);

// 在主窗口显示时,检查一次系统登陆状态,避免因daemon开机启动过早导致登陆状态未和系统保持同步
m_daemon->checkLogin();
if (m_daemon->isReady()) {
m_daemon->checkLogin();
}

// 为避免应用升级后接口不兼容,如果客户端和daemon版本不一致,重启一次daemon
#ifndef QT_DEBUG
Expand All @@ -53,12 +55,18 @@ Worker::~Worker() {}

QString Worker::getNode()
{
if (!isReady()) {
return "";
}
qCDebug(this->logger) << "get node";
return m_daemon->getNode();
};

QString Worker::getLanguage()
{
if (!isReady()) {
return "";
}
qCDebug(this->logger) << "get language";
return m_daemon->getLanguage();
};
Expand Down Expand Up @@ -288,4 +296,9 @@ void Worker::getSysInfo()
this->signalsGetSysInfoResp(watcher->result());
});
watcher->setFuture(future);
}

bool Worker::isReady()
{
return m_daemon->isReady();
}
2 changes: 2 additions & 0 deletions src/maincomponentplugin/worker.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ public slots:
QString genUUID();
// 获取系统信息
void getSysInfo();
// 获取worker是否准备好
bool isReady();
signals:
void userInfoChanged();
void messageChanged();
Expand Down

0 comments on commit 4032fb7

Please sign in to comment.