diff --git a/src/extension/favorite/app-favorite-model.cpp b/src/extension/favorite/app-favorite-model.cpp index aaea8371fc0746c65d67ad025fa8429a91281c44..1df03b2b8e11caf65639b1cd2081af0065a174e3 100644 --- a/src/extension/favorite/app-favorite-model.cpp +++ b/src/extension/favorite/app-favorite-model.cpp @@ -129,9 +129,12 @@ void AppFavoritesModel::updateFavoritesApps(const DataEntity &app, const QModelI if (app.id().isEmpty()) { return; } + QPersistentModelIndex index(sourceIndex); if (app.favorite() > 0 && !FavoriteFolderHelper::instance()->containApp(app.id())) { - QPersistentModelIndex index(sourceIndex); + if (m_favoritesApps.contains(index)) { + return; + } addFavoriteApp(index); FavoritesConfig::instance().insertValue(APP_ID_SCHEME + index.data(DataEntity::Id).toString()); @@ -139,8 +142,6 @@ void AppFavoritesModel::updateFavoritesApps(const DataEntity &app, const QModelI if (FavoriteFolderHelper::instance()->containApp(app.id())) { FavoriteFolderHelper::instance()->removeAppFromFolder(app.id()); } - - QPersistentModelIndex index(sourceIndex); removeFavoriteApp(index); } } @@ -218,9 +219,15 @@ void AppFavoritesModel::clearFavorites() FavoritesConfig::instance().clear(); } -bool AppFavoritesModel::getApp(const QString &appid, DataEntity &app) +bool AppFavoritesModel::isAppIncluded(const QString &appid) { - return m_sourceModel->databaseInterface()->getApp(appid, app); + QModelIndex sourceIndex = m_sourceModel->index(m_sourceModel->indexOfApp(appid), 0, {}); + if (!sourceIndex.isValid()) { + return false; + } + + QPersistentModelIndex index(sourceIndex); + return m_favoritesApps.contains(index); } void AppFavoritesModel::onAppRemoved(const QModelIndex &parent, int first, int last) @@ -365,6 +372,8 @@ void AppFavoritesModel::addAppToFavorites(const QString &id, const int &index) if (id.isEmpty()) { return; } + QPersistentModelIndex modelIndex(m_sourceModel->index(m_sourceModel->indexOfApp(id))); + addFavoriteApp(modelIndex); m_sourceModel->databaseInterface()->fixAppToFavorite(id, 1); diff --git a/src/extension/favorite/app-favorite-model.h b/src/extension/favorite/app-favorite-model.h index f5be78093100a27b74007e9612b6156fb9b9c5a9..a9ab31e0e7287ffb2cdafd2ce6849f9b1e083c5a 100644 --- a/src/extension/favorite/app-favorite-model.h +++ b/src/extension/favorite/app-favorite-model.h @@ -42,7 +42,7 @@ public: void addAppToFavorites(const QString &id, const int &index); void removeAppFromFavorites(const QString &id); void changeFileState(const QString &url, const bool &favorite); - bool getApp(const QString &appid, DataEntity &app); + bool isAppIncluded(const QString &appid); private: explicit AppFavoritesModel(QObject *parent = nullptr); diff --git a/src/extension/favorite/favorites-config.cpp b/src/extension/favorite/favorites-config.cpp index 0403a9441d4a9290308d3847594337560b8f5d8e..9e419cad102e218e84d4843381a5f4562db03420 100644 --- a/src/extension/favorite/favorites-config.cpp +++ b/src/extension/favorite/favorites-config.cpp @@ -22,6 +22,7 @@ #include #include #include "favorites-config.h" +#include "favorite-folder-helper.h" #define FOLDER_FILE_PATH ".config/ukui-menu/" #define FOLDER_FILE_NAME "favorite.json" @@ -138,19 +139,24 @@ void FavoritesConfig::initConfig() m_favoritesList.clear(); QJsonArray array = jsonDocument.array(); - QJsonArray newArray; + bool needSync = false; for (int i = 0; i < array.size(); i++) { if (array.at(i).isString()) { - m_favoritesList.append(array.at(i).toString()); - newArray.append(array.at(i)); + QString id = array.at(i).toString(); + // 配置文件出现错误, 某一个应用 同时出现在了 应用组的内部和外部 + if (id.startsWith(APP_ID_SCHEME) && FavoriteFolderHelper::instance()->containApp(id.mid(APP_ID_SCHEME.length()))) { + needSync = true; + continue; + } + m_favoritesList.append(id); + } else { + needSync = true; } } - file.open(QFile::WriteOnly); - jsonDocument.setArray(newArray); - file.write(jsonDocument.toJson()); - file.flush(); - file.close(); + if (needSync) { + sync(); + } } } // UkuiMenu diff --git a/src/extension/favorite/favorites-model.cpp b/src/extension/favorite/favorites-model.cpp index 5cba3984066514b4ab42a363fa86cb4939e0be87..cf890a4a126d84f4ec9d5fcaec6c4feb740da0ab 100644 --- a/src/extension/favorite/favorites-model.cpp +++ b/src/extension/favorite/favorites-model.cpp @@ -80,6 +80,11 @@ void FavoritesModel::openMenu(const int &row) void FavoritesModel::addAppToFavorites(const QString &id, const int &index) { + if (AppFavoritesModel::instance().isAppIncluded(id) || FavoriteFolderHelper::instance()->containApp(id)) { + qWarning() << "This application is already included in the favorite apps!"; + return; + } + int appOrder; if (index == -1) { appOrder = FavoritesConfig::instance().configSize(); @@ -108,8 +113,7 @@ void FavoritesModel::addAppsToNewFolder(const QString &idFrom, const QString &id return; } - DataEntity app; - if (AppFavoritesModel::instance().getApp(idFrom, app) && AppFavoritesModel::instance().getApp(idTo, app)) { + if (AppFavoritesModel::instance().isAppIncluded(idFrom) && AppFavoritesModel::instance().isAppIncluded(idTo)) { FavoriteFolderHelper::instance()->addAppsToNewFolder(idFrom, idTo, ""); } } diff --git a/src/libappdata/app-search-plugin.cpp b/src/libappdata/app-search-plugin.cpp index 5df6f84d8816ca18c01c0af24d8f0f814927d059..bd059910676d3ecaf5df6f03e02c485bce856e06 100644 --- a/src/libappdata/app-search-plugin.cpp +++ b/src/libappdata/app-search-plugin.cpp @@ -19,6 +19,7 @@ */ #include "app-search-plugin.h" #include "data-entity.h" +#include "basic-app-model.h" #include #include @@ -60,9 +61,7 @@ AppSearchPluginPrivate::AppSearchPluginPrivate(QObject *parent) : QThread(parent m_appSearchTask->setSearchOnlineApps(false); UkuiSearch::SearchResultProperties searchResultProperties; - searchResultProperties << UkuiSearch::SearchProperty::SearchResultProperty::ApplicationDesktopPath - << UkuiSearch::SearchProperty::SearchResultProperty::ApplicationLocalName - << UkuiSearch::SearchProperty::SearchResultProperty::ApplicationIconName; + searchResultProperties << UkuiSearch::SearchProperty::SearchResultProperty::ApplicationDesktopPath; m_appSearchTask->setResultProperties(UkuiSearch::SearchProperty::SearchType::Application, searchResultProperties); m_timer = new QTimer; @@ -101,11 +100,10 @@ void AppSearchPluginPrivate::run() m_timer->stop(); if (result.getSearchId() == m_searchId) { DataEntity app; - app.setType(DataType::Normal); - app.setId(result.getValue(UkuiSearch::SearchProperty::ApplicationDesktopPath).toString()); - app.setName(result.getValue(UkuiSearch::SearchProperty::ApplicationLocalName).toString()); - app.setIcon(result.getValue(UkuiSearch::SearchProperty::ApplicationIconName).toString()); - + QString id = result.getValue(UkuiSearch::SearchProperty::ApplicationDesktopPath).toString(); + if (!BasicAppModel::instance()->getAppById(id, app)) { + BasicAppModel::instance()->databaseInterface()->getApp(id, app); + }; Q_EMIT this->searchedOne(app); } } diff --git a/src/utils/app-manager.cpp b/src/utils/app-manager.cpp index 8d52a0e1e840dede069e798db1b7551d7a01c2bc..9df1d2976bba01ecc2452968362912b28f1c7ff4 100644 --- a/src/utils/app-manager.cpp +++ b/src/utils/app-manager.cpp @@ -88,6 +88,12 @@ void AppManager::launchBinaryApp(const QString &app, const QString &args) void AppManager::launchAppWithArguments(const QString &appid, const QStringList &args, const QString &applicationName) { + if (appid.isEmpty()) { + return; + } + + Q_EMIT request(UkuiMenuApplication::Hide); + QDBusMessage message = QDBusMessage::createMethodCall(KYLIN_APP_MANAGER_NAME, KYLIN_APP_MANAGER_PATH, KYLIN_APP_MANAGER_INTERFACE,