aboutsummaryrefslogtreecommitdiff
path: root/launcher/Application.cpp
diff options
context:
space:
mode:
authorTrial97 <alexandru.tripon97@gmail.com>2023-05-31 20:12:12 +0300
committerTrial97 <alexandru.tripon97@gmail.com>2023-05-31 20:12:12 +0300
commit29c3dc40ef7f5b1fce5ab5970a39613d0f7f5089 (patch)
treece92f8a86d08531879105a16194a14391c0ae2ea /launcher/Application.cpp
parente8ee4497f77a571b305a48b70f84c8729b800859 (diff)
parent954d4d701a136e79c25b58f9680d26a555a6e6fe (diff)
downloadPrismLauncher-29c3dc40ef7f5b1fce5ab5970a39613d0f7f5089.tar.gz
PrismLauncher-29c3dc40ef7f5b1fce5ab5970a39613d0f7f5089.tar.bz2
PrismLauncher-29c3dc40ef7f5b1fce5ab5970a39613d0f7f5089.zip
Merge branch 'develop' of https://github.com/PrismLauncher/PrismLauncher into logdir
Diffstat (limited to 'launcher/Application.cpp')
-rw-r--r--launcher/Application.cpp218
1 files changed, 131 insertions, 87 deletions
diff --git a/launcher/Application.cpp b/launcher/Application.cpp
index f68e8792..430a96af 100644
--- a/launcher/Application.cpp
+++ b/launcher/Application.cpp
@@ -7,6 +7,8 @@
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
* Copyright (C) 2022 Lenny McLennington <lenny@sneed.church>
* Copyright (C) 2022 Tayou <tayou@gmx.net>
+ * Copyright (C) 2023 TheKodeToad <TheKodeToad@proton.me>
+ * Copyright (C) 2023 Rachel Powers <508861+Ryex@users.noreply.github.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -45,6 +47,7 @@
#include "net/PasteUpload.h"
#include "pathmatcher/MultiMatcher.h"
#include "pathmatcher/SimplePrefixMatcher.h"
+#include "settings/INIFile.h"
#include "ui/MainWindow.h"
#include "ui/InstanceWindow.h"
@@ -62,15 +65,11 @@
#include "ui/pages/global/APIPage.h"
#include "ui/pages/global/CustomCommandsPage.h"
-#ifdef Q_OS_WIN
-#include "ui/WinDarkmode.h"
-#include <versionhelpers.h>
-#endif
-
#include "ui/setupwizard/SetupWizard.h"
#include "ui/setupwizard/LanguageWizardPage.h"
#include "ui/setupwizard/JavaWizardPage.h"
#include "ui/setupwizard/PasteWizardPage.h"
+#include "ui/setupwizard/ThemeWizardPage.h"
#include "ui/dialogs/CustomMessageBox.h"
@@ -81,7 +80,9 @@
#include "ApplicationMessage.h"
#include <iostream>
+#include <mutex>
+#include <QFileOpenEvent>
#include <QAccessible>
#include <QCommandLineParser>
#include <QDir>
@@ -105,7 +106,7 @@
#include "java/JavaUtils.h"
-#include "updater/UpdateChecker.h"
+#include "updater/ExternalUpdater.h"
#include "tools/JProfiler.h"
#include "tools/JVisualVM.h"
@@ -129,6 +130,10 @@
#include "MangoHud.h"
#endif
+#ifdef Q_OS_MAC
+#include "updater/MacSparkleUpdater.h"
+#endif
+
#if defined Q_OS_WIN32
#ifndef WIN32_LEAN_AND_MEAN
@@ -150,6 +155,9 @@ namespace {
/** This is used so that we can output to the log file in addition to the CLI. */
void appDebugOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{
+ static std::mutex loggerMutex;
+ const std::lock_guard<std::mutex> lock(loggerMutex); // synchronized, QFile logFile is not thread-safe
+
QString out = qFormatLogMessage(type, context, msg);
out += QChar::LineFeed;
@@ -159,45 +167,6 @@ void appDebugOutput(QtMsgType type, const QMessageLogContext &context, const QSt
fflush(stderr);
}
-QString getIdealPlatform(QString currentPlatform) {
- auto info = Sys::getKernelInfo();
- switch(info.kernelType) {
- case Sys::KernelType::Darwin: {
- if(info.kernelMajor >= 17) {
- // macOS 10.13 or newer
- return "osx64-5.15.2";
- }
- else {
- // macOS 10.12 or older
- return "osx64";
- }
- }
- case Sys::KernelType::Windows: {
- // FIXME: 5.15.2 is not stable on Windows, due to a large number of completely unpredictable and hard to reproduce issues
- break;
-/*
- if(info.kernelMajor == 6 && info.kernelMinor >= 1) {
- // Windows 7
- return "win32-5.15.2";
- }
- else if (info.kernelMajor > 6) {
- // Above Windows 7
- return "win32-5.15.2";
- }
- else {
- // Below Windows 7
- return "win32";
- }
-*/
- }
- case Sys::KernelType::Undetermined:
- case Sys::KernelType::Linux: {
- break;
- }
- }
- return currentPlatform;
-}
-
}
Application::Application(int &argc, char **argv) : QApplication(argc, argv)
@@ -259,9 +228,19 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
m_serverToJoin = parser.value("server");
m_profileToUse = parser.value("profile");
m_liveCheck = parser.isSet("alive");
- m_zipToImport = parser.value("import");
+
m_instanceIdToShowWindowOf = parser.value("show");
+ for (auto zip_path : parser.values("import")){
+ m_zipsToImport.append(QUrl::fromLocalFile(QFileInfo(zip_path).absoluteFilePath()));
+ }
+
+ // treat unspecified positional arguments as import urls
+ for (auto zip_path : parser.positionalArguments()) {
+ m_zipsToImport.append(QUrl::fromLocalFile(QFileInfo(zip_path).absoluteFilePath()));
+ }
+
+
// error if --launch is missing with --server or --profile
if((!m_serverToJoin.isEmpty() || !m_profileToUse.isEmpty()) && m_instanceIdToLaunch.isEmpty())
{
@@ -309,6 +288,7 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
if (QFile::exists(FS::PathCombine(m_rootPath, "portable.txt"))) {
dataPath = m_rootPath;
adjustedBy = "Portable data path";
+ m_portable = true;
}
#endif
}
@@ -345,7 +325,7 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
}
/*
- * Establish the mechanism for communication with an already running PolyMC that uses the same data path.
+ * Establish the mechanism for communication with an already running PrismLauncher that uses the same data path.
* If there is one, tell it what the user actually wanted to do and exit.
* We want to initialize this before logging to avoid messing with the log of a potential already running copy.
*/
@@ -363,12 +343,14 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
activate.command = "activate";
m_peerInstance->sendMessage(activate.serialize(), timeout);
- if(!m_zipToImport.isEmpty())
+ if(!m_zipsToImport.isEmpty())
{
- ApplicationMessage import;
- import.command = "import";
- import.args.insert("path", m_zipToImport.toString());
- m_peerInstance->sendMessage(import.serialize(), timeout);
+ for (auto zip_url : m_zipsToImport) {
+ ApplicationMessage import;
+ import.command = "import";
+ import.args.insert("path", zip_url.toString());
+ m_peerInstance->sendMessage(import.serialize(), timeout);
+ }
}
}
else
@@ -435,6 +417,47 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
" " "|" " "
"%{if-category}[%{category}]: %{endif}"
"%{message}");
+
+ bool foundLoggingRules = false;
+
+ auto logRulesFile = QStringLiteral("qtlogging.ini");
+ auto logRulesPath = FS::PathCombine(dataPath, logRulesFile);
+
+ qDebug() << "Testing" << logRulesPath << "...";
+ foundLoggingRules = QFile::exists(logRulesPath);
+
+ // search the dataPath()
+ // seach app data standard path
+ if(!foundLoggingRules && !isPortable() && dirParam.isEmpty()) {
+ logRulesPath = QStandardPaths::locate(QStandardPaths::AppDataLocation, FS::PathCombine("..", logRulesFile));
+ if(!logRulesPath.isEmpty()) {
+ qDebug() << "Found" << logRulesPath << "...";
+ foundLoggingRules = true;
+ }
+ }
+ // seach root path
+ if(!foundLoggingRules) {
+ logRulesPath = FS::PathCombine(m_rootPath, logRulesFile);
+ qDebug() << "Testing" << logRulesPath << "...";
+ foundLoggingRules = QFile::exists(logRulesPath);
+ }
+
+ if(foundLoggingRules) {
+ // load and set logging rules
+ qDebug() << "Loading logging rules from:" << logRulesPath;
+ QSettings loggingRules(logRulesPath, QSettings::IniFormat);
+ loggingRules.beginGroup("Rules");
+ QStringList rule_names = loggingRules.childKeys();
+ QStringList rules;
+ qDebug() << "Setting log rules:";
+ for (auto rule_name : rule_names) {
+ auto rule = QString("%1=%2").arg(rule_name).arg(loggingRules.value(rule_name).toString());
+ rules.append(rule);
+ qDebug() << " " << rule;
+ }
+ auto rules_str = rules.join("\n");
+ QLoggingCategory::setFilterRules(rules_str);
+ }
qDebug() << "<> Log initialized.";
}
@@ -499,14 +522,10 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
{
// Provide a fallback for migration from PolyMC
m_settings.reset(new INISettingsObject({ BuildConfig.LAUNCHER_CONFIGFILE, "polymc.cfg", "multimc.cfg" }, this));
- // Updates
- // Multiple channels are separated by spaces
- m_settings->registerSetting("UpdateChannel", BuildConfig.VERSION_CHANNEL);
- m_settings->registerSetting("AutoUpdate", true);
// Theming
m_settings->registerSetting("IconTheme", QString("pe_colored"));
- m_settings->registerSetting("ApplicationTheme", QString("system"));
+ m_settings->registerSetting("ApplicationTheme", QString());
m_settings->registerSetting("BackgroundCat", QString("kitteh"));
// Remembered state
@@ -545,6 +564,8 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
m_settings->registerSetting("InstanceDir", "instances");
m_settings->registerSetting({"CentralModsDir", "ModsDir"}, "mods");
m_settings->registerSetting("IconsDir", "icons");
+ m_settings->registerSetting("DownloadsDir", QStandardPaths::writableLocation(QStandardPaths::DownloadLocation));
+ m_settings->registerSetting("DownloadsDirWatchRecursive", false);
// Editors
m_settings->registerSetting("JsonEditor", QString());
@@ -641,6 +662,9 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
m_settings->registerSetting("UpdateDialogGeometry", "");
m_settings->registerSetting("ModDownloadGeometry", "");
+ m_settings->registerSetting("RPDownloadGeometry", "");
+ m_settings->registerSetting("TPDownloadGeometry", "");
+ m_settings->registerSetting("ShaderDownloadGeometry", "");
// HACK: This code feels so stupid is there a less stupid way of doing this?
{
@@ -687,6 +711,7 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
m_settings->set("FlameKeyOverride", flameKey);
m_settings->reset("CFKeyOverride");
}
+ m_settings->registerSetting("ModrinthToken", "");
m_settings->registerSetting("UserAgentOverride", "");
// Init page provider
@@ -714,7 +739,7 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
// initialize network access and proxy setup
{
- m_network = new QNetworkAccessManager();
+ m_network.reset(new QNetworkAccessManager());
QString proxyTypeStr = settings()->get("ProxyType").toString();
QString addr = settings()->get("ProxyAddr").toString();
int port = settings()->get("ProxyPort").value<qint16>();
@@ -736,10 +761,10 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
// initialize the updater
if(BuildConfig.UPDATER_ENABLED)
{
- auto platform = getIdealPlatform(BuildConfig.BUILD_PLATFORM);
- auto channelUrl = BuildConfig.UPDATER_BASE + platform + "/channels.json";
- qDebug() << "Initializing updater with platform: " << platform << " -- " << channelUrl;
- m_updateChecker.reset(new UpdateChecker(m_network, channelUrl, BuildConfig.VERSION_CHANNEL));
+ qDebug() << "Initializing updater";
+#ifdef Q_OS_MAC
+ m_updater.reset(new MacSparkleUpdater());
+#endif
qDebug() << "<> Updater started.";
}
@@ -854,12 +879,7 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
}
});
- {
- setIconTheme(settings()->get("IconTheme").toString());
- qDebug() << "<> Icon theme set.";
- setApplicationTheme(settings()->get("ApplicationTheme").toString(), true);
- qDebug() << "<> Application theme set.";
- }
+ applyCurrentlySelectedTheme(true);
updateCapabilities();
@@ -901,7 +921,8 @@ bool Application::createSetupWizard()
return false;
}();
bool pasteInterventionRequired = settings()->get("PastebinURL") != "";
- bool wizardRequired = javaRequired || languageRequired || pasteInterventionRequired;
+ bool themeInterventionRequired = settings()->get("ApplicationTheme") == "";
+ bool wizardRequired = javaRequired || languageRequired || pasteInterventionRequired || themeInterventionRequired;
if(wizardRequired)
{
@@ -920,6 +941,12 @@ bool Application::createSetupWizard()
{
m_setupWizard->addPage(new PasteWizardPage(m_setupWizard));
}
+
+ if (themeInterventionRequired)
+ {
+ settings()->set("ApplicationTheme", QString("system")); // set default theme after going into theme wizard
+ m_setupWizard->addPage(new ThemeWizardPage(m_setupWizard));
+ }
connect(m_setupWizard, &QDialog::finished, this, &Application::setupWizardFinished);
m_setupWizard->show();
return true;
@@ -942,7 +969,7 @@ bool Application::event(QEvent* event)
if (event->type() == QEvent::FileOpen) {
auto ev = static_cast<QFileOpenEvent*>(event);
- m_mainWindow->droppedURLs({ ev->url() });
+ m_mainWindow->processURLs({ ev->url() });
}
return QApplication::event(event);
@@ -1002,10 +1029,10 @@ void Application::performMainStartupAction()
showMainWindow(false);
qDebug() << "<> Main window shown.";
}
- if(!m_zipToImport.isEmpty())
+ if(!m_zipsToImport.isEmpty())
{
- qDebug() << "<> Importing instance from zip:" << m_zipToImport;
- m_mainWindow->droppedURLs({ m_zipToImport });
+ qDebug() << "<> Importing from zip:" << m_zipsToImport;
+ m_mainWindow->processURLs( m_zipsToImport );
}
}
@@ -1058,7 +1085,7 @@ void Application::messageReceived(const QByteArray& message)
qWarning() << "Received" << command << "message without a zip path/URL.";
return;
}
- m_mainWindow->droppedURLs({ QUrl(path) });
+ m_mainWindow->processURLs({ QUrl::fromLocalFile(QFileInfo(path).absoluteFilePath()) });
}
else if(command == "launch")
{
@@ -1127,9 +1154,14 @@ QList<ITheme*> Application::getValidApplicationThemes()
return m_themeManager->getValidApplicationThemes();
}
-void Application::setApplicationTheme(const QString& name, bool initial)
+void Application::applyCurrentlySelectedTheme(bool initial)
+{
+ m_themeManager->applyCurrentlySelectedTheme(initial);
+}
+
+void Application::setApplicationTheme(const QString& name)
{
- m_themeManager->setApplicationTheme(name, initial);
+ m_themeManager->setApplicationTheme(name);
}
void Application::setIconTheme(const QString& name)
@@ -1357,16 +1389,7 @@ MainWindow* Application::showMainWindow(bool minimized)
m_mainWindow = new MainWindow();
m_mainWindow->restoreState(QByteArray::fromBase64(APPLICATION->settings()->get("MainWindowState").toByteArray()));
m_mainWindow->restoreGeometry(QByteArray::fromBase64(APPLICATION->settings()->get("MainWindowGeometry").toByteArray()));
-#ifdef Q_OS_WIN
- if (IsWindows10OrGreater())
- {
- if (QString::compare(settings()->get("ApplicationTheme").toString(), "dark") == 0) {
- WinDarkmode::setDarkWinTitlebar(m_mainWindow->winId(), true);
- } else {
- WinDarkmode::setDarkWinTitlebar(m_mainWindow->winId(), false);
- }
- }
-#endif
+
if(minimized)
{
m_mainWindow->showMinimized();
@@ -1543,7 +1566,8 @@ QString Application::getJarPath(QString jarFile)
FS::PathCombine(m_rootPath, "share/" + BuildConfig.LAUNCHER_APP_BINARY_NAME),
#endif
FS::PathCombine(m_rootPath, "jars"),
- FS::PathCombine(applicationDirPath(), "jars")
+ FS::PathCombine(applicationDirPath(), "jars"),
+ FS::PathCombine(applicationDirPath(), "..", "jars") // from inside build dir, for debuging
};
for(QString p : potentialPaths)
{
@@ -1574,6 +1598,15 @@ QString Application::getFlameAPIKey()
return BuildConfig.FLAME_API_KEY;
}
+QString Application::getModrinthAPIToken()
+{
+ QString tokenOverride = m_settings->get("ModrinthToken").toString();
+ if (!tokenOverride.isEmpty())
+ return tokenOverride;
+
+ return QString();
+}
+
QString Application::getUserAgent()
{
QString uaOverride = m_settings->get("UserAgentOverride").toString();
@@ -1694,3 +1727,14 @@ bool Application::handleDataMigration(const QString& currentData,
}
return true;
}
+
+void Application::triggerUpdateCheck()
+{
+ if (m_updater) {
+ qDebug() << "Checking for updates.";
+ m_updater->setBetaAllowed(false); // There are no other channels than stable
+ m_updater->checkForUpdates();
+ } else {
+ qDebug() << "Updater not available.";
+ }
+}