From 29c2f9d9c5b397ed244b58e467ba938afbb46103 Mon Sep 17 00:00:00 2001 From: JunjieBai Date: Tue, 14 Nov 2023 14:39:14 +0800 Subject: [PATCH] perf(plugins):use process manager to open applications. --- frontend/mainwindow.cpp | 14 +++++----- libsearch/appsearch/app-search-plugin.cpp | 28 +++++++++---------- libsearch/file-utils.cpp | 27 +++++++++--------- libsearch/notesearch/note-search-plugin.cpp | 14 +++++----- .../settingsearch/settings-search-plugin.cpp | 16 +++++------ libsearch/websearch/web-search-plugin.cpp | 16 +++++------ 6 files changed, 58 insertions(+), 57 deletions(-) diff --git a/frontend/mainwindow.cpp b/frontend/mainwindow.cpp index 4cab030..4bf4d81 100644 --- a/frontend/mainwindow.cpp +++ b/frontend/mainwindow.cpp @@ -468,20 +468,20 @@ bool MainWindow::eventFilter(QObject *watched, QEvent *event) void MainWindow::openSearchSettings() { bool res(false); - QDBusInterface* appLaunchInterface = new QDBusInterface("com.kylin.AppManager", - "/com/kylin/AppManager", - "com.kylin.AppManager", - QDBusConnection::sessionBus()); + QDBusInterface* appLaunchInterface = new QDBusInterface(QStringLiteral("com.kylin.ProcessManager"), + QStringLiteral("/com/kylin/ProcessManager/AppLauncher"), + QStringLiteral("com.kylin.ProcessManager.AppLauncher"), + QDBusConnection::sessionBus()); if(!appLaunchInterface->isValid()) { qWarning() << qPrintable(QDBusConnection::sessionBus().lastError().message()); res = false; } else { appLaunchInterface->setTimeout(10000); - QDBusReply reply = appLaunchInterface->call("LaunchAppWithArguments", "ukui-control-center.desktop", QStringList() << "-m" << "search"); + QDBusReply reply = appLaunchInterface->call("LaunchAppWithArguments", "/usr/share/applications/ukui-control-center.desktop", QStringList{"-m", "search"}); if(reply.isValid()) { - res = reply; + res = true; } else { - qWarning() << "SoftWareCenter dbus called failed!"; + qWarning() << "ProcessManager dbus called failed!" << reply.error(); res = false; } } diff --git a/libsearch/appsearch/app-search-plugin.cpp b/libsearch/appsearch/app-search-plugin.cpp index f2e7150..58558da 100644 --- a/libsearch/appsearch/app-search-plugin.cpp +++ b/libsearch/appsearch/app-search-plugin.cpp @@ -285,20 +285,20 @@ bool AppSearchPlugin::launch(const QString &path) invokeActions(InvokableAction::HideUI); } bool res(false); - QDBusInterface * appLaunchInterface = new QDBusInterface("com.kylin.AppManager", - "/com/kylin/AppManager", - "com.kylin.AppManager", + QDBusInterface * appLaunchInterface = new QDBusInterface(QStringLiteral("com.kylin.ProcessManager"), + QStringLiteral("/com/kylin/ProcessManager/AppLauncher"), + QStringLiteral("com.kylin.ProcessManager.AppLauncher"), QDBusConnection::sessionBus()); if(!appLaunchInterface->isValid()) { qWarning() << qPrintable(QDBusConnection::sessionBus().lastError().message()); res = false; } else { appLaunchInterface->setTimeout(10000); - QDBusReply reply = appLaunchInterface->call("LaunchApp", path); + QDBusReply reply = appLaunchInterface->call("LaunchApp", path); if(reply.isValid()) { - res = reply; + res = true; } else { - qWarning() << "AppManager dbus called failed!"; + qWarning() << "ProcessManager dbus called failed!" << reply.error(); res = false; } } @@ -366,24 +366,24 @@ bool AppSearchPlugin::installAppAction(const QString & name) } else { //软件商店未打开,打开软件商店下载此软件 qDebug() << "Softwarecenter has not been launched, now launch it." << name; - QDBusInterface * appLaunchInterface = new QDBusInterface("com.kylin.AppManager", - "/com/kylin/AppManager", - "com.kylin.AppManager", + QDBusInterface * appLaunchInterface = new QDBusInterface(QStringLiteral("com.kylin.ProcessManager"), + QStringLiteral("/com/kylin/ProcessManager/AppLauncher"), + QStringLiteral("com.kylin.ProcessManager.AppLauncher"), QDBusConnection::sessionBus()); if(!appLaunchInterface->isValid()) { qWarning() << qPrintable(QDBusConnection::sessionBus().lastError().message()); res = false; } else { appLaunchInterface->setTimeout(10000); - QDBusReply reply = appLaunchInterface->call("LaunchAppWithArguments", "kylin-software-center.desktop", QStringList() << "-find" << name); + QDBusReply reply = appLaunchInterface->call("LaunchAppWithArguments", "/usr/share/applications/kylin-software-center.desktop", QStringList() << "-find" << name); if(reply.isValid()) { - res = reply; + res = true; } else { - qWarning() << "SoftWareCenter dbus called failed!"; + qWarning() << "ProcessManager dbus called failed!" << reply.error(); res = false; } } - if(appLaunchInterface) { + if (appLaunchInterface) { delete appLaunchInterface; } appLaunchInterface = nullptr; @@ -391,7 +391,7 @@ bool AppSearchPlugin::installAppAction(const QString & name) res = QProcess::startDetached("kylin-software-center", {"-find", name}); } } - if(interface) { + if (interface) { delete interface; } interface = nullptr; diff --git a/libsearch/file-utils.cpp b/libsearch/file-utils.cpp index 608fe10..f11c5fe 100644 --- a/libsearch/file-utils.cpp +++ b/libsearch/file-utils.cpp @@ -661,8 +661,8 @@ int FileUtils::openFile(QString &path, bool openInDir) } } - GError *error = NULL; - GAppInfo *info = NULL; + GError *error = nullptr; + GAppInfo *info = nullptr; /* * g_app_info_get_default_for_type function get wrong default app, so we get the * default app info from mimeapps.list, and chose the right default app for mimeType file @@ -677,7 +677,7 @@ int FileUtils::openFile(QString &path, bool openInDir) g_error_free(error); } else { gchar *desktopApp = g_key_file_get_string(keyfile, "Default Applications", mimeType.toUtf8(), &error); - if (NULL != desktopApp) { + if (nullptr != desktopApp) { info = (GAppInfo*)g_desktop_app_info_new(desktopApp); g_free (desktopApp); } else { @@ -685,31 +685,32 @@ int FileUtils::openFile(QString &path, bool openInDir) } } g_key_file_free (keyfile); - if(!G_IS_APP_INFO(info)) { + if (!G_IS_APP_INFO(info)) { res = -1; } else { bool isSuccess(false); - QDBusInterface * appLaunchInterface = new QDBusInterface("com.kylin.AppManager", - "/com/kylin/AppManager", - "com.kylin.AppManager", + QDBusInterface * appLaunchInterface = new QDBusInterface(QStringLiteral("com.kylin.ProcessManager"), + QStringLiteral("/com/kylin/ProcessManager/AppLauncher"), + QStringLiteral("com.kylin.ProcessManager.AppLauncher"), QDBusConnection::sessionBus()); - if(!appLaunchInterface->isValid()) { + if (!appLaunchInterface->isValid()) { qWarning() << qPrintable(QDBusConnection::sessionBus().lastError().message()); isSuccess = false; } else { appLaunchInterface->setTimeout(10000); - QDBusReply reply = appLaunchInterface->call("LaunchDefaultAppWithUrl", QUrl::fromLocalFile(path).toString()); + QDBusReply reply = appLaunchInterface->call("LaunchDefaultAppWithUrl", QUrl::fromLocalFile(path).toString()); if(reply.isValid()) { - isSuccess = reply; + isSuccess = true; } else { - qWarning() << "SoftWareCenter dbus called failed!"; + qWarning() << "ProcessManager dbus called failed!" << reply.error(); isSuccess = false; } } - if(appLaunchInterface) { + if (appLaunchInterface) { delete appLaunchInterface; } - appLaunchInterface = NULL; + appLaunchInterface = nullptr; + if (!isSuccess){ QDesktopServices::openUrl(QUrl::fromLocalFile(path)); } diff --git a/libsearch/notesearch/note-search-plugin.cpp b/libsearch/notesearch/note-search-plugin.cpp index 44c8bdc..92b1acb 100644 --- a/libsearch/notesearch/note-search-plugin.cpp +++ b/libsearch/notesearch/note-search-plugin.cpp @@ -83,27 +83,27 @@ void NoteSearchPlugin::openAction(int actionkey, QString key, int type) { DataCollecter::collectLaunchEvent(QStringLiteral("Note Search"), QStringLiteral("open")); bool res(false); - QDBusInterface * appLaunchInterface = new QDBusInterface("com.kylin.AppManager", - "/com/kylin/AppManager", - "com.kylin.AppManager", + QDBusInterface * appLaunchInterface = new QDBusInterface(QStringLiteral("com.kylin.ProcessManager"), + QStringLiteral("/com/kylin/ProcessManager/AppLauncher"), + QStringLiteral("com.kylin.ProcessManager.AppLauncher"), QDBusConnection::sessionBus()); if(!appLaunchInterface->isValid()) { qWarning() << qPrintable(QDBusConnection::sessionBus().lastError().message()); res = false; } else { appLaunchInterface->setTimeout(10000); - QDBusReply reply = appLaunchInterface->call("LaunchAppWithArguments", "ukui-notebook.desktop", QStringList() << "--show" << key); + QDBusReply reply = appLaunchInterface->call("LaunchAppWithArguments", "/usr/share/applications/ukui-notebook.desktop", QStringList() << "--show" << key); if(reply.isValid()) { - res = reply; + res = true; } else { - qWarning() << "SoftWareCenter dbus called failed!"; + qWarning() << "ProcessManager dbus called failed!" << reply.error(); res = false; } } if(appLaunchInterface) { delete appLaunchInterface; } - appLaunchInterface = NULL; + appLaunchInterface = nullptr; if (res) break; QProcess process; diff --git a/libsearch/settingsearch/settings-search-plugin.cpp b/libsearch/settingsearch/settings-search-plugin.cpp index 1fea970..bf8af25 100644 --- a/libsearch/settingsearch/settings-search-plugin.cpp +++ b/libsearch/settingsearch/settings-search-plugin.cpp @@ -71,27 +71,27 @@ void SettingsSearchPlugin::openAction(int actionkey, QString key, int type) { DataCollecter::collectLaunchEvent(QStringLiteral("Settings Search"), QStringLiteral("open")); bool res(false); - QDBusInterface * appLaunchInterface = new QDBusInterface("com.kylin.AppManager", - "/com/kylin/AppManager", - "com.kylin.AppManager", + QDBusInterface * appLaunchInterface = new QDBusInterface(QStringLiteral("com.kylin.ProcessManager"), + QStringLiteral("/com/kylin/ProcessManager/AppLauncher"), + QStringLiteral("com.kylin.ProcessManager.AppLauncher"), QDBusConnection::sessionBus()); if(!appLaunchInterface->isValid()) { qWarning() << qPrintable(QDBusConnection::sessionBus().lastError().message()); res = false; } else { appLaunchInterface->setTimeout(10000); - QDBusReply reply = appLaunchInterface->call("LaunchAppWithArguments", "ukui-control-center.desktop", QStringList() << "-m" << key.toLower()); + QDBusReply reply = appLaunchInterface->call("LaunchAppWithArguments", "/usr/share/applications/ukui-control-center.desktop", QStringList() << "-m" << key.toLower()); if(reply.isValid()) { - res = reply; + res = true; } else { - qWarning() << "SoftWareCenter dbus called failed!"; + qWarning() << "ProcessManager dbus called failed!" << reply.error(); res = false; } } - if(appLaunchInterface) { + if (appLaunchInterface) { delete appLaunchInterface; } - appLaunchInterface = NULL; + appLaunchInterface = nullptr; if (res) break; //打开控制面板对应页面 diff --git a/libsearch/websearch/web-search-plugin.cpp b/libsearch/websearch/web-search-plugin.cpp index 6afe31f..fe56a49 100644 --- a/libsearch/websearch/web-search-plugin.cpp +++ b/libsearch/websearch/web-search-plugin.cpp @@ -97,27 +97,27 @@ void UkuiSearch::WebSearchPlugin::openAction(int actionkey, QString key, int typ address = "http://baidu.com/s?word=" + m_keyWord ; //百度 } bool res(false); - QDBusInterface * appLaunchInterface = new QDBusInterface("com.kylin.AppManager", - "/com/kylin/AppManager", - "com.kylin.AppManager", + QDBusInterface * appLaunchInterface = new QDBusInterface(QStringLiteral("com.kylin.ProcessManager"), + QStringLiteral("/com/kylin/ProcessManager/AppLauncher"), + QStringLiteral("com.kylin.ProcessManager.AppLauncher"), QDBusConnection::sessionBus()); if(!appLaunchInterface->isValid()) { qWarning() << qPrintable(QDBusConnection::sessionBus().lastError().message()); res = false; } else { appLaunchInterface->setTimeout(10000); - QDBusReply reply = appLaunchInterface->call("LaunchDefaultAppWithUrl", address); + QDBusReply reply = appLaunchInterface->call("LaunchDefaultAppWithUrl", address); if(reply.isValid()) { - res = reply; + res = true; } else { - qWarning() << "SoftWareCenter dbus called failed!"; + qWarning() << "ProcessManager dbus called failed!" << reply.error(); res = false; } } - if(appLaunchInterface) { + if (appLaunchInterface) { delete appLaunchInterface; } - appLaunchInterface = NULL; + appLaunchInterface = nullptr; if (res) return; QDesktopServices::openUrl(address);