Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

consolidate firefox incognitobrowser logic (and deprecate opera/launcher) #5805

Merged
merged 11 commits into from
Jan 11, 2025
39 changes: 22 additions & 17 deletions src/util/IncognitoBrowser.cpp
Original file line number Diff line number Diff line change
@@ -5,18 +5,22 @@
# include "util/XDGHelper.hpp"
#endif

#include <QFileInfo>
#include <QProcess>
#include <QVariant>

namespace {

using namespace chatterino;

QString getPrivateSwitch(const QString &browserExecutable)
QString getPrivateArg(const QString &exePath)
teknsl marked this conversation as resolved.
Show resolved Hide resolved
{
// list of command line switches to turn on private browsing in browsers
static auto switches = std::vector<std::pair<QString, QString>>{
{"firefox", "-private-window"},
struct Entry {
QString exe;
QString arg;
};

static std::vector<Entry> lut{
teknsl marked this conversation as resolved.
Show resolved Hide resolved
{"librewolf", "-private-window"},
{"waterfox", "-private-window"},
{"icecat", "-private-window"},
@@ -30,30 +34,31 @@ QString getPrivateSwitch(const QString &browserExecutable)
{"firefox-esr", "-private-window"},
teknsl marked this conversation as resolved.
Show resolved Hide resolved
{"chromium", "-incognito"},
{"brave", "-incognito"},
{"firefox-devedition", "-private-window"},
{"firefox-developer-edition", "-private-window"},
{"firefox-beta", "-private-window"},
{"firefox-nightly", "-private-window"},
};

// compare case-insensitively
auto lowercasedBrowserExecutable = browserExecutable.toLower();
QString exe = QFileInfo(exePath).baseName().toLower();
teknsl marked this conversation as resolved.
Show resolved Hide resolved

#ifdef Q_OS_WINDOWS
if (lowercasedBrowserExecutable.endsWith(".exe"))
if (exe.endsWith(".exe"))
{
lowercasedBrowserExecutable.chop(4);
exe.chop(4);
}
#endif

for (const auto &switch_ : switches)
for (const auto &entry : lut)
{
if (lowercasedBrowserExecutable.endsWith(switch_.first))
if (exe == entry.exe)
{
return switch_.second;
return entry.arg;
teknsl marked this conversation as resolved.
Show resolved Hide resolved
}
}

// catch all mozilla distributed variants
if (exe.startsWith("firefox"))
{
return "-private-window";
}

// couldn't match any browser -> unknown browser
return {};
}
@@ -108,14 +113,14 @@ namespace chatterino {
bool supportsIncognitoLinks()
{
auto browserExe = getDefaultBrowserExecutable();
return !browserExe.isNull() && !getPrivateSwitch(browserExe).isNull();
return !browserExe.isNull() && !getPrivateArg(browserExe).isNull();
}

bool openLinkIncognito(const QString &link)
{
auto browserExe = getDefaultBrowserExecutable();
return QProcess::startDetached(browserExe,
{getPrivateSwitch(browserExe), link});
{getPrivateArg(browserExe), link});
}

} // namespace chatterino
Loading