From 9fff2feac58353ca4cfac9fb46c75dee029e7785 Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Thu, 27 Oct 2022 12:03:44 +0200 Subject: [PATCH] fixed #819 --- src/librssguard/definitions/definitions.h | 4 ++++ src/librssguard/miscellaneous/application.cpp | 19 ++++++++++++++++++- src/librssguard/miscellaneous/application.h | 3 +++ .../network-web/adblock/adblockmanager.cpp | 8 +++++--- 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/librssguard/definitions/definitions.h b/src/librssguard/definitions/definitions.h index 0651d4f8c..e7ba14adc 100644 --- a/src/librssguard/definitions/definitions.h +++ b/src/librssguard/definitions/definitions.h @@ -16,6 +16,7 @@ #define SERVICE_CODE_REDDIT "reddit" #define SERVICE_CODE_NEWSBLUR "newsblur" +#define ADBLOCK_SERVER_FILE "adblock-server.js" #define ADBLOCK_SERVER_PORT 48484 #define ADBLOCK_HOWTO "https://github.com/martinrotter/rssguard/blob/master/resources/docs/Documentation.md#adbl" #define ADBLOCK_ICON_ACTIVE "adblock" @@ -117,6 +118,9 @@ #define CLI_SIN_SHORT "s" #define CLI_SIN_LONG "no-single-instance" +#define CLI_ADBLOCKPORT_SHORT "p" +#define CLI_ADBLOCKPORT_LONG "adblock-port" + #define CLI_NSTDOUTERR_SHORT "n" #define CLI_NSTDOUTERR_LONG "no-standard-output" diff --git a/src/librssguard/miscellaneous/application.cpp b/src/librssguard/miscellaneous/application.cpp index e1101abd8..a3e250b63 100644 --- a/src/librssguard/miscellaneous/application.cpp +++ b/src/librssguard/miscellaneous/application.cpp @@ -363,6 +363,10 @@ void Application::eliminateFirstRuns() { settings()->setValue(GROUP(General), QString(General::FirstRun) + QL1C('_') + APP_VERSION, false); } +int Application::customAdblockPort() const { + return m_customAdblockPort; +} + QStringList Application::rawCliArgs() const { return m_rawCliArgs; } @@ -1044,6 +1048,15 @@ void Application::parseCmdArgumentsFromMyInstance(const QStringList& raw_cli_arg s_disableDebug = true; qDebugNN << LOGSEC_CORE << "Disabling any stdout/stderr outputs."; } + + if (!m_cmdParser.value(QSL(CLI_ADBLOCKPORT_SHORT)).isEmpty()) { + m_customAdblockPort = m_cmdParser.value(QSL(CLI_ADBLOCKPORT_SHORT)).toInt(); + + qDebugNN << LOGSEC_ADBLOCK << "Setting custom server port."; + } + else { + m_customAdblockPort = 0; + } } void Application::fillCmdArgumentsParser(QCommandLineParser& parser) { @@ -1072,13 +1085,17 @@ void Application::fillCmdArgumentsParser(QCommandLineParser& parser) { QCommandLineOption forced_style({QSL(CLI_STYLE_SHORT), QSL(CLI_STYLE_LONG)}, QSL("Force some application style."), QSL("style-name")); + QCommandLineOption + adblock_port({QSL(CLI_ADBLOCKPORT_SHORT), QSL(CLI_ADBLOCKPORT_LONG)}, + QSL("Use custom port for AdBlock server. It is highly recommended to use values higher than 1024."), + QSL("port")); parser.addOptions({ help, version, log_file, custom_data_folder, disable_singleinstance, disable_only_debug, disable_debug, #if defined(USE_WEBENGINE) force_nowebengine, #endif - forced_style + forced_style, adblock_port }); parser.addPositionalArgument(QSL("urls"), QSL("List of URL addresses pointing to individual online feeds which should be added."), diff --git a/src/librssguard/miscellaneous/application.h b/src/librssguard/miscellaneous/application.h index e45be9ce7..f467c9375 100644 --- a/src/librssguard/miscellaneous/application.h +++ b/src/librssguard/miscellaneous/application.h @@ -178,6 +178,8 @@ class RSSGUARD_DLLSPEC Application : public SingleApplication { // Custom debug/console log handler. static void performLogging(QtMsgType type, const QMessageLogContext& context, const QString& msg); + int customAdblockPort() const; + public slots: // Restarts the application. void restart(); @@ -256,6 +258,7 @@ class RSSGUARD_DLLSPEC Application : public SingleApplication { bool m_firstRunEver; bool m_firstRunCurrentVersion; QString m_customDataFolder; + int m_customAdblockPort; bool m_allowMultipleInstances; #if defined(USE_WEBENGINE) diff --git a/src/librssguard/network-web/adblock/adblockmanager.cpp b/src/librssguard/network-web/adblock/adblockmanager.cpp index 3fbd218ef..a846bcc5c 100644 --- a/src/librssguard/network-web/adblock/adblockmanager.cpp +++ b/src/librssguard/network-web/adblock/adblockmanager.cpp @@ -302,9 +302,9 @@ QString AdBlockManager::askServerForCosmeticRules(const QString& url) const { QProcess* AdBlockManager::startServer(int port) { QString temp_server = QDir::toNativeSeparators(IOFactory::getSystemFolder(QStandardPaths::StandardLocation::TempLocation)) + - QDir::separator() + QSL("adblock-server.js"); + QDir::separator() + QSL(ADBLOCK_SERVER_FILE); - if (!IOFactory::copyFile(QSL(":/scripts/adblock/adblock-server.js"), temp_server)) { + if (!IOFactory::copyFile(QSL(":/scripts/adblock/") + QSL(ADBLOCK_SERVER_FILE), temp_server)) { qWarningNN << LOGSEC_ADBLOCK << "Failed to copy server file to TEMP."; } @@ -385,6 +385,8 @@ void AdBlockManager::updateUnifiedFiltersFileAndStartServer() { IOFactory::writeFile(m_unifiedFiltersFile, unified_contents.toUtf8()); if (m_enabled) { - m_serverProcess = startServer(ADBLOCK_SERVER_PORT); + auto custom_port = qApp->customAdblockPort(); + + m_serverProcess = startServer(custom_port > 0 ? custom_port : ADBLOCK_SERVER_PORT); } }