Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Nit: Make ProxyController a featureflag #9771

Merged
merged 2 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/feature/featurelist.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,3 +222,10 @@ FEATURE(webPurchase, // Feature ID
FeatureCallback_true, // Can be flipped off
QStringList(), // feature dependencies
FeatureCallback_webPurchase)

FEATURE(localProxy, // Feature ID
"LocalProxy", // Feature name
FeatureCallback_proxyCanTurnOn, // Can be flipped on
FeatureCallback_true, // Can be flipped off
QStringList(), // feature dependencies
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this have a dependency on split tunnelling?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true!

FeatureCallback_inStaging)
8 changes: 8 additions & 0 deletions src/feature/featurelistcallback.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,4 +194,12 @@ bool FeatureCallback_hasBalrog() {
#endif
}

bool FeatureCallback_proxyCanTurnOn() {
#if defined(MZ_WINDOWS) || defined(MZ_LINUX)
return true;
#else
return false;
#endif
}

#endif // FEATURELISTCALLBACK_H
27 changes: 19 additions & 8 deletions src/proxycontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,19 @@ Logger logger("ProxyController");
}

const QString ProxyController::binaryPath() {
// On Release expect it to be in the same folder
// as the executable
#ifndef MZ_DEBUG
auto binaryPath = QCoreApplication::applicationFilePath();
auto info = QFileInfo(binaryPath);
QDir dir = info.absoluteDir();
return dir.filePath(SOCKSPROXY_BIN);
#else
auto binaryPath = QCoreApplication::applicationFilePath();
auto currentDir = QFileInfo(binaryPath).dir();
auto socksproxydir = QFileInfo(currentDir, "../extension/socks5proxy/bin/");
return socksproxydir.absoluteDir().filePath(SOCKSPROXY_BIN);
#endif
}

void ProxyController::start() {
Expand Down Expand Up @@ -108,16 +117,18 @@ void ProxyController::stop() {
bool ProxyController::canActivate() {
if (!m_canActivate.has_value()) {
m_canActivate = ([]() {
#ifndef MZ_WINDOWS
return false;
#else
// This is not for prod rn.
if (Constants::inProduction()) {
auto const* f = Feature::get(Feature::Feature_localProxy);
if (!f->isSupported()) {
logger.info() << "SocksProxy disabled due to Feature Flag";
return false;
}
auto const* f = Feature::get(Feature::Feature_splitTunnel);
return f->isSupported() && QFileInfo(binaryPath()).exists();
#endif
if (!QFileInfo(binaryPath()).exists()) {
logger.info() << "SocksProxy disabled due to Missing Binary";
logger.info() << "Expected socksproxy here: " << binaryPath();
return false;
}
logger.info() << "Socksproxy is supported";
return true;
})();
}
return m_canActivate.value();
Expand Down
Loading