diff --git a/src/apps/dde-file-manager/main.cpp b/src/apps/dde-file-manager/main.cpp index 8313f4752d..7878f79d82 100644 --- a/src/apps/dde-file-manager/main.cpp +++ b/src/apps/dde-file-manager/main.cpp @@ -337,19 +337,19 @@ int main(int argc, char *argv[]) } else { qCInfo(logAppFileManager) << "new client"; a.handleNewClient(uniqueKey); - return 0; + ::_exit(0); } qCWarning(logAppFileManager) << " --- app start --- pid = " << a.applicationPid(); int ret { a.exec() }; + a.closeServer(); DPF_NAMESPACE::LifeCycle::shutdownPlugins(); bool enableHeadless { DConfigManager::instance()->value(kDefaultCfgPath, "dfm.headless", false).toBool() }; bool isSigterm { qApp->property("SIGTERM").toBool() }; if (!isSigterm && enableHeadless && !SysInfoUtils::isOpenAsAdmin()) { - a.closeServer(); QProcess::startDetached(QString(argv[0]), { "-d" }); } - return ret; + ::_exit(ret); } diff --git a/src/apps/dde-file-manager/singleapplication.cpp b/src/apps/dde-file-manager/singleapplication.cpp index 0e247a36d9..268f907086 100644 --- a/src/apps/dde-file-manager/singleapplication.cpp +++ b/src/apps/dde-file-manager/singleapplication.cpp @@ -36,6 +36,7 @@ SingleApplication::~SingleApplication() void SingleApplication::initConnect() { connect(localServer, &QLocalServer::newConnection, this, &SingleApplication::handleConnection); + connect(this, &QApplication::aboutToQuit, this, &SingleApplication::closeServer); } QLocalSocket *SingleApplication::getNewClientConnect(const QString &key, const QByteArray &message) diff --git a/src/dfm-base/utils/clipboardmonitor.cpp b/src/dfm-base/utils/clipboardmonitor.cpp index adb9d93306..14b03ec35c 100644 --- a/src/dfm-base/utils/clipboardmonitor.cpp +++ b/src/dfm-base/utils/clipboardmonitor.cpp @@ -92,23 +92,23 @@ ClipboardMonitor::ClipboardMonitor(QObject *parent) : QThread(parent) { // 创建 XCB 连接 - connection = nullptr; - connection = xcb_connect(nullptr, nullptr); - if (xcb_connection_has_error(connection)) { - for (size_t i = 0; i < 100; i++) { - std::string displayStr(":"); - displayStr += std::to_string(i); - // setenv("DISPLAY",displayStr.c_str(),1); - connection = xcb_connect(displayStr.c_str(), nullptr); - if (xcb_connection_has_error(connection) == 0) { - break; - } + connection = nullptr; + connection = xcb_connect(nullptr, nullptr); + if (xcb_connection_has_error(connection)) { + for (size_t i = 0; i < 100; i++) { + std::string displayStr(":"); + displayStr += std::to_string(i); + // setenv("DISPLAY",displayStr.c_str(),1); + connection = xcb_connect(displayStr.c_str(), nullptr); + if (xcb_connection_has_error(connection) == 0) { + break; } } + } - if (xcb_connection_has_error(connection)) { - return; - } + if (xcb_connection_has_error(connection)) { + return; + } @@ -121,17 +121,10 @@ ClipboardMonitor::ClipboardMonitor(QObject *parent) m_queryExtension = queryExtension; xcb_discard_reply(connection, xcb_xfixes_query_version(connection, 1, 0).sequence); screen = xcb_setup_roots_iterator(xcb_get_setup(connection)).data; - connect(qApp, &QApplication::aboutToQuit, this, [this](){ - stop(); - this->wait(100); - }); } ClipboardMonitor::~ClipboardMonitor() { - if (connection) { - xcb_disconnect(connection); - } } void ClipboardMonitor::stop() @@ -175,7 +168,8 @@ void ClipboardMonitor::run() while (true) { xcb_generic_event_t *event = xcb_wait_for_event(connection); if (stoped) { - free(event); + if (event) + free(event); break; } if (event) { diff --git a/src/plugins/filemanager/core/dfmplugin-computer/computer.cpp b/src/plugins/filemanager/core/dfmplugin-computer/computer.cpp index a5cd417f66..69b6c4d91e 100644 --- a/src/plugins/filemanager/core/dfmplugin-computer/computer.cpp +++ b/src/plugins/filemanager/core/dfmplugin-computer/computer.cpp @@ -87,6 +87,11 @@ bool Computer::start() return true; } +void Computer::stop() +{ + ComputerItemWatcher::instance()->clearAsyncThread(); +} + void Computer::onWindowOpened(quint64 winId) { auto window = FMWindowsIns.findWindowById(winId); diff --git a/src/plugins/filemanager/core/dfmplugin-computer/computer.h b/src/plugins/filemanager/core/dfmplugin-computer/computer.h index 05281d058d..198a9813a4 100644 --- a/src/plugins/filemanager/core/dfmplugin-computer/computer.h +++ b/src/plugins/filemanager/core/dfmplugin-computer/computer.h @@ -40,6 +40,7 @@ class Computer : public dpf::Plugin public: virtual void initialize() override; virtual bool start() override; + virtual void stop() override; protected Q_SLOTS: void onWindowOpened(quint64 windd); diff --git a/src/plugins/filemanager/core/dfmplugin-computer/watcher/computeritemwatcher.cpp b/src/plugins/filemanager/core/dfmplugin-computer/watcher/computeritemwatcher.cpp index a4f584e4ea..46e3ac01a1 100644 --- a/src/plugins/filemanager/core/dfmplugin-computer/watcher/computeritemwatcher.cpp +++ b/src/plugins/filemanager/core/dfmplugin-computer/watcher/computeritemwatcher.cpp @@ -579,6 +579,13 @@ void ComputerItemWatcher::insertUrlMapper(const QString &devId, const QUrl &mntU routeMapper.insertMulti(devUrl, ComputerUtils::makeBurnUrl(devId)); } +void ComputerItemWatcher::clearAsyncThread() +{ + if (fw) { + fw->waitForFinished(); + } +} + void ComputerItemWatcher::updateSidebarItem(const QUrl &url, const QString &newName, bool editable) { QVariantMap map { @@ -754,15 +761,16 @@ void ComputerItemWatcher::startQueryItems(bool async) }; if (async) { - QFutureWatcher *fw { new QFutureWatcher() }; - fw->setFuture(QtConcurrent::run(this, &ComputerItemWatcher::items)); + fw = new QFutureWatcher(); // if computer view is not init view, no receiver to receive the signal, cause when cd to computer view, shows empty. // on initialize computer view/model, get the cached items in construction. - connect(fw, &QFutureWatcher::finished, this, [fw, afterQueryFunc, this]() { + connect(fw, &QFutureWatcher::finished, this, [afterQueryFunc, this]() { initedDatas = fw->result(); afterQueryFunc(); - delete fw; + fw->deleteLater(); + fw = nullptr; }); + fw->setFuture(QtConcurrent::run(this, &ComputerItemWatcher::items)); return; } diff --git a/src/plugins/filemanager/core/dfmplugin-computer/watcher/computeritemwatcher.h b/src/plugins/filemanager/core/dfmplugin-computer/watcher/computeritemwatcher.h index 1e81a8dcf9..b567f2a442 100644 --- a/src/plugins/filemanager/core/dfmplugin-computer/watcher/computeritemwatcher.h +++ b/src/plugins/filemanager/core/dfmplugin-computer/watcher/computeritemwatcher.h @@ -53,6 +53,7 @@ class ComputerItemWatcher : public QObject void handleSidebarItemsVisiable(); void insertUrlMapper(const QString &devId, const QUrl &mntUrl); + void clearAsyncThread(); static QString userDirGroup(); static QString diskGroup(); @@ -127,6 +128,7 @@ protected Q_SLOTS: QMap groupIds; QMap routeMapper; + QPointer> fw{ nullptr }; }; } #endif // COMPUTERITEMWATCHER_H