Flatten util/IncognitoBrowser.{h,c}pp (#4280)

This commit is contained in:
pajlada 2023-01-01 13:06:34 +01:00 committed by GitHub
parent 1043f9f803
commit e48945e370
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 66 additions and 57 deletions

View file

@ -1,15 +1,17 @@
#include "IncognitoBrowser.hpp" #include "util/IncognitoBrowser.hpp"
#include <QProcess> #include <QProcess>
#include <QRegularExpression> #include <QRegularExpression>
#include <QSettings> #include <QSettings>
#include <QVariant> #include <QVariant>
namespace chatterino {
namespace { namespace {
using namespace chatterino;
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
QString injectPrivateSwitch(QString command) QString injectPrivateSwitch(QString command)
{ {
// list of command line switches to turn on private browsing in browsers // list of command line switches to turn on private browsing in browsers
static auto switches = std::vector<std::pair<QString, QString>>{ static auto switches = std::vector<std::pair<QString, QString>>{
{"firefox", "-private-window"}, {"librewolf", "-private-window"}, {"firefox", "-private-window"}, {"librewolf", "-private-window"},
@ -41,10 +43,10 @@ namespace {
// couldn't match any browser -> unknown browser // couldn't match any browser -> unknown browser
return QString(); return QString();
} }
QString getCommand(const QString &link) QString getCommand(const QString &link)
{ {
// get default browser prog id // get default browser prog id
auto browserId = QSettings("HKEY_CURRENT_" auto browserId = QSettings("HKEY_CURRENT_"
"USER\\Software\\Microsoft\\Windows\\Shell\\" "USER\\Software\\Microsoft\\Windows\\Shell\\"
@ -55,27 +57,34 @@ namespace {
.toString(); .toString();
// get default browser start command // get default browser start command
auto command = QSettings("HKEY_CLASSES_ROOT\\" + browserId + auto command =
"\\shell\\open\\command", QSettings("HKEY_CLASSES_ROOT\\" + browserId + "\\shell\\open\\command",
QSettings::NativeFormat) QSettings::NativeFormat)
.value("Default") .value("Default")
.toString(); .toString();
if (command.isNull()) if (command.isNull())
{
return QString(); return QString();
}
// inject switch to enable private browsing // inject switch to enable private browsing
command = injectPrivateSwitch(command); command = injectPrivateSwitch(command);
if (command.isNull()) if (command.isNull())
{
return QString(); return QString();
}
// link // link
command += " " + link; command += " " + link;
return command; return command;
} }
#endif #endif
} // namespace } // namespace
namespace chatterino {
bool supportsIncognitoLinks() bool supportsIncognitoLinks()
{ {
#ifdef Q_OS_WIN #ifdef Q_OS_WIN

View file

@ -1,6 +1,6 @@
#pragma once #pragma once
#include <QtGlobal> #include <QString>
namespace chatterino { namespace chatterino {