This commit is contained in:
Martin Rotter 2022-10-27 12:03:44 +02:00
parent c440e38313
commit 9fff2feac5
4 changed files with 30 additions and 4 deletions

View File

@ -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"

View File

@ -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."),

View File

@ -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)

View File

@ -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);
}
}