Files

615 lines
20 KiB
C++
Raw Permalink Normal View History

2020-01-17 13:56:30 +08:00
/*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
* 2010-2016 LXQt team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301, USA.
**/
2019-07-04 15:46:12 +08:00
#include "modulemanager.h"
#include "ukuimodule.h"
2019-12-31 09:29:25 +08:00
#include "idlewatcher.h"
2022-03-22 15:48:08 +08:00
#include "ukuismserver.h"
#include "ukuisessiondebug.h"
2019-07-04 15:46:12 +08:00
2019-07-27 17:45:54 +08:00
#include <QCoreApplication>
2019-12-30 09:49:50 +08:00
#include "xdgautostart.h"
#include "xdgdesktopfile.h"
#include "xdgdirs.h"
2019-07-04 15:46:12 +08:00
#include <QFileInfo>
2019-07-13 17:57:05 +08:00
#include <QStringList>
#include <QSettings>
#include <QStandardPaths>
2019-07-04 15:46:12 +08:00
#include <QDebug>
#include <QGSettings/QGSettings>
// #include <QSoundEffect>
2020-12-02 10:30:23 +08:00
#include <QDBusInterface>
2021-02-27 17:37:43 +08:00
#include <QDir>
/* qt会将glib里的signals成员识别为宏,所以取消该宏
* 后面如果用到signals时,使用Q_SIGNALS代替即可
**/
#ifdef signals
#undef signals
#endif
2019-07-04 15:46:12 +08:00
#define SESSION_REQUIRED_COMPONENTS "org.ukui.session.required-components"
#define SESSION_REQUIRED_COMPONENTS_PATH "/org/ukui/desktop/session/required-components/"
2022-03-22 15:48:08 +08:00
extern UKUISMServer*& getGlobalServer();
2022-04-28 10:55:48 +08:00
//kylin-kmre-manager在ukui-session之前已经被启动,在执行恢复会话的时候,其还未注册到ukui-session中,所以需要对其进行特殊处理
std::map<QString, int> ModuleManager::m_startupMap = {{QString("/usr/bin/kylin-kmre-manager"), 1}};
2022-03-22 15:48:08 +08:00
void ModuleManager::playBootMusic(bool arg)
{
2021-03-06 16:01:06 +08:00
//set default value of whether boot-music is opened
2020-08-18 14:43:21 +08:00
bool play_music = true;
2022-03-22 15:48:08 +08:00
if (QGSettings::isSchemaInstalled("org.ukui.session")) {
QGSettings *gset = new QGSettings("org.ukui.session", "/org/ukui/desktop/session/", this);
if (gset == NULL) {
qDebug() << "QGSettings init error";
2021-03-06 16:01:06 +08:00
free(gset);
return;
}
2021-11-15 15:16:40 +08:00
QString xdg_session_type = qgetenv("XDG_SESSION_TYPE");
2022-03-22 15:48:08 +08:00
if (arg) {
2021-09-29 11:44:55 +08:00
play_music = gset->get("startup-music").toBool();
if (play_music) {
2022-03-22 15:48:08 +08:00
if (xdg_session_type == "wayland") {
2021-11-15 15:16:40 +08:00
QProcess::startDetached("paplay --volume=23456 /usr/share/ukui/ukui-session-manager/startup.wav");
2022-03-22 15:48:08 +08:00
} else {
2021-11-15 15:16:40 +08:00
QProcess::startDetached("aplay /usr/share/ukui/ukui-session-manager/startup.wav");
2022-03-22 15:48:08 +08:00
}
2021-09-29 11:44:55 +08:00
}
2022-03-22 15:48:08 +08:00
} else {
2021-09-29 11:44:55 +08:00
play_music = gset->get("weakup-music").toBool();
if (play_music) {
2021-11-15 15:16:40 +08:00
if (xdg_session_type == "wayland") {
QProcess::startDetached("paplay --volume=23456 /usr/share/ukui/ukui-session-manager/weakup.wav");
2022-03-22 15:48:08 +08:00
} else {
2021-11-15 15:16:40 +08:00
QProcess::startDetached("aplay /usr/share/ukui/ukui-session-manager/weakup.wav");
2022-03-22 15:48:08 +08:00
}
2021-03-06 16:01:06 +08:00
}
}
2020-08-18 14:43:21 +08:00
}
}
//睡眠转休眠判断
bool isSuspendToHibernate()
{
2022-04-21 10:46:21 +08:00
QString path = "/sys/power/wakeup_reason";
if (!QFile::exists(path)) {
return false;
}
QFile wakeup_reason_file(path);
wakeup_reason_file.open(QIODevice::ReadOnly | QIODevice::Text);
QString wakeupReason = wakeup_reason_file.readAll().simplified();
wakeup_reason_file.close();
if (QString::compare(wakeupReason,"0xaa") == 0) {
qDebug()<< "Suspend to Hibernate, wakeup_reason is "<<wakeupReason;
return true;
}
return false;
}
2022-03-22 15:48:08 +08:00
ModuleManager::ModuleManager( QObject* parent) : QObject(parent)
2019-07-04 15:46:12 +08:00
{
2021-03-02 13:43:10 +08:00
QDBusConnection::systemBus().connect(QString("org.freedesktop.login1"),
QString("/org/freedesktop/login1"),
QString("org.freedesktop.login1.Manager"),
QString("PrepareForSleep"), this, SLOT(weakup(bool)));
constructStartupList();
2019-07-04 15:46:12 +08:00
}
2022-03-22 15:48:08 +08:00
void ModuleManager::weakup(bool arg)
{
if (arg) {
qDebug() << "准备执行睡眠休眠";
} else {
qDebug() << "从睡眠休眠中唤醒";
if (!isSuspendToHibernate()) {
qDebug() << "播放唤醒音乐";
playBootMusic(false);
}
}
2021-03-02 13:43:10 +08:00
}
2019-07-04 15:46:12 +08:00
ModuleManager::~ModuleManager()
{
ModulesMapIterator i(mNameMap);
2022-03-22 15:48:08 +08:00
while (i.hasNext()) {
2019-07-04 15:46:12 +08:00
i.next();
auto p = i.value();
disconnect(p, SIGNAL(finished(int, QProcess::ExitStatus)), nullptr, nullptr);
delete p;
mNameMap[i.key()] = nullptr;
}
}
void ModuleManager::constructStartupList()
2019-07-04 15:46:12 +08:00
{
const QByteArray id(SESSION_REQUIRED_COMPONENTS);
QString window_manager;
QString panel;
QString file_manager;
QString wm_notfound;
2020-04-18 20:36:34 +08:00
if (QGSettings::isSchemaInstalled(id)) {
2022-03-22 15:48:08 +08:00
const QGSettings *gs = new QGSettings(SESSION_REQUIRED_COMPONENTS, SESSION_REQUIRED_COMPONENTS_PATH, this);
if (gs == NULL) {
qDebug() << "QGSettings init error";
2021-03-06 16:01:06 +08:00
return;
}
window_manager = gs->get("windowmanager").toString() + ".desktop";
panel = gs->get("panel").toString() + ".desktop";
file_manager = gs->get("filemanager").toString() + ".desktop";
wm_notfound = gs->get("windowmanager").toString();
2020-04-18 20:36:34 +08:00
} else {
//gsetting安装失败,或无法获取,设置默认值
qDebug() << "从gsettings 中或取值失败,设置默认值";
window_manager = "ukwm.desktop";
panel = "ukui-panel.desktop";
file_manager = "peony-qt-desktop.desktop";
}
2021-11-15 15:16:40 +08:00
QString xdg_session_type = qgetenv("XDG_SESSION_TYPE");
if (xdg_session_type == "wayland") {
isWayland = true;
}
QStringList desktop_paths;
2021-11-15 15:16:40 +08:00
desktop_paths << "/usr/share/applications";
desktop_paths << "/etc/xdg/autostart";
bool panel_found = false;
bool fm_found = false;
bool wm_found = false;
2021-02-27 17:37:43 +08:00
//const auto files = XdgAutoStart::desktopFileList(desktop_paths, false);
for (const QString &dirName : const_cast<const QStringList&>(desktop_paths)) {
QDir dir(dirName);
2022-03-22 15:48:08 +08:00
if (!dir.exists()) continue;
2021-02-27 17:37:43 +08:00
const QFileInfoList files = dir.entryInfoList(QStringList(QLatin1String("*.desktop")), QDir::Files | QDir::Readable);
for (const QFileInfo &fi : files) {
if (fi.fileName() == panel) {
mPanel.load(fi.absoluteFilePath());
panel_found = true;
qDebug() << "panel has been found";
}
if (fi.fileName() == file_manager) {
mFileManager.load(fi.absoluteFilePath());
fm_found = true;
qDebug() << "filemanager has been found";
}
if (fi.fileName() == window_manager) {
mWindowManager.load(fi.absoluteFilePath());
wm_found = true;
qDebug() << "windowmanager has been found";
}
2021-02-27 17:37:43 +08:00
if (fm_found && panel_found && wm_found)
break;
}
}
2022-03-22 15:48:08 +08:00
if (!panel_found || !fm_found || !wm_found) isDirectInstall = true;
if (isDirectInstall) {
wmFound = wm_found;
}
2021-08-16 14:00:10 +08:00
2020-04-18 20:36:34 +08:00
if (wm_found == false) {
2020-06-18 13:10:17 +08:00
QFileInfo check_ukwm("/usr/share/applications/ukwm.desktop");
QFileInfo check_ukuikwin("/usr/share/applications/ukui-kwin.desktop");
2022-03-22 15:48:08 +08:00
if (check_ukwm.exists()) {
2020-06-18 13:10:17 +08:00
window_manager = "ukwm.desktop";
2021-02-27 17:37:43 +08:00
mWindowManager.load("/usr/share/applications/ukwm.desktop");
2022-03-22 15:48:08 +08:00
} else if (check_ukuikwin.exists()) {
2020-06-18 13:10:17 +08:00
window_manager = "ukui-kwin.desktop";
2021-02-27 17:37:43 +08:00
mWindowManager.load("/usr/share/applications/ukui-kwin.desktop");
2020-06-18 13:10:17 +08:00
}
2021-02-27 17:37:43 +08:00
wm_found = true;
2020-06-18 13:10:17 +08:00
}
//配置文件所给的窗口管理器找不到.desktop文件时,将所给QString设为可执行命令,创建一个desktop文件赋给mWindowManager
// if (wm_found == false) {
// mWindowManager = XdgDesktopFile(XdgDesktopFile::ApplicationType,"window-manager", wm_notfound);
// qDebug() << "windowmanager has been created";
// }
QString desktop_phase = "X-UKUI-Autostart-Phase";
QString desktop_type = "Type";
2020-03-07 19:52:28 +08:00
//设置excludeHidden为true,判断所有desktop文件的Hidden值,若为true,则将其从自启列表中去掉
const XdgDesktopFileList all_file_list = XdgAutoStart::desktopFileList(true);
2022-03-22 15:48:08 +08:00
for (XdgDesktopFileList::const_iterator i = all_file_list.constBegin(); i != all_file_list.constEnd(); ++i) {
2020-07-25 16:01:23 +08:00
QString filename = QFileInfo(i->fileName()).fileName();
2022-03-22 15:48:08 +08:00
if (filename == panel || filename == file_manager || filename == window_manager) {
2020-07-25 16:01:23 +08:00
continue;
}
const XdgDesktopFile file = *i;
if (i->contains(desktop_phase)) {
2022-03-22 15:48:08 +08:00
QStringList s1 = file.value(desktop_phase).toString().split(QLatin1Char(';'));
if (s1.contains("Initialization")) {
mInitialization << file;
} else if (s1.contains("Desktop")) {
mDesktop << file;
} else if (s1.contains("Application")) {
mApplication << file;
}
} else if (i->contains(desktop_type)) {
QStringList s2 = file.value(desktop_type).toString().split(QLatin1Char(';'));
if (s2.contains("Application")) {
mApplication << file;
}
}
}
QStringList force_app_paths;
force_app_paths << "/usr/share/ukui/applications";
const XdgDesktopFileList force_file_list = XdgAutoStart::desktopFileList(force_app_paths, true);
2022-03-22 15:48:08 +08:00
for (XdgDesktopFileList::const_iterator i = force_file_list.constBegin(); i != force_file_list.constEnd(); ++i) {
qDebug() << (*i).fileName();
mForceApplication << *i;
2019-12-31 11:13:26 +08:00
}
2019-07-04 15:46:12 +08:00
}
/* Startup Phare:
* Initialization
* WindowManager
* Panel
* FileManager
* Desktop
* Application
*
*/
2020-11-24 21:47:51 +08:00
2022-03-22 15:48:08 +08:00
bool ModuleManager::startModuleTimer(QTimer *timer, int i)
{
timer->setSingleShot(true);
2022-03-22 15:48:08 +08:00
connect(timer, SIGNAL(timeout()), this, SLOT(timeup()));
timer->start(i * 1000);
2021-02-27 17:37:43 +08:00
return true;
}
2022-03-22 15:48:08 +08:00
void ModuleManager::startupfinished(const QString &appName, const QString &string)
{
2021-03-22 09:48:09 +08:00
qDebug() << "moudle :" + appName + " startup finished, and it want to say " + string;
2022-03-22 15:48:08 +08:00
if (appName == "ukui-settings-daemon") {
2021-11-15 15:16:40 +08:00
tusd->stop();
2021-03-22 10:32:20 +08:00
emit usdfinished();
return;
}
2022-03-22 15:48:08 +08:00
if (appName == "ukui-kwin") {
2021-11-15 15:16:40 +08:00
twm->stop();
isWMStarted = true;
2020-11-28 17:26:00 +08:00
emit wmfinished();
return;
}
2022-03-22 15:48:08 +08:00
if (appName == "ukui-panel") {
2021-11-15 15:16:40 +08:00
tpanel->stop();
isPanelStarted = true;
2020-11-28 17:26:00 +08:00
emit panelfinished();
return;
}
2022-03-22 15:48:08 +08:00
if (appName == "peony-qt-desktop") {
2021-11-15 15:16:40 +08:00
tdesktop->stop();
isDesktopStarted = true;
2021-02-27 17:37:43 +08:00
emit desktopfinished();
return;
}
2020-11-28 17:26:00 +08:00
}
2022-03-22 15:48:08 +08:00
void ModuleManager::timeup()
{
2021-02-27 17:37:43 +08:00
QTimer *time_out = qobject_cast<QTimer*>(sender());
2022-03-22 15:48:08 +08:00
if (time_out == tusd) {
qDebug() << "usd超时";
2021-11-15 15:16:40 +08:00
emit usdfinished();
2021-03-22 10:32:20 +08:00
return;
}
2022-03-22 15:48:08 +08:00
if (time_out == twm) {
2021-09-29 11:44:55 +08:00
qDebug() <<"wm超时";
2021-11-15 15:16:40 +08:00
isWMStarted = true;
emit wmfinished();
2020-11-28 17:26:00 +08:00
return;
}
2022-03-22 15:48:08 +08:00
if (time_out == tpanel) {
qDebug() << "panel超时";
2021-11-15 15:16:40 +08:00
isPanelStarted = true;
emit panelfinished();
2020-11-28 17:26:00 +08:00
return;
}
2022-03-22 15:48:08 +08:00
if (time_out == tdesktop) {
qDebug() << "peony-qt-desktop超时";
2021-11-15 15:16:40 +08:00
isDesktopStarted = true;
emit desktopfinished();
2021-02-27 17:37:43 +08:00
return;
}
}
2022-03-22 15:48:08 +08:00
void ModuleManager::startCompsite()
{
2021-11-15 15:16:40 +08:00
if (isWayland) return;
2021-07-05 15:02:14 +08:00
qDebug() << "Enter:: startCompsite";
2022-03-22 15:48:08 +08:00
if (!isPanelStarted || !isDesktopStarted || !isWMStarted) return;// || !isWMStarted
2021-08-16 14:00:10 +08:00
2022-03-22 15:48:08 +08:00
if (isCompsiteStarted) return;
2021-08-16 14:00:10 +08:00
isCompsiteStarted = true;
2021-07-05 15:02:14 +08:00
// start composite
QDBusInterface dbus("org.ukui.KWin", "/Compositor", "org.ukui.kwin.Compositing", QDBusConnection::sessionBus());
2021-08-16 14:00:10 +08:00
2021-07-05 15:02:14 +08:00
if (!dbus.isValid()) {
2022-03-22 15:48:08 +08:00
qWarning() << "dbusCall: QDBusInterface is invalid ; kwin do not exit!";
timerUpdate();
} else {
qDebug() << "Start composite";
dbus.call("resume");
2021-11-15 15:16:40 +08:00
timerUpdate();
2021-07-05 15:02:14 +08:00
}
}
void ModuleManager::startup()
{
2022-03-22 15:48:08 +08:00
//直接安装进入的流程
2021-08-16 14:00:10 +08:00
const QFile file_installer("/etc/xdg/autostart/kylin-os-installer.desktop");
2022-03-22 15:48:08 +08:00
if (file_installer.exists() && isDirectInstall) {
if (wmFound) {
isPanelStarted = true;
isDesktopStarted = true;
connect(this, &ModuleManager::wmfinished, [=](){ startCompsite(); });
startProcess(mWindowManager, false);
startModuleTimer(twm, 18);
} else {
timerUpdate();
}
return;
2021-08-16 14:00:10 +08:00
}
2021-11-15 15:16:40 +08:00
if (isWayland) {
startProcess("hwaudioservice", true);
}
2021-11-15 15:16:40 +08:00
if (!isWayland) {
connect(this, &ModuleManager::panelfinished, [=](){ startCompsite(); });
connect(this, &ModuleManager::wmfinished, [=](){ startCompsite(); });
connect(this, &ModuleManager::desktopfinished, [=](){ startCompsite(); });
dostartwm();
} else {
QTimer::singleShot(500, this, SLOT(timerUpdate()));
}
2021-03-22 10:32:20 +08:00
qDebug() << "Start Initialization app: ";
for (XdgDesktopFileList::const_iterator i = mInitialization.constBegin(); i != mInitialization.constEnd(); ++i) {
startProcess(*i, true);
}
2022-03-22 15:48:08 +08:00
startModuleTimer(tusd,5);
2021-07-05 15:02:14 +08:00
startProcess(mPanel, true);
2022-03-22 15:48:08 +08:00
startModuleTimer(tpanel,5);
2021-11-15 15:16:40 +08:00
2021-07-05 15:02:14 +08:00
startProcess(mFileManager, true);
2022-03-22 15:48:08 +08:00
startModuleTimer(tdesktop,5);
2021-07-05 15:02:14 +08:00
2022-03-22 15:48:08 +08:00
if (!isWayland) {
qDebug() << "Start desktop: ";
for (XdgDesktopFileList::const_iterator i = mDesktop.constBegin(); i != mDesktop.constEnd(); ++i) {
startProcess(*i, true);
}
2021-07-05 15:02:14 +08:00
}
2021-02-27 17:37:43 +08:00
}
2022-03-22 15:48:08 +08:00
void ModuleManager::dostartwm()
{
if (mWindowManager.name() != "UKUI-KWin") {
qDebug() << "Start window manager: " << mWindowManager.name();
2021-11-15 15:16:40 +08:00
startProcess(mWindowManager, false);
2022-03-22 15:48:08 +08:00
startModuleTimer(twm, 18);
} else {
2021-11-15 15:16:40 +08:00
startProcess(mWindowManager, false);
isWMStarted = true;
2021-01-27 10:10:36 +08:00
}
2020-01-17 13:56:30 +08:00
}
2022-03-22 15:48:08 +08:00
void ModuleManager::timerUpdate()
{
playBootMusic(true);
2021-02-02 15:19:46 +08:00
QTimer::singleShot(500, this, [&](){
emit finished();
});
2022-03-22 15:48:08 +08:00
if (isWayland) {
qDebug() << "Start desktop: ";
for (XdgDesktopFileList::const_iterator i = mDesktop.constBegin(); i != mDesktop.constEnd(); ++i) {
startProcess(*i, true);
}
}
qDebug() << "Start application: ";
QFile file_nm("/etc/xdg/autostart/kylin-nm.desktop");
QFile file_sogou("/usr/bin/sogouImeService");
2020-04-18 20:36:34 +08:00
for (XdgDesktopFileList::const_iterator i = mApplication.constBegin(); i != mApplication.constEnd(); ++i) {
2020-03-07 19:52:28 +08:00
qDebug() << i->fileName();
2022-03-22 15:48:08 +08:00
if (i->fileName() == "/etc/xdg/autostart/nm-applet.desktop" && file_nm.exists()) {
2019-12-09 15:22:02 +08:00
qDebug() << "the kylin-nm exist so the nm-applet will not start";
continue;
}
2022-03-22 15:48:08 +08:00
if (i->fileName() == "/etc/xdg/autostart/fcitx-qimpanel-autostart.desktop" && file_sogou.exists()) {
qDebug() << "the sogouImeService exist so the fcitx-ui-qimpanel will not start";
continue;
}
startProcess(*i, false);
}
qDebug() << "Start force application: ";
2022-03-22 15:48:08 +08:00
for (XdgDesktopFileList::const_iterator i = mForceApplication.constBegin(); i != mForceApplication.constEnd(); ++i) {
startProcess(*i, true);
2019-07-04 15:46:12 +08:00
}
2022-03-22 15:48:08 +08:00
if (QGSettings::isSchemaInstalled("org.ukui.session")) {
QGSettings *gset = new QGSettings("org.ukui.session", "/org/ukui/desktop/session/", this);
2022-04-27 14:51:25 +08:00
QStringList keyList = gset->keys();
2022-04-27 16:21:35 +08:00
//keyList中的值是restoreSession而不是restore-session
if (keyList.contains("restoreSession")) {
2022-04-27 14:51:25 +08:00
QVariant res = gset->get("restore-session");
bool restoreSession = res.toBool();
if (restoreSession) {
2022-04-27 16:21:35 +08:00
//此处加上一个半秒的延迟可以更快的加速恢复会话,实验发现如果不加延迟,在此处直接开始恢复会话,反而会更慢
QTimer::singleShot(500, [](){
qDebug(UKUI_SESSION) << "began restore session";
getGlobalServer()->restoreSession();
});
2022-04-27 14:51:25 +08:00
}
} else {
qDebug() << "lack of required QGsettings";
2022-03-22 15:48:08 +08:00
}
}
2019-07-04 15:46:12 +08:00
}
2022-03-22 15:48:08 +08:00
void ModuleManager::startProcess(const XdgDesktopFile &file, bool required)
2019-07-04 15:46:12 +08:00
{
QStringList args = file.expandExecString();
2020-04-18 20:36:34 +08:00
if (args.isEmpty()) {
qWarning() << "Wrong desktop file: " << file.fileName();
2019-07-04 15:46:12 +08:00
return;
}
QString name = QFileInfo(file.fileName()).fileName();
2020-04-18 20:36:34 +08:00
if (!mNameMap.contains(name)) {
2022-03-22 15:48:08 +08:00
UkuiModule *proc = new UkuiModule(file, this);
connect(proc, &UkuiModule::moduleStateChanged, this, &ModuleManager::moduleStateChanged);
proc->start();
2019-07-04 15:46:12 +08:00
mNameMap[name] = proc;
2020-04-18 20:36:34 +08:00
if (required || autoRestart(file)) {
connect(proc, SIGNAL(finished(int, QProcess::ExitStatus)),
2022-03-22 15:48:08 +08:00
this, SLOT(restartModules(int, QProcess::ExitStatus)));
}
}
2019-07-04 15:46:12 +08:00
}
void ModuleManager::startProcess(const QString& name, bool required)
2019-07-04 15:46:12 +08:00
{
QString desktop_name = name + ".desktop";
QStringList desktop_paths;
desktop_paths << "/usr/share/applications";
const auto files = XdgAutoStart::desktopFileList(desktop_paths, false);
2020-04-18 20:36:34 +08:00
for (const XdgDesktopFile& file : files) {
if (QFileInfo(file.fileName()).fileName() == desktop_name) {
startProcess(file, required);
return;
2019-07-04 15:46:12 +08:00
}
}
}
void ModuleManager::stopProcess(const QString& name)
{
2022-03-22 15:48:08 +08:00
if (mNameMap.contains(name)) {
2019-07-04 15:46:12 +08:00
mNameMap[name]->terminate();
2022-03-22 15:48:08 +08:00
}
2019-07-04 15:46:12 +08:00
}
bool ModuleManager::nativeEventFilter(const QByteArray &eventType, void *message, long *result)
{
if (eventType != "xcb_generic_event_t") // We only want to handle XCB events
return false;
return false;
}
2019-07-13 17:57:05 +08:00
2022-03-22 15:48:08 +08:00
void ModuleManager::insertStartupList(QString &&str)
{
if (!str.isEmpty()) {
m_startupMap[std::forward<QString>(str)] = 1;
}
}
bool ModuleManager::isProgramStarted(QString &&str)
{
auto it = m_startupMap.find(std::forward<QString>(str));
if (it != m_startupMap.end()) {
return true;
}
return false;
}
bool ModuleManager::autoRestart(const XdgDesktopFile &file)
{
QString auto_restart = "X-UKUI-AutoRestart";
return file.value(auto_restart).toBool();
}
2019-07-13 17:57:05 +08:00
void ModuleManager::restartModules(int /*exitCode*/, QProcess::ExitStatus exitStatus)
{
2022-03-22 15:48:08 +08:00
if (getGlobalServer()->prepareForShutdown()) {
qDebug() << "Logout phase, don't Restart";
return;
}
UkuiModule *proc = qobject_cast<UkuiModule*>(sender());
if (nullptr == proc) {
qWarning() << "Got an invalid (null) module to restart, Ignoring it";
return;
}
2022-03-22 15:48:08 +08:00
//需要做出修改
if (proc->restartNum > 10) {
2019-12-31 11:13:26 +08:00
mNameMap.remove(proc->fileName);
disconnect(proc, SIGNAL(finished(int, QProcess::ExitStatus)), nullptr, nullptr);
proc->deleteLater();
return;
}
2019-07-13 17:57:05 +08:00
2020-04-18 20:36:34 +08:00
if (!proc->isTerminating()) {
2021-03-16 15:53:54 +08:00
//根据退出码来判断程序是否属于异常退出。
2019-07-13 17:57:05 +08:00
QString procName = proc->file.name();
2022-03-22 15:48:08 +08:00
if (proc->exitCode() == 0) {
qDebug() << "Process" << procName << "(" << proc << ") exited correctly. " << "With the exitcode = " << proc->exitCode() << ",exitStatus = " << exitStatus;
} else {
qDebug() << "Process" << procName << "(" << proc << ") has to be restarted. " << "With the exitcode = " << proc->exitCode() << ",exitStatus = " << exitStatus;
proc->start();
proc->restartNum++;
return;
}
2019-07-13 17:57:05 +08:00
}
mNameMap.remove(proc->fileName);
proc->deleteLater();
}
2019-07-27 17:45:54 +08:00
void ModuleManager::logout(bool doExit)
{
// /org/freedesktop/login1/session/self 和 /org/freedesktop/login1/session/auto
//有什么区别
2020-12-02 10:30:23 +08:00
QDBusInterface face("org.freedesktop.login1",\
"/org/freedesktop/login1/session/self",\
"org.freedesktop.login1.Session",\
QDBusConnection::systemBus());
2020-04-18 20:36:34 +08:00
if (doExit) {
face.call("Terminate");
exit(0);
}
2019-07-27 17:45:54 +08:00
}
#include "modulemanager.moc"