mirror of
https://gitee.com/spark-store-project/spark-store
synced 2026-04-29 19:00:16 +08:00
fix(update): 统一忽略更新配置到用户目录
This commit is contained in:
@@ -324,7 +324,8 @@ bool AppDelegate::editorEvent(QEvent *event, QAbstractItemModel *model,
|
||||
QRect unignoreButtonRect(option.rect.right() - 80, option.rect.top() + (option.rect.height() - 30) / 2, 70, 30);
|
||||
if (unignoreButtonRect.contains(mouseEvent->pos())) {
|
||||
// 发送取消忽略信号
|
||||
emit unignoreApp(packageName);
|
||||
QString newVersion = index.data(Qt::UserRole + 3).toString();
|
||||
emit unignoreApp(packageName, newVersion);
|
||||
return true;
|
||||
}
|
||||
return true; // 消耗其他事件,不允许其他交互
|
||||
@@ -369,8 +370,8 @@ bool AppDelegate::editorEvent(QEvent *event, QAbstractItemModel *model,
|
||||
// 检查是否点击了忽略按钮
|
||||
QRect ignoreButtonRect(rect.right() - 160, rect.top() + (rect.height() - 30) / 2, 70, 30);
|
||||
if (ignoreButtonRect.contains(mouseEvent->pos())) {
|
||||
QString currentVersion = index.data(Qt::UserRole + 2).toString();
|
||||
emit ignoreApp(packageName, currentVersion);
|
||||
QString newVersion = index.data(Qt::UserRole + 3).toString();
|
||||
emit ignoreApp(packageName, newVersion);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1026,4 +1027,4 @@ void AppDelegate::clearSelection() {
|
||||
// 实现获取下载状态信息的方法
|
||||
const QHash<QString, DownloadInfo>& AppDelegate::getDownloads() const {
|
||||
return m_downloads;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ signals:
|
||||
void updateDisplay(const QString &packageName);
|
||||
void updateFinished(bool success); //传递是否完成更新
|
||||
void ignoreApp(const QString &packageName, const QString &version); // 新增:忽略应用信号
|
||||
void unignoreApp(const QString &packageName); // 新增:取消忽略应用信号
|
||||
void unignoreApp(const QString &packageName, const QString &version); // 新增:取消忽略应用信号
|
||||
|
||||
private slots:
|
||||
void updateSpinner(); // 新增槽函数
|
||||
@@ -72,4 +72,4 @@ private:
|
||||
|
||||
void enqueueInstall(const QString &packageName);
|
||||
void startNextInstall();
|
||||
};
|
||||
};
|
||||
|
||||
@@ -4,40 +4,19 @@
|
||||
#include <QFile>
|
||||
#include <QTextStream>
|
||||
#include <QDebug>
|
||||
#include <unistd.h> // for geteuid
|
||||
|
||||
IgnoreConfig::IgnoreConfig(QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
// 设置配置文件路径
|
||||
QString configDir;
|
||||
|
||||
// // 检查是否以 root 权限运行
|
||||
// if (geteuid() == 0) {
|
||||
// // 首先检查是否有 SUDO_USER_HOME 环境变量(表示是通过 pkexec 提权的普通用户)
|
||||
// QByteArray sudoUserHomeEnv = qgetenv("SUDO_USER_HOME");
|
||||
// if (!sudoUserHomeEnv.isEmpty()) {
|
||||
// // 通过 pkexec 提权的普通用户,使用原用户的配置目录
|
||||
// QString sudoUserHomePath = QString::fromLocal8Bit(sudoUserHomeEnv);
|
||||
// configDir = sudoUserHomePath + "/.config";
|
||||
// } else {
|
||||
// // 获取实际的 HOME 目录来判断是真正的 root 用户还是其他方式提权的用户
|
||||
// QByteArray homeEnv = qgetenv("HOME");
|
||||
// QString homePath = QString::fromLocal8Bit(homeEnv);
|
||||
|
||||
// if (homePath == "/root") {
|
||||
// // 真正的 root 用户,使用 /root/.config
|
||||
// configDir = "/root/.config";
|
||||
// } else {
|
||||
// // 其他方式提权的用户,使用 HOME 目录下的配置
|
||||
// configDir = homePath + "/.config";
|
||||
// }
|
||||
// }
|
||||
// } else {
|
||||
// // 普通用户,使用标准配置目录
|
||||
// configDir = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation);
|
||||
// }
|
||||
configDir = "/etc/";
|
||||
QByteArray sudoUserHomeEnv = qgetenv("SUDO_USER_HOME");
|
||||
|
||||
if (!sudoUserHomeEnv.isEmpty()) {
|
||||
configDir = QString::fromLocal8Bit(sudoUserHomeEnv) + "/.config";
|
||||
} else {
|
||||
configDir = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation);
|
||||
}
|
||||
|
||||
QDir dir(configDir);
|
||||
if (!dir.exists()) {
|
||||
dir.mkpath(".");
|
||||
@@ -64,17 +43,9 @@ void IgnoreConfig::addIgnoredApp(const QString &packageName, const QString &vers
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
void IgnoreConfig::removeIgnoredApp(const QString &packageName)
|
||||
void IgnoreConfig::removeIgnoredApp(const QString &packageName, const QString &version)
|
||||
{
|
||||
// 移除所有该包名的版本
|
||||
auto it = m_ignoredApps.begin();
|
||||
while (it != m_ignoredApps.end()) {
|
||||
if (it->first == packageName) {
|
||||
it = m_ignoredApps.erase(it);
|
||||
} else {
|
||||
++it;
|
||||
}
|
||||
}
|
||||
m_ignoredApps.remove(qMakePair(packageName, version));
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
@@ -145,4 +116,4 @@ bool IgnoreConfig::loadConfig()
|
||||
}
|
||||
file.close();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ public:
|
||||
void addIgnoredApp(const QString &packageName, const QString &version);
|
||||
|
||||
// 移除忽略的应用
|
||||
void removeIgnoredApp(const QString &packageName);
|
||||
void removeIgnoredApp(const QString &packageName, const QString &version);
|
||||
|
||||
// 检查应用是否被忽略
|
||||
bool isAppIgnored(const QString &packageName, const QString &version) const;
|
||||
@@ -39,4 +39,4 @@ private:
|
||||
QString m_configFilePath;
|
||||
};
|
||||
|
||||
#endif // IGNORECONFIG_H
|
||||
#endif // IGNORECONFIG_H
|
||||
|
||||
@@ -238,10 +238,10 @@ void MainWindow::checkUpdates()
|
||||
for (const auto &item : updateInfo) {
|
||||
QJsonObject obj = item.toObject();
|
||||
QString packageName = obj["package"].toString();
|
||||
QString currentVersion = obj["current_version"].toString();
|
||||
QString newVersion = obj["new_version"].toString();
|
||||
|
||||
// 检查应用是否被忽略
|
||||
if (m_ignoreConfig->isAppIgnored(packageName, currentVersion)) {
|
||||
if (m_ignoreConfig->isAppIgnored(packageName, newVersion)) {
|
||||
// 标记为忽略状态
|
||||
obj["ignored"] = true;
|
||||
ignoredApps.append(obj);
|
||||
@@ -468,9 +468,9 @@ void MainWindow::onIgnoreApp(const QString &packageName, const QString &version)
|
||||
}
|
||||
|
||||
// 新增:处理取消忽略应用的槽函数
|
||||
void MainWindow::onUnignoreApp(const QString &packageName) {
|
||||
void MainWindow::onUnignoreApp(const QString &packageName, const QString &version) {
|
||||
// 从忽略配置中移除应用
|
||||
m_ignoreConfig->removeIgnoredApp(packageName);
|
||||
m_ignoreConfig->removeIgnoredApp(packageName, version);
|
||||
|
||||
// 更新模型中应用的状态
|
||||
QJsonArray updatedApps;
|
||||
@@ -485,4 +485,4 @@ void MainWindow::onUnignoreApp(const QString &packageName) {
|
||||
|
||||
// 重新排序:正常应用在前,忽略应用在后
|
||||
checkUpdates();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,6 +43,6 @@ private slots:
|
||||
void handleUpdateFinished(bool success); // 新增:处理更新完成的槽函数
|
||||
void handleSelectionChanged(); // 新增:处理选择变化的槽函数
|
||||
void onIgnoreApp(const QString &packageName, const QString &version); // 新增:处理忽略应用的槽函数
|
||||
void onUnignoreApp(const QString &packageName); // 新增:处理取消忽略应用
|
||||
void onUnignoreApp(const QString &packageName, const QString &version); // 新增:处理取消忽略应用
|
||||
};
|
||||
#endif // MAINWINDOW_H
|
||||
#endif // MAINWINDOW_H
|
||||
|
||||
Reference in New Issue
Block a user