consolidate firefox incognitobrowser logic (and deprecate opera/launcher) (#5805)
Co-authored-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com>
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
|
||||
## Unversioned
|
||||
|
||||
- Minor: Treat all browsers starting with `firefox` as a Firefox browser. (#5805)
|
||||
- Minor: Remove incognito browser support for `opera/launcher` (this should no longer be a thing). (#5805)
|
||||
- Bugfix: Fixed a crash relating to Lua HTTP. (#5800)
|
||||
- Dev: Updated Conan dependencies. (#5776)
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
# include "util/XDGHelper.hpp"
|
||||
#endif
|
||||
|
||||
#include <QFileInfo>
|
||||
#include <QProcess>
|
||||
#include <QVariant>
|
||||
|
||||
@@ -12,52 +13,6 @@ namespace {
|
||||
|
||||
using namespace chatterino;
|
||||
|
||||
QString getPrivateSwitch(const QString &browserExecutable)
|
||||
{
|
||||
// list of command line switches to turn on private browsing in browsers
|
||||
static auto switches = std::vector<std::pair<QString, QString>>{
|
||||
{"firefox", "-private-window"},
|
||||
{"librewolf", "-private-window"},
|
||||
{"waterfox", "-private-window"},
|
||||
{"icecat", "-private-window"},
|
||||
{"chrome", "-incognito"},
|
||||
{"google-chrome-stable", "-incognito"},
|
||||
{"vivaldi", "-incognito"},
|
||||
{"opera", "-newprivatetab"},
|
||||
{"opera\\launcher", "--private"},
|
||||
{"iexplore", "-private"},
|
||||
{"msedge", "-inprivate"},
|
||||
{"firefox-esr", "-private-window"},
|
||||
{"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();
|
||||
|
||||
#ifdef Q_OS_WINDOWS
|
||||
if (lowercasedBrowserExecutable.endsWith(".exe"))
|
||||
{
|
||||
lowercasedBrowserExecutable.chop(4);
|
||||
}
|
||||
#endif
|
||||
|
||||
for (const auto &switch_ : switches)
|
||||
{
|
||||
if (lowercasedBrowserExecutable.endsWith(switch_.first))
|
||||
{
|
||||
return switch_.second;
|
||||
}
|
||||
}
|
||||
|
||||
// couldn't match any browser -> unknown browser
|
||||
return {};
|
||||
}
|
||||
|
||||
QString getDefaultBrowserExecutable()
|
||||
{
|
||||
#ifdef USEWINSDK
|
||||
@@ -102,9 +57,62 @@ QString getDefaultBrowserExecutable()
|
||||
}
|
||||
|
||||
} // namespace
|
||||
//
|
||||
|
||||
namespace chatterino::incognitobrowser::detail {
|
||||
|
||||
QString getPrivateSwitch(const QString &browserExecutable)
|
||||
{
|
||||
static auto switches = std::vector<std::pair<QString, QString>>{
|
||||
{"librewolf", "-private-window"},
|
||||
{"waterfox", "-private-window"},
|
||||
{"icecat", "-private-window"},
|
||||
{"chrome", "-incognito"},
|
||||
{"google-chrome-stable", "-incognito"},
|
||||
{"vivaldi", "-incognito"},
|
||||
{"opera", "-newprivatetab"},
|
||||
{"iexplore", "-private"},
|
||||
{"msedge", "-inprivate"},
|
||||
{"chromium", "-incognito"},
|
||||
{"brave", "-incognito"},
|
||||
};
|
||||
|
||||
// the browser executable may be a full path, strip it to its basename and
|
||||
// compare case insensitively
|
||||
auto lowercasedBrowserExecutable =
|
||||
QFileInfo(browserExecutable).baseName().toLower();
|
||||
|
||||
#ifdef Q_OS_WINDOWS
|
||||
if (lowercasedBrowserExecutable.endsWith(".exe"))
|
||||
{
|
||||
lowercasedBrowserExecutable.chop(4);
|
||||
}
|
||||
#endif
|
||||
|
||||
for (const auto &switch_ : switches)
|
||||
{
|
||||
if (lowercasedBrowserExecutable == switch_.first)
|
||||
{
|
||||
return switch_.second;
|
||||
}
|
||||
}
|
||||
|
||||
// catch all mozilla distributed variants
|
||||
if (lowercasedBrowserExecutable.startsWith("firefox"))
|
||||
{
|
||||
return "-private-window";
|
||||
}
|
||||
|
||||
// couldn't match any browser -> unknown browser
|
||||
return {};
|
||||
}
|
||||
|
||||
} // namespace chatterino::incognitobrowser::detail
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
using namespace chatterino::incognitobrowser::detail;
|
||||
|
||||
bool supportsIncognitoLinks()
|
||||
{
|
||||
auto browserExe = getDefaultBrowserExecutable();
|
||||
|
||||
@@ -2,6 +2,12 @@
|
||||
|
||||
#include <QString>
|
||||
|
||||
namespace chatterino::incognitobrowser::detail {
|
||||
|
||||
QString getPrivateSwitch(const QString &browserExecutable);
|
||||
|
||||
} // namespace chatterino::incognitobrowser::detail
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
bool supportsIncognitoLinks();
|
||||
|
||||
@@ -52,6 +52,7 @@ set(test_SOURCES
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/TwitchIrc.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/IgnoreController.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/OnceFlag.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/IncognitoBrowser.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/lib/Snapshot.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/lib/Snapshot.hpp
|
||||
# Add your new file above this line!
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
#include "util/IncognitoBrowser.hpp"
|
||||
|
||||
#include "Test.hpp"
|
||||
|
||||
using namespace chatterino;
|
||||
|
||||
TEST(IncognitoBrowser, getPrivateSwitch)
|
||||
{
|
||||
using namespace chatterino::incognitobrowser::detail;
|
||||
|
||||
ASSERT_EQ(getPrivateSwitch("firefox.exe"), "-private-window");
|
||||
ASSERT_EQ(getPrivateSwitch("firefox"), "-private-window");
|
||||
ASSERT_EQ(getPrivateSwitch("firefox-forsen-version"), "-private-window");
|
||||
|
||||
ASSERT_EQ(getPrivateSwitch("chrome.exe"), "-incognito");
|
||||
ASSERT_EQ(getPrivateSwitch("google-chrome-stable"), "-incognito");
|
||||
|
||||
ASSERT_EQ(getPrivateSwitch("opera.exe"), "-newprivatetab");
|
||||
|
||||
ASSERT_EQ(getPrivateSwitch("unsupportedBrowser.exe"), "");
|
||||
}
|
||||
Reference in New Issue
Block a user