fix:#I8EQUH【终端】系统日常运行一段时间后,在文件管理器右键打开的终端窗口没有置顶

This commit is contained in:
yangjianhao 2024-01-12 11:49:49 +08:00 committed by Yue-Lan
parent 6b21eb4cd2
commit eb7712190d
2 changed files with 19 additions and 24 deletions

View File

@ -34,7 +34,9 @@
#include <QtConcurrent> #include <QtConcurrent>
#include <QProcess> #include <QProcess>
#include <QMessageBox> #include <QMessageBox>
#include <QDBusConnection>
#include <QDBusMessage>
#include <QDBusPendingCall>
#include <QDebug> #include <QDebug>
#ifdef KYLIN_COMMON #ifdef KYLIN_COMMON
@ -82,30 +84,23 @@ MateTerminalMenuPlugin::MateTerminalMenuPlugin(QObject *parent) : QObject (paren
} }
void MateTerminalMenuPlugin::openTerminal(){ void MateTerminalMenuPlugin::openTerminal(){
//qDebug()<<"triggered"<<uri;
QUrl url = m_uri; QUrl url = m_uri;
auto directory = url.path().toUtf8().constData(); auto dir = url.path();
gchar **argv = nullptr;
g_shell_parse_argv (terminal_cmd.toUtf8().constData(), nullptr, &argv, nullptr); QStringList args;
GError *err = nullptr; args << "--working-directory" << dir;
g_spawn_async (directory, QString terminal_path = QStandardPaths::locate(QStandardPaths::ApplicationsLocation, "mate-terminal.desktop");
argv, if (terminal_path.isEmpty()) {
nullptr, terminal_path = QFile(terminal_cmd).fileName() + ".desktop";
G_SPAWN_SEARCH_PATH, terminal_path = QStandardPaths::locate(QStandardPaths::ApplicationsLocation, terminal_path);
nullptr, if (!QFile(terminal_path).exists()) {
nullptr, return;
nullptr, }
&err);
if (err) {
qDebug()<<"openTerminal failed:"<<err->message;
g_error_free(err);
err = nullptr;
//try again to open terminal
//maybe this method is better,but still need more test to confirm
tryOpenAgain();
} }
g_strfreev (argv);
QDBusMessage msg = QDBusMessage::createMethodCall("com.kylin.AppManager", "/com/kylin/AppManager", "com.kylin.AppManager", "LaunchAppWithArguments");
msg << terminal_path << args;
QDBusConnection::sessionBus().asyncCall(msg);
} }
void MateTerminalMenuPlugin::tryOpenAgain() void MateTerminalMenuPlugin::tryOpenAgain()

View File

@ -4,7 +4,7 @@
# #
#------------------------------------------------- #-------------------------------------------------
QT += widgets concurrent QT += widgets concurrent dbus
TARGET = peony-menu-plugin-mate-terminal TARGET = peony-menu-plugin-mate-terminal
TEMPLATE = lib TEMPLATE = lib