added basic code for incognito links

This commit is contained in:
fourtf 2018-10-16 14:13:19 +02:00
parent 31b9d497d7
commit 280605e715
7 changed files with 186 additions and 18 deletions

View file

@ -261,7 +261,8 @@ SOURCES += \
src/messages/MessageContainer.cpp \ src/messages/MessageContainer.cpp \
src/debug/Benchmark.cpp \ src/debug/Benchmark.cpp \
src/common/UsernameSet.cpp \ src/common/UsernameSet.cpp \
src/widgets/settingspages/AdvancedPage.cpp src/widgets/settingspages/AdvancedPage.cpp \
src/util/IncognitoBrowser.cpp
HEADERS += \ HEADERS += \
src/Application.hpp \ src/Application.hpp \
@ -462,7 +463,8 @@ HEADERS += \
src/widgets/helper/Button.hpp \ src/widgets/helper/Button.hpp \
src/messages/MessageContainer.hpp \ src/messages/MessageContainer.hpp \
src/common/UsernameSet.hpp \ src/common/UsernameSet.hpp \
src/widgets/settingspages/AdvancedPage.hpp src/widgets/settingspages/AdvancedPage.hpp \
src/util/IncognitoBrowser.hpp
RESOURCES += \ RESOURCES += \
resources/resources.qrc \ resources/resources.qrc \

View file

@ -2,6 +2,7 @@
#include "RunGui.hpp" #include "RunGui.hpp"
#include "singletons/Paths.hpp" #include "singletons/Paths.hpp"
#include "singletons/Settings.hpp" #include "singletons/Settings.hpp"
#include "util/IncognitoBrowser.hpp"
#include <QApplication> #include <QApplication>
#include <QStringList> #include <QStringList>
@ -11,9 +12,6 @@ using namespace chatterino;
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
auto shared = std::make_shared<QString>();
log(std::atomic_is_lock_free(&shared));
QApplication a(argc, argv); QApplication a(argc, argv);
// convert char** to QStringList // convert char** to QStringList

59
src/nullableptr.h Normal file
View file

@ -0,0 +1,59 @@
#pragma once
namespace chatterino {
template <typename T>
class NullablePtr
{
public:
NullablePtr()
: element_(nullptr)
{
}
NullablePtr(T *element)
: element_(element)
{
}
T *operator->() const
{
assert(this->hasElement());
return element_;
}
T &operator*() const
{
assert(this->hasElement());
return *element_;
}
T *get() const
{
assert(this->hasElement());
return this->element_;
}
bool isNull() const
{
return this->element_ == nullptr;
}
bool hasElement() const
{
return this->element_ != nullptr;
}
operator bool() const
{
return this->hasElement();
}
private:
T *element_;
};
} // namespace chatterino

View file

@ -0,0 +1,74 @@
#include "incognitobrowser.hpp"
#include <QProcess>
#include <QSettings>
#include <QVariant>
#include "debug/Log.hpp"
#ifdef Q_OS_WIN
namespace chatterino {
namespace {
QString getAppPath(const QString &executableName)
{
auto paths = QStringList{
// clang-format off
"HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\" + executableName,
"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\" + executableName
// clang-format on
};
for (const auto &path : paths) {
auto val = QSettings(path, QSettings::NativeFormat)
.value("Default")
.toString();
if (!val.isNull()) {
return val;
}
}
return QString();
}
} // namespace
void openLinkIncognito(const QString &link)
{
auto browserChoice = QSettings("HKEY_CURRENT_"
"USER\\Software\\Microsoft\\Windows\\Shell\\"
"Associations\\UrlAssociatio"
"ns\\http\\UserChoice",
QSettings::NativeFormat)
.value("Progid")
.toString();
if (!browserChoice.isNull()) {
if (browserChoice == "FirefoxURL") {
// Firefox
auto path = getAppPath("firefox.exe");
QProcess::startDetached(path, {"-private-window", link});
} else if (browserChoice == "ChromeHTML") {
// Chrome
auto path = getAppPath("chrome.exe");
QProcess::startDetached(path, {"-incognito", link});
}
// Possible implementation for MS Edge.
// Doesn't quite work yet.
/*
else if (browserChoice == "AppXq0fevzme2pys62n3e0fbqa7peapykr8v") {
// Edge
QProcess::startDetached("C:\\Windows\\System32\\cmd.exe",
{"/c", "start",
"shell:AppsFolder\Microsoft.MicrosoftEdge_"
"8wekyb3d8bbwe!MicrosoftEdge",
"-private", link});
}
*/
}
}
} // namespace chatterino
#endif

View file

@ -0,0 +1,14 @@
#pragma once
#include <QtGlobal>
#ifdef Q_OS_WIN
// only supported on windows right now
# define INCOGNITO_LINKS_SUPPORTED
namespace chatterino {
void openLinkIncognito(const QString &link);
}
#endif

View file

@ -0,0 +1,21 @@
#pragma once
#include <algorithm>
namespace chatterino {
namespace util {
template <typename Container, typename UnaryPredicate>
typename Container::iterator find_if(Container &container, UnaryPredicate pred)
{
return std::find_if(container.begin(), container.end(), pred);
}
template <typename Container, typename UnaryPredicate>
bool any_of(Container &container, UnaryPredicate pred)
{
return std::any_of(container.begin(), container.end(), pred);
}
} // namespace util
} // namespace chatterino

View file

@ -3,19 +3,19 @@
#include "widgets/BaseWidget.hpp" #include "widgets/BaseWidget.hpp"
#include <QtCore/QVariant> #include <QtCore/QVariant>
#include <QtWidgets/QAction> #include <QAction>
#include <QtWidgets/QApplication> #include <QApplication>
#include <QtWidgets/QButtonGroup> #include <QButtonGroup>
#include <QtWidgets/QDialog> #include <QDialog>
#include <QtWidgets/QDialogButtonBox> #include <QDialogButtonBox>
#include <QtWidgets/QFormLayout> #include <QFormLayout>
#include <QtWidgets/QHBoxLayout> #include <QHBoxLayout>
#include <QtWidgets/QHeaderView> #include <QHeaderView>
#include <QtWidgets/QLabel> #include <QLabel>
#include <QtWidgets/QLineEdit> #include <QLineEdit>
#include <QtWidgets/QPushButton> #include <QPushButton>
#include <QtWidgets/QTabWidget> #include <QTabWidget>
#include <QtWidgets/QVBoxLayout> #include <QVBoxLayout>
namespace chatterino { namespace chatterino {