perf(plugins):use process manager to open applications.

This commit is contained in:
JunjieBai 2023-11-14 14:39:14 +08:00 committed by iaom
parent 85c108e17f
commit 29c2f9d9c5
6 changed files with 58 additions and 57 deletions

View File

@ -468,20 +468,20 @@ bool MainWindow::eventFilter(QObject *watched, QEvent *event)
void MainWindow::openSearchSettings() { void MainWindow::openSearchSettings() {
bool res(false); bool res(false);
QDBusInterface* appLaunchInterface = new QDBusInterface("com.kylin.AppManager", QDBusInterface* appLaunchInterface = new QDBusInterface(QStringLiteral("com.kylin.ProcessManager"),
"/com/kylin/AppManager", QStringLiteral("/com/kylin/ProcessManager/AppLauncher"),
"com.kylin.AppManager", QStringLiteral("com.kylin.ProcessManager.AppLauncher"),
QDBusConnection::sessionBus()); QDBusConnection::sessionBus());
if(!appLaunchInterface->isValid()) { if(!appLaunchInterface->isValid()) {
qWarning() << qPrintable(QDBusConnection::sessionBus().lastError().message()); qWarning() << qPrintable(QDBusConnection::sessionBus().lastError().message());
res = false; res = false;
} else { } else {
appLaunchInterface->setTimeout(10000); appLaunchInterface->setTimeout(10000);
QDBusReply<bool> reply = appLaunchInterface->call("LaunchAppWithArguments", "ukui-control-center.desktop", QStringList() << "-m" << "search"); QDBusReply<void> reply = appLaunchInterface->call("LaunchAppWithArguments", "/usr/share/applications/ukui-control-center.desktop", QStringList{"-m", "search"});
if(reply.isValid()) { if(reply.isValid()) {
res = reply; res = true;
} else { } else {
qWarning() << "SoftWareCenter dbus called failed!"; qWarning() << "ProcessManager dbus called failed!" << reply.error();
res = false; res = false;
} }
} }

View File

@ -285,20 +285,20 @@ bool AppSearchPlugin::launch(const QString &path)
invokeActions(InvokableAction::HideUI); invokeActions(InvokableAction::HideUI);
} }
bool res(false); bool res(false);
QDBusInterface * appLaunchInterface = new QDBusInterface("com.kylin.AppManager", QDBusInterface * appLaunchInterface = new QDBusInterface(QStringLiteral("com.kylin.ProcessManager"),
"/com/kylin/AppManager", QStringLiteral("/com/kylin/ProcessManager/AppLauncher"),
"com.kylin.AppManager", QStringLiteral("com.kylin.ProcessManager.AppLauncher"),
QDBusConnection::sessionBus()); QDBusConnection::sessionBus());
if(!appLaunchInterface->isValid()) { if(!appLaunchInterface->isValid()) {
qWarning() << qPrintable(QDBusConnection::sessionBus().lastError().message()); qWarning() << qPrintable(QDBusConnection::sessionBus().lastError().message());
res = false; res = false;
} else { } else {
appLaunchInterface->setTimeout(10000); appLaunchInterface->setTimeout(10000);
QDBusReply<bool> reply = appLaunchInterface->call("LaunchApp", path); QDBusReply<void> reply = appLaunchInterface->call("LaunchApp", path);
if(reply.isValid()) { if(reply.isValid()) {
res = reply; res = true;
} else { } else {
qWarning() << "AppManager dbus called failed!"; qWarning() << "ProcessManager dbus called failed!" << reply.error();
res = false; res = false;
} }
} }
@ -366,24 +366,24 @@ bool AppSearchPlugin::installAppAction(const QString & name)
} else { } else {
//软件商店未打开,打开软件商店下载此软件 //软件商店未打开,打开软件商店下载此软件
qDebug() << "Softwarecenter has not been launched, now launch it." << name; qDebug() << "Softwarecenter has not been launched, now launch it." << name;
QDBusInterface * appLaunchInterface = new QDBusInterface("com.kylin.AppManager", QDBusInterface * appLaunchInterface = new QDBusInterface(QStringLiteral("com.kylin.ProcessManager"),
"/com/kylin/AppManager", QStringLiteral("/com/kylin/ProcessManager/AppLauncher"),
"com.kylin.AppManager", QStringLiteral("com.kylin.ProcessManager.AppLauncher"),
QDBusConnection::sessionBus()); QDBusConnection::sessionBus());
if(!appLaunchInterface->isValid()) { if(!appLaunchInterface->isValid()) {
qWarning() << qPrintable(QDBusConnection::sessionBus().lastError().message()); qWarning() << qPrintable(QDBusConnection::sessionBus().lastError().message());
res = false; res = false;
} else { } else {
appLaunchInterface->setTimeout(10000); appLaunchInterface->setTimeout(10000);
QDBusReply<bool> reply = appLaunchInterface->call("LaunchAppWithArguments", "kylin-software-center.desktop", QStringList() << "-find" << name); QDBusReply<void> reply = appLaunchInterface->call("LaunchAppWithArguments", "/usr/share/applications/kylin-software-center.desktop", QStringList() << "-find" << name);
if(reply.isValid()) { if(reply.isValid()) {
res = reply; res = true;
} else { } else {
qWarning() << "SoftWareCenter dbus called failed!"; qWarning() << "ProcessManager dbus called failed!" << reply.error();
res = false; res = false;
} }
} }
if(appLaunchInterface) { if (appLaunchInterface) {
delete appLaunchInterface; delete appLaunchInterface;
} }
appLaunchInterface = nullptr; appLaunchInterface = nullptr;
@ -391,7 +391,7 @@ bool AppSearchPlugin::installAppAction(const QString & name)
res = QProcess::startDetached("kylin-software-center", {"-find", name}); res = QProcess::startDetached("kylin-software-center", {"-find", name});
} }
} }
if(interface) { if (interface) {
delete interface; delete interface;
} }
interface = nullptr; interface = nullptr;

View File

@ -661,8 +661,8 @@ int FileUtils::openFile(QString &path, bool openInDir)
} }
} }
GError *error = NULL; GError *error = nullptr;
GAppInfo *info = NULL; GAppInfo *info = nullptr;
/* /*
* g_app_info_get_default_for_type function get wrong default app, so we get the * 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 * 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); g_error_free(error);
} else { } else {
gchar *desktopApp = g_key_file_get_string(keyfile, "Default Applications", mimeType.toUtf8(), &error); 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); info = (GAppInfo*)g_desktop_app_info_new(desktopApp);
g_free (desktopApp); g_free (desktopApp);
} else { } else {
@ -685,31 +685,32 @@ int FileUtils::openFile(QString &path, bool openInDir)
} }
} }
g_key_file_free (keyfile); g_key_file_free (keyfile);
if(!G_IS_APP_INFO(info)) { if (!G_IS_APP_INFO(info)) {
res = -1; res = -1;
} else { } else {
bool isSuccess(false); bool isSuccess(false);
QDBusInterface * appLaunchInterface = new QDBusInterface("com.kylin.AppManager", QDBusInterface * appLaunchInterface = new QDBusInterface(QStringLiteral("com.kylin.ProcessManager"),
"/com/kylin/AppManager", QStringLiteral("/com/kylin/ProcessManager/AppLauncher"),
"com.kylin.AppManager", QStringLiteral("com.kylin.ProcessManager.AppLauncher"),
QDBusConnection::sessionBus()); QDBusConnection::sessionBus());
if(!appLaunchInterface->isValid()) { if (!appLaunchInterface->isValid()) {
qWarning() << qPrintable(QDBusConnection::sessionBus().lastError().message()); qWarning() << qPrintable(QDBusConnection::sessionBus().lastError().message());
isSuccess = false; isSuccess = false;
} else { } else {
appLaunchInterface->setTimeout(10000); appLaunchInterface->setTimeout(10000);
QDBusReply<bool> reply = appLaunchInterface->call("LaunchDefaultAppWithUrl", QUrl::fromLocalFile(path).toString()); QDBusReply<void> reply = appLaunchInterface->call("LaunchDefaultAppWithUrl", QUrl::fromLocalFile(path).toString());
if(reply.isValid()) { if(reply.isValid()) {
isSuccess = reply; isSuccess = true;
} else { } else {
qWarning() << "SoftWareCenter dbus called failed!"; qWarning() << "ProcessManager dbus called failed!" << reply.error();
isSuccess = false; isSuccess = false;
} }
} }
if(appLaunchInterface) { if (appLaunchInterface) {
delete appLaunchInterface; delete appLaunchInterface;
} }
appLaunchInterface = NULL; appLaunchInterface = nullptr;
if (!isSuccess){ if (!isSuccess){
QDesktopServices::openUrl(QUrl::fromLocalFile(path)); QDesktopServices::openUrl(QUrl::fromLocalFile(path));
} }

View File

@ -83,27 +83,27 @@ void NoteSearchPlugin::openAction(int actionkey, QString key, int type)
{ {
DataCollecter::collectLaunchEvent(QStringLiteral("Note Search"), QStringLiteral("open")); DataCollecter::collectLaunchEvent(QStringLiteral("Note Search"), QStringLiteral("open"));
bool res(false); bool res(false);
QDBusInterface * appLaunchInterface = new QDBusInterface("com.kylin.AppManager", QDBusInterface * appLaunchInterface = new QDBusInterface(QStringLiteral("com.kylin.ProcessManager"),
"/com/kylin/AppManager", QStringLiteral("/com/kylin/ProcessManager/AppLauncher"),
"com.kylin.AppManager", QStringLiteral("com.kylin.ProcessManager.AppLauncher"),
QDBusConnection::sessionBus()); QDBusConnection::sessionBus());
if(!appLaunchInterface->isValid()) { if(!appLaunchInterface->isValid()) {
qWarning() << qPrintable(QDBusConnection::sessionBus().lastError().message()); qWarning() << qPrintable(QDBusConnection::sessionBus().lastError().message());
res = false; res = false;
} else { } else {
appLaunchInterface->setTimeout(10000); appLaunchInterface->setTimeout(10000);
QDBusReply<bool> reply = appLaunchInterface->call("LaunchAppWithArguments", "ukui-notebook.desktop", QStringList() << "--show" << key); QDBusReply<void> reply = appLaunchInterface->call("LaunchAppWithArguments", "/usr/share/applications/ukui-notebook.desktop", QStringList() << "--show" << key);
if(reply.isValid()) { if(reply.isValid()) {
res = reply; res = true;
} else { } else {
qWarning() << "SoftWareCenter dbus called failed!"; qWarning() << "ProcessManager dbus called failed!" << reply.error();
res = false; res = false;
} }
} }
if(appLaunchInterface) { if(appLaunchInterface) {
delete appLaunchInterface; delete appLaunchInterface;
} }
appLaunchInterface = NULL; appLaunchInterface = nullptr;
if (res) if (res)
break; break;
QProcess process; QProcess process;

View File

@ -71,27 +71,27 @@ void SettingsSearchPlugin::openAction(int actionkey, QString key, int type)
{ {
DataCollecter::collectLaunchEvent(QStringLiteral("Settings Search"), QStringLiteral("open")); DataCollecter::collectLaunchEvent(QStringLiteral("Settings Search"), QStringLiteral("open"));
bool res(false); bool res(false);
QDBusInterface * appLaunchInterface = new QDBusInterface("com.kylin.AppManager", QDBusInterface * appLaunchInterface = new QDBusInterface(QStringLiteral("com.kylin.ProcessManager"),
"/com/kylin/AppManager", QStringLiteral("/com/kylin/ProcessManager/AppLauncher"),
"com.kylin.AppManager", QStringLiteral("com.kylin.ProcessManager.AppLauncher"),
QDBusConnection::sessionBus()); QDBusConnection::sessionBus());
if(!appLaunchInterface->isValid()) { if(!appLaunchInterface->isValid()) {
qWarning() << qPrintable(QDBusConnection::sessionBus().lastError().message()); qWarning() << qPrintable(QDBusConnection::sessionBus().lastError().message());
res = false; res = false;
} else { } else {
appLaunchInterface->setTimeout(10000); appLaunchInterface->setTimeout(10000);
QDBusReply<bool> reply = appLaunchInterface->call("LaunchAppWithArguments", "ukui-control-center.desktop", QStringList() << "-m" << key.toLower()); QDBusReply<void> reply = appLaunchInterface->call("LaunchAppWithArguments", "/usr/share/applications/ukui-control-center.desktop", QStringList() << "-m" << key.toLower());
if(reply.isValid()) { if(reply.isValid()) {
res = reply; res = true;
} else { } else {
qWarning() << "SoftWareCenter dbus called failed!"; qWarning() << "ProcessManager dbus called failed!" << reply.error();
res = false; res = false;
} }
} }
if(appLaunchInterface) { if (appLaunchInterface) {
delete appLaunchInterface; delete appLaunchInterface;
} }
appLaunchInterface = NULL; appLaunchInterface = nullptr;
if (res) if (res)
break; break;
//打开控制面板对应页面 //打开控制面板对应页面

View File

@ -97,27 +97,27 @@ void UkuiSearch::WebSearchPlugin::openAction(int actionkey, QString key, int typ
address = "http://baidu.com/s?word=" + m_keyWord ; //百度 address = "http://baidu.com/s?word=" + m_keyWord ; //百度
} }
bool res(false); bool res(false);
QDBusInterface * appLaunchInterface = new QDBusInterface("com.kylin.AppManager", QDBusInterface * appLaunchInterface = new QDBusInterface(QStringLiteral("com.kylin.ProcessManager"),
"/com/kylin/AppManager", QStringLiteral("/com/kylin/ProcessManager/AppLauncher"),
"com.kylin.AppManager", QStringLiteral("com.kylin.ProcessManager.AppLauncher"),
QDBusConnection::sessionBus()); QDBusConnection::sessionBus());
if(!appLaunchInterface->isValid()) { if(!appLaunchInterface->isValid()) {
qWarning() << qPrintable(QDBusConnection::sessionBus().lastError().message()); qWarning() << qPrintable(QDBusConnection::sessionBus().lastError().message());
res = false; res = false;
} else { } else {
appLaunchInterface->setTimeout(10000); appLaunchInterface->setTimeout(10000);
QDBusReply<bool> reply = appLaunchInterface->call("LaunchDefaultAppWithUrl", address); QDBusReply<void> reply = appLaunchInterface->call("LaunchDefaultAppWithUrl", address);
if(reply.isValid()) { if(reply.isValid()) {
res = reply; res = true;
} else { } else {
qWarning() << "SoftWareCenter dbus called failed!"; qWarning() << "ProcessManager dbus called failed!" << reply.error();
res = false; res = false;
} }
} }
if(appLaunchInterface) { if (appLaunchInterface) {
delete appLaunchInterface; delete appLaunchInterface;
} }
appLaunchInterface = NULL; appLaunchInterface = nullptr;
if (res) if (res)
return; return;
QDesktopServices::openUrl(address); QDesktopServices::openUrl(address);