mirror of
https://gitee.com/spark-store-project/spark-store
synced 2025-12-14 21:02: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:
136
src/main.cpp
136
src/main.cpp
@@ -1,13 +1,11 @@
|
||||
#include "application.h"
|
||||
#include "mainwindow-dtk.h"
|
||||
|
||||
#include <DApplication>
|
||||
#include <DLog>
|
||||
#include <DPlatformWindowHandle>
|
||||
#include <DApplicationSettings>
|
||||
#include <DAboutDialog>
|
||||
#include <QLabel>
|
||||
#include <DWidgetUtil>
|
||||
#include <DSysInfo>
|
||||
#include <DApplicationSettings>
|
||||
#include <DWidgetUtil>
|
||||
|
||||
#include <QStandardPaths>
|
||||
|
||||
DCORE_USE_NAMESPACE
|
||||
DWIDGET_USE_NAMESPACE
|
||||
@@ -18,35 +16,36 @@ int main(int argc, char *argv[])
|
||||
static const QString version = "Version 4.1.2";
|
||||
static const QDate buildDate = QLocale(QLocale::English).toDate(QString(__DATE__).replace(" ", " 0"), "MMM dd yyyy");
|
||||
static const QTime buildTime = QTime::fromString(__TIME__, "hh:mm:ss");
|
||||
QSettings readConfig(QDir::homePath() + "/.config/spark-store/config.ini", QSettings::IniFormat);
|
||||
QSettings *setConfig = new QSettings(QDir::homePath() + "/.config/spark-store/config.ini", QSettings::IniFormat);
|
||||
static const QString buildDateTime = buildDate.toString("yyyy.MM.dd") + "-" + buildTime.toString("hh:mm:ss");
|
||||
|
||||
// 设置桌面环境环境变量
|
||||
bool isDeepinOS = true;
|
||||
if (!QString(qgetenv("XDG_CURRENT_DESKTOP")).toLower().startsWith("deepin"))
|
||||
{
|
||||
setenv("XDG_CURRENT_DESKTOP", "Deepin", 1);
|
||||
qputenv("XDG_CURRENT_DESKTOP", "Deepin");
|
||||
isDeepinOS = false;
|
||||
}
|
||||
|
||||
bool isWayland = false;
|
||||
auto e = QProcessEnvironment::systemEnvironment();
|
||||
QString XDG_SESSION_TYPE = e.value(QStringLiteral("XDG_SESSION_TYPE"));
|
||||
QString WAYLAND_DISPLAY = e.value(QStringLiteral("WAYLAND_DISPLAY"));
|
||||
|
||||
if (XDG_SESSION_TYPE == QLatin1String("wayland") || WAYLAND_DISPLAY.contains(QLatin1String("wayland"), Qt::CaseInsensitive))
|
||||
{
|
||||
isWayland = true;
|
||||
}
|
||||
setConfig->setValue("build/isWayland", isWayland);
|
||||
setConfig->setValue("build/isDeepinOS", isDeepinOS);
|
||||
|
||||
QSettings config(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + "/config.ini", QSettings::IniFormat);
|
||||
config.setValue("build/isWayland", isWayland);
|
||||
config.setValue("build/isDeepinOS", isDeepinOS);
|
||||
|
||||
// Check config file, if there is no wayland config, then set it to default, which means use wayland if possible.
|
||||
if (!readConfig.contains("build/useWayland"))
|
||||
if (!config.contains("build/useWayland"))
|
||||
{
|
||||
setConfig->setValue("build/useWayland", true);
|
||||
config.setValue("build/useWayland", true);
|
||||
}
|
||||
|
||||
bool useWayland = readConfig.value("build/useWayland").toBool();
|
||||
bool useWayland = config.value("build/useWayland").toBool();
|
||||
qDebug() << "System Wayland enabled:" << isWayland << ". Spark Wayland enabled:" << useWayland;
|
||||
|
||||
// Set display backend
|
||||
@@ -62,104 +61,55 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
qputenv("QT_QPA_PLATFORM", "dxcb");
|
||||
}
|
||||
|
||||
// 龙芯机器配置,使得 DApplication 能正确加载 QTWEBENGINE
|
||||
qputenv("DTK_FORCE_RASTER_WIDGETS", "FALSE");
|
||||
// qputenv("QTWEBENGINE_CHROMIUM_FLAGS", "--disable-features=UseModernMediaControls");
|
||||
// qputenv("QTWEBENGINE_CHROMIUM_FLAGS", "--disable-web-security");
|
||||
// 浏览器开启 GPU 支持
|
||||
#ifdef __sw_64__
|
||||
qputenv("QTWEBENGINE_CHROMIUM_FLAGS", "--ignore-gpu-blocklist --enable-gpu-rasterization --enable-native-gpu-memory-buffers --enable-accelerated-video-decode --no-sandbox");
|
||||
#else
|
||||
qputenv("QTWEBENGINE_CHROMIUM_FLAGS", "--ignore-gpu-blocklist --enable-gpu-rasterization --enable-native-gpu-memory-buffers --enable-accelerated-video-decode");
|
||||
#endif
|
||||
|
||||
DApplication::setAttribute(Qt::AA_EnableHighDpiScaling); // 开启 Hidpi 支持
|
||||
|
||||
// 浏览器开启 GPU 支持
|
||||
qputenv("QTWEBENGINE_CHROMIUM_FLAGS", "--ignore-gpu-blocklist --enable-gpu-rasterization --enable-native-gpu-memory-buffers --enable-accelerated-video-decode");
|
||||
|
||||
// 强制使用 DTK 平台插件
|
||||
QVector<char *> fakeArgs(argc + 2);
|
||||
fakeArgs[0] = argv[0];
|
||||
QString fakeArgs1 = "-platformtheme";
|
||||
QByteArray fakeArgsTemp = fakeArgs1.toLatin1(); // must
|
||||
fakeArgs[1] = fakeArgsTemp.data();
|
||||
fakeArgs1 = "deepin";
|
||||
fakeArgsTemp = fakeArgs1.toLatin1(); // must
|
||||
fakeArgs[2] = fakeArgsTemp.data();
|
||||
|
||||
fakeArgs[1] = const_cast<char *>("-platformtheme");
|
||||
fakeArgs[2] = const_cast<char *>("deepin");
|
||||
for (int i = 1; i < argc; i++)
|
||||
{
|
||||
fakeArgs[i + 2] = argv[i];
|
||||
int fakeArgc = argc + 2; // DApplication的argc要用引用,避免c++编译器优化
|
||||
DApplication a(fakeArgc, fakeArgs.data());
|
||||
|
||||
// 初始化日志模块 (默认日志位置 ~/.cache/deepin/spark-store)
|
||||
DLogManager::registerConsoleAppender();
|
||||
DLogManager::registerFileAppender();
|
||||
|
||||
// Wayland 环境下使用,防止子控件 Native 化
|
||||
if (!DPlatformWindowHandle::pluginVersion().isEmpty())
|
||||
{
|
||||
a.setAttribute(Qt::AA_DontCreateNativeWidgetSiblings, true);
|
||||
}
|
||||
a.setAttribute(Qt::AA_UseHighDpiPixmaps);
|
||||
a.setApplicationDisplayName("Spark Store");
|
||||
int fakeArgc = argc + 2; // QCoreApplication 的 argc 要用引用,避免 c++ 编译器优化
|
||||
Application a(fakeArgc, fakeArgs.data());
|
||||
// 设置版本和构建时间
|
||||
a.setVersionAndBuildDateTime(version, buildDateTime);
|
||||
|
||||
a.loadTranslator(); // 载入翻译
|
||||
|
||||
if (readConfig.value("build/version").toString() != version)
|
||||
{
|
||||
qDebug() << "Spark Store has been updated!";
|
||||
setConfig->setValue("build/version", version);
|
||||
setConfig->setValue("build/time", buildDate.toString("yyyy.MM.dd") + "-" + buildTime.toString());
|
||||
}
|
||||
setConfig->deleteLater();
|
||||
|
||||
// Customized DAboutDialog
|
||||
|
||||
DAboutDialog dialog;
|
||||
a.setAboutDialog(&dialog);
|
||||
dialog.setLicense(QObject::tr("We publish this program under GPL V3"));
|
||||
dialog.setVersion(DApplication::buildVersion(readConfig.value("build/version").toString() + "-" + "Flamescion" + "-" + readConfig.value("build/time").toString()));
|
||||
dialog.setProductIcon(QIcon::fromTheme("spark-store")); // 设置Logo
|
||||
dialog.setProductName(QLabel::tr("Spark Store"));
|
||||
dialog.setDescription(
|
||||
QObject::tr(
|
||||
"<span style=' font-size:10pt;font-weight:60;'>An appstore powered by community</span><br/>"
|
||||
"<a href='https://www.spark-app.store/'>https://www.spark-app.store</a><br/>"
|
||||
"<span style=' font-size:12pt;'>Spark developers</span>"));
|
||||
|
||||
dialog.setProductName(QLabel::tr("Spark Store"));
|
||||
dialog.setCompanyLogo(QPixmap(":/spark-store.png"));
|
||||
dialog.setWebsiteName(QObject::tr("The Spark Project"));
|
||||
dialog.setWebsiteLink("https://gitee.com/deepin-community-store");
|
||||
|
||||
a.setOrganizationName("spark-union");
|
||||
a.setProductName(QObject::tr("Spark Store"));
|
||||
a.setApplicationName("Spark Store"); // 不用翻译,影响 ~/.local/share/spark-union 下文件夹名称
|
||||
a.setApplicationDisplayName(QObject::tr("Spark Store")); // 设置窗口显示标题 (Wayland 下会显示 Qt 原生标题栏)
|
||||
a.setWindowIcon(QIcon::fromTheme("spark-store"));
|
||||
a.setApplicationDescription(
|
||||
QObject::tr(
|
||||
"<span style='font-size:10pt;font-weight:60;'>An appstore powered by deepin community</span><br/>"
|
||||
"<a href='https://www.spark-app.store/'>https://www.spark-app.store</a><br/>"
|
||||
"<span style='font-size:12pt;'>Spark developers</span><br/><br/>"
|
||||
"Published under GPL V3"));
|
||||
// 限制单实例运行
|
||||
if (!a.setSingleInstance("spark-store"))
|
||||
{
|
||||
qDebug() << "The application is already running!";
|
||||
QDBusInterface iface("com.gitee.spark.store",
|
||||
"/com/gitee/spark/store",
|
||||
"com.gitee.spark.store",
|
||||
QDBusConnection::sessionBus());
|
||||
|
||||
QString arg1 = argv[1];
|
||||
|
||||
iface.asyncCall("activeWindow", arg1);
|
||||
|
||||
qWarning() << "Another instance has already started, activating...";
|
||||
return -1;
|
||||
}
|
||||
|
||||
DGuiApplicationHelper::instance()->setPaletteType(DGuiApplicationHelper::LightType); // 固定主题为浅色主题
|
||||
DApplicationSettings settings; // 定义 DApplicationSettings,自动保存主题设置
|
||||
DApplicationSettings settings; // 定义 DApplicationSettings,自动保存主题设置
|
||||
|
||||
MainWindow w;
|
||||
// 让打开时界面显示在正中
|
||||
Dtk::Widget::moveToCenter(&w);
|
||||
|
||||
QString arg1 = argv[1];
|
||||
if (arg1.startsWith("spk://"))
|
||||
if (argc > 1)
|
||||
{
|
||||
w.openUrl(QUrl(argv[1]));
|
||||
QString arg1 = argv[1];
|
||||
if (arg1.trimmed().startsWith("spk://"))
|
||||
{
|
||||
w.openUrl(QUrl(argv[1]));
|
||||
}
|
||||
}
|
||||
w.show();
|
||||
w.setWindowTitle("Spark Store");
|
||||
|
||||
Reference in New Issue
Block a user