mirror of
https://gitee.com/spark-store-project/spark-store
synced 2025-12-14 12:52:04 +08:00
!178 fix: 修复主窗口关闭后,关于窗口没有自动关闭的问题
* 添加 Application 类,继承 DApplication,将 main 函数中设置属性、关于信息等操作移至 Application 构造函数中进行 * 1.1. 添加 setOrganizationName 操作,设置组织名称为 spark-union,与 SWRT 保持一致 * 1.2. 设置组织名称后,QStandardPaths::AppConfigLocation 等路径相应改变,修改所有配置文件和缓存文件路径(server.list/config.ini 等) * 1.3. 关于对话框设置父对象后,对话框背景色受主窗口样式表影响,移动部分控件样式表设置方式与位置 * 修复关于窗口不显示组织 Logo 的问题,补充丢失的资源文件,整理资源文件 * 去除 .pro 文件中无效的更新翻译文件脚本调用,整理 .pro 文件,添加编译时更新 ts 文件脚本调用 * 继续修复偶现关闭客户端时崩溃问题(疑似 aria2c 进程未启动,pid 未初始化为随机值,执行 kill 操作时未判断导致) * 修复进入详情页时焦点默认在分享链接按钮上的问题 * 暂时去除没有意义的 DBus 接口,使用 DGuiApplicationHelper::newProcessInstance 获取新进程的启动参数 * 更新翻译文件,去除已经不存在的翻译
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
#include "downloadworker.h"
|
||||
|
||||
#include <QEventLoop>
|
||||
#include <QProcess>
|
||||
#include <QRegularExpression>
|
||||
#include <QDir>
|
||||
#include <QtConcurrent>
|
||||
#include <QStandardPaths>
|
||||
|
||||
DownloadController::DownloadController(QObject *parent)
|
||||
{
|
||||
@@ -48,7 +50,7 @@ bool checkMeatlink(QString metaUrl)
|
||||
|
||||
void gennerateDomain(QVector<QString> &domains)
|
||||
{
|
||||
QFile serverList(QDir::homePath().toUtf8() + "/.config/spark-store/server.list");
|
||||
QFile serverList(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + "/server.list");
|
||||
if (serverList.open(QFile::ReadOnly))
|
||||
{
|
||||
QStringList list = QString(serverList.readAll()).trimmed().split("\n");
|
||||
@@ -87,14 +89,17 @@ void DownloadController::startDownload(const QString &url)
|
||||
}
|
||||
|
||||
QtConcurrent::run([=]()
|
||||
{
|
||||
{
|
||||
QString metaUrl = url + ".metalink";
|
||||
qDebug() << "metalink" << metaUrl;
|
||||
bool useMetalink = false;
|
||||
if (checkMeatlink(metaUrl)){
|
||||
if (checkMeatlink(metaUrl))
|
||||
{
|
||||
useMetalink = true;
|
||||
qDebug() << "useMetalink:" << useMetalink;
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
gennerateDomain(domains);
|
||||
// qDebug() << domains << domains.size();
|
||||
}
|
||||
@@ -111,10 +116,12 @@ void DownloadController::startDownload(const QString &url)
|
||||
QString aria2ConnectionMax = "--max-concurrent-downloads=16";
|
||||
QString aria2DNSCommand = "--async-dns-server=119.29.29.29,223.5.5.5";
|
||||
|
||||
if (useMetalink){
|
||||
if (useMetalink)
|
||||
{
|
||||
command.append(metaUrl.toUtf8());
|
||||
}
|
||||
else{
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < domains.size(); i++)
|
||||
{
|
||||
command.append(replaceDomain(url, domains.at(i)).replace("+","%2B").toUtf8()); //对+进行转译,避免oss出错
|
||||
@@ -133,7 +140,8 @@ void DownloadController::startDownload(const QString &url)
|
||||
command.append(aria2ConnectionPerServer.toUtf8());
|
||||
command.append(aria2ConnectionMax.toUtf8());
|
||||
command.append(aria2DNSCommand.toUtf8());
|
||||
if (useMetalink){
|
||||
if (useMetalink)
|
||||
{
|
||||
command.append(aria2NoSeeds.toUtf8());
|
||||
}
|
||||
qDebug() << command;
|
||||
@@ -144,8 +152,7 @@ void DownloadController::startDownload(const QString &url)
|
||||
cmd->start();
|
||||
cmd->waitForStarted(); //等待启动完成
|
||||
|
||||
QObject::connect(cmd, &QProcess::readyReadStandardOutput,
|
||||
[&]()
|
||||
QObject::connect(cmd, &QProcess::readyReadStandardOutput, [&]()
|
||||
{
|
||||
//通过读取输出计算下载速度
|
||||
QString message = cmd->readAllStandardOutput().data();
|
||||
@@ -188,8 +195,7 @@ void DownloadController::startDownload(const QString &url)
|
||||
emit downloadProcess(speedInfo, downloadSizeRecord, fileSize);
|
||||
}
|
||||
});
|
||||
QObject::connect(cmd, &QProcess::readyReadStandardError,
|
||||
[&]()
|
||||
QObject::connect(cmd, &QProcess::readyReadStandardError, [&]()
|
||||
{
|
||||
emit errorOccur(cmd->readAllStandardError().data());
|
||||
return;
|
||||
@@ -222,10 +228,16 @@ void DownloadController::startDownload(const QString &url)
|
||||
*/
|
||||
void DownloadController::stopDownload()
|
||||
{
|
||||
if (pidNumber < 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// 实现下载进程退出
|
||||
QString killCmd = QString("kill -9 %1").arg(pidNumber);
|
||||
system(killCmd.toUtf8());
|
||||
qDebug() << "kill aria2!";
|
||||
pidNumber = -1;
|
||||
}
|
||||
|
||||
qint64 DownloadController::getFileSize(const QString &url)
|
||||
|
||||
@@ -21,7 +21,7 @@ public:
|
||||
|
||||
private:
|
||||
int threadNum;
|
||||
int pidNumber;
|
||||
int pidNumber = -1;
|
||||
QString filename;
|
||||
qint64 fileSize;
|
||||
QVector<QPair<qint64, qint64>> ranges;
|
||||
|
||||
@@ -1,39 +1,45 @@
|
||||
#include "sparkapi.h"
|
||||
|
||||
#include <QSettings>
|
||||
#include <QStandardPaths>
|
||||
#include <QDebug>
|
||||
|
||||
QString SparkAPI::serverUrl = "";
|
||||
|
||||
SparkAPI::SparkAPI(QObject *parent) : QObject(parent)
|
||||
{
|
||||
QSettings readConfig(QDir::homePath() + "/.config/spark-store/config.ini", QSettings::IniFormat);
|
||||
if (!readConfig.value("server/choose").toString().isEmpty() && readConfig.value("server/updated").toString() == "TRUE")
|
||||
QSettings config(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + "/config.ini", QSettings::IniFormat);
|
||||
if (!config.value("server/choose").toString().isEmpty() && config.value("server/updated").toBool())
|
||||
{
|
||||
SparkAPI::setServerUrl(readConfig.value("server/choose").toString());
|
||||
SparkAPI::setServerUrl(config.value("server/choose").toString());
|
||||
}
|
||||
}
|
||||
|
||||
void SparkAPI::get(QUrl url)
|
||||
{
|
||||
QNetworkRequest request;
|
||||
HttpRequest *httprequest = new HttpRequest;
|
||||
request.setUrl(QUrl(url.toString().replace("+", "%2B")));
|
||||
connect(httprequest, &HttpRequest::finished, [=](QString data)
|
||||
{
|
||||
{
|
||||
QByteArray arr = data.toUtf8();
|
||||
//解析Json
|
||||
QJsonParseError error;
|
||||
if(QJsonDocument::fromJson(arr,&error).isArray())
|
||||
{
|
||||
auto doc = QJsonDocument::fromJson(arr,&error).array();
|
||||
emit finished(doc);
|
||||
}else {
|
||||
auto doc = QJsonDocument::fromJson(arr,&error).object();
|
||||
emit finishedObject(doc);
|
||||
}
|
||||
// 解析 Json
|
||||
QJsonParseError error;
|
||||
if(QJsonDocument::fromJson(arr,&error).isArray())
|
||||
{
|
||||
auto doc = QJsonDocument::fromJson(arr,&error).array();
|
||||
emit finished(doc);
|
||||
} else {
|
||||
auto doc = QJsonDocument::fromJson(arr,&error).object();
|
||||
emit finishedObject(doc);
|
||||
}
|
||||
|
||||
httprequest->deleteLater();
|
||||
});
|
||||
|
||||
httprequest->deleteLater(); });
|
||||
httprequest->getRequest(request);
|
||||
}
|
||||
|
||||
void SparkAPI::getRAW(QUrl url)
|
||||
{
|
||||
QNetworkRequest request;
|
||||
@@ -45,30 +51,37 @@ void SparkAPI::getRAW(QUrl url)
|
||||
httprequest->deleteLater(); });
|
||||
httprequest->getRequest(request);
|
||||
}
|
||||
|
||||
void SparkAPI::getAppList(QString type)
|
||||
{
|
||||
get(QUrl(getServerUrl() + "store/" + type + "/applist.json"));
|
||||
}
|
||||
|
||||
void SparkAPI::getSearchList(QString keyword)
|
||||
{
|
||||
get(QUrl("https://search.deepinos.org.cn/appinfo/search?keyword=" + keyword));
|
||||
}
|
||||
|
||||
void SparkAPI::getAppInfo(QUrl spk)
|
||||
{
|
||||
get(QUrl(getServerUrl() + "store" + spk.path().replace("+", "%2B") + "/app.json"));
|
||||
}
|
||||
|
||||
void SparkAPI::getAppDownloadTimes(QUrl spk)
|
||||
{
|
||||
getRAW(QUrl(getServerUrl() + "store" + spk.path().replace("+", "%2B") + "/download-times.txt"));
|
||||
}
|
||||
|
||||
QString SparkAPI::getServerUrl()
|
||||
{
|
||||
return SparkAPI::serverUrl;
|
||||
}
|
||||
|
||||
QString SparkAPI::getImgServerUrl()
|
||||
{
|
||||
return SparkAPI::serverUrl;
|
||||
}
|
||||
|
||||
void SparkAPI::setServerUrl(QString url)
|
||||
{
|
||||
SparkAPI::serverUrl = url;
|
||||
|
||||
@@ -1,16 +1,21 @@
|
||||
#ifndef SPARKAPI_H
|
||||
#define SPARKAPI_H
|
||||
|
||||
#include "utils/httprequest.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonArray>
|
||||
#include <QJsonParseError>
|
||||
#include "utils/httprequest.h"
|
||||
#include <QSettings>
|
||||
#include <QDir>
|
||||
|
||||
class SparkAPI : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit SparkAPI(QObject *parent = nullptr);
|
||||
|
||||
static QString getServerUrl();
|
||||
static QString getImgServerUrl();
|
||||
static void setServerUrl(QString url);
|
||||
@@ -20,17 +25,14 @@ public:
|
||||
void getRAW(QUrl url);
|
||||
void getAppList(QString type);
|
||||
void getAppInfo(QUrl spk);
|
||||
explicit SparkAPI(QObject *parent = nullptr);
|
||||
|
||||
private:
|
||||
static QString serverUrl;
|
||||
|
||||
signals:
|
||||
void finished(QJsonArray);
|
||||
void finishedRAW(QString);
|
||||
void finishedObject(QJsonObject);
|
||||
|
||||
public slots:
|
||||
private:
|
||||
static QString serverUrl;
|
||||
};
|
||||
|
||||
#endif // SPARKAPI_H
|
||||
|
||||
Reference in New Issue
Block a user