Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…client into releases/gabriel/mac_os_beetmover
  • Loading branch information
gabrielBusta committed Aug 3, 2022
2 parents 422fdab + e0ce542 commit c38470e
Show file tree
Hide file tree
Showing 23 changed files with 380 additions and 72 deletions.
24 changes: 9 additions & 15 deletions .github/workflows/functional_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,6 @@ jobs:
auth_header="$(git config --local --get http.https://github.com/.extraheader)"
git submodule sync --recursive
git -c "http.extraheader=$auth_header" -c protocol.version=2 submodule update --init --force --recursive --depth=1
- name: Cache build
id: cache-build
uses: actions/cache@v2
with:
path: build/
key: ${{ github.sha }}

- name: Install dependecies
if: steps.cache-build.outputs.cache-hit != 'true'
run: |
Expand All @@ -64,6 +56,10 @@ jobs:
cmake -S $(pwd) -B build/cmake -DBUILD_DUMMY=ON \
-DCMAKE_CXX_FLAGS=--coverage -DCMAKE_EXE_LINKER_FLAGS=--coverage
cmake --build build/cmake -j$(nproc)
- uses: actions/upload-artifact@v3
with:
name: test-client-${{ github.sha }}
path: build/

- name: Generate tasklist
id: testGen
Expand All @@ -73,7 +69,6 @@ jobs:
for test in $(find tests/functional -name 'test*.js' | sort); do
printf '{"name": "%s", "path": "%s"}' $(basename ${test%.js} | sed -n 's/test//p') $test
done | jq -s -c
- name: Check tests
shell: bash
env:
Expand All @@ -94,13 +89,10 @@ jobs:
steps:
- name: Clone repository
uses: actions/checkout@v2

- name: Cache build
id: cache-build
uses: actions/cache@v2
- uses: actions/download-artifact@v3
with:
name: test-client-${{ github.sha }}
path: build/
key: ${{ github.sha }}

- name: Install dependecies
run: |
Expand All @@ -111,7 +103,9 @@ jobs:
- name: Check build
shell: bash
run: ./build/cmake/src/mozillavpn -v
run: |
chmod +x ./build/cmake/src/mozillavpn
./build/cmake/src/mozillavpn -v
- name: Running ${{matrix.test.name}} Tests
id: runTests
Expand Down
27 changes: 27 additions & 0 deletions src/addonmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <QJsonObject>
#include <QFileInfo>
#include <QResource>
#include <QQmlEngine>
#include <QSaveFile>
#include <QStandardPaths>

Expand Down Expand Up @@ -596,3 +597,29 @@ Addon* AddonManager::pick(QJSValue filterCallback) const {

return nullptr;
}

QJSValue AddonManager::reduce(QJSValue callback, QJSValue initialValue) const {
if (!callback.isCallable()) {
logger.error() << "AddonManager.reduce must receive a callable JS value";
return initialValue;
}

QJSEngine* engine = QmlEngineHolder::instance()->engine();
Q_ASSERT(engine);

QJSValue reducedValue = initialValue;

for (QMap<QString, AddonData>::const_iterator i(m_addons.constBegin());
i != m_addons.constEnd(); ++i) {
if (!i.value().m_addon || !i.value().m_addon->enabled()) {
continue;
}

QJSValueList arguments;
arguments.append(engine->toScriptValue(i.value().m_addon));
arguments.append(reducedValue);
reducedValue = callback.call(arguments);
}

return reducedValue;
}
2 changes: 2 additions & 0 deletions src/addonmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class AddonManager final : public QAbstractListModel {
public:
Q_INVOKABLE Addon* pick(QJSValue filterCallback) const;

Q_INVOKABLE QJSValue reduce(QJSValue callback, QJSValue initialValue) const;

enum ModelRoles {
AddonRole = Qt::UserRole + 1,
};
Expand Down
77 changes: 56 additions & 21 deletions src/addons/addon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ bool evaluateConditionsSettingsOp(const QString& op, bool result) {

struct ConditionCallback {
QString m_key;
std::function<bool(const QJsonValue&)> m_callback;
std::function<bool(const QJsonValue&)> m_staticCallback;
std::function<AddonConditionWatcher*(QObject*, const QJsonValue&)>
m_dynamicCallback;
};

QList<ConditionCallback> s_conditionCallbacks{
Expand All @@ -62,6 +64,9 @@ QList<ConditionCallback> s_conditionCallbacks{
}

return true;
},
[](QObject*, const QJsonValue&) -> AddonConditionWatcher* {
return nullptr;
}},

{"platforms",
Expand All @@ -78,6 +83,9 @@ QList<ConditionCallback> s_conditionCallbacks{
}

return true;
},
[](QObject*, const QJsonValue&) -> AddonConditionWatcher* {
return nullptr;
}},

{"settings",
Expand Down Expand Up @@ -131,6 +139,9 @@ QList<ConditionCallback> s_conditionCallbacks{
}

return true;
},
[](QObject*, const QJsonValue&) -> AddonConditionWatcher* {
return nullptr;
}},

{"env",
Expand All @@ -151,6 +162,9 @@ QList<ConditionCallback> s_conditionCallbacks{

logger.info() << "Unknown env value:" << env;
return false;
},
[](QObject*, const QJsonValue&) -> AddonConditionWatcher* {
return nullptr;
}},

{"min_client_version",
Expand All @@ -166,6 +180,9 @@ QList<ConditionCallback> s_conditionCallbacks{
}

return true;
},
[](QObject*, const QJsonValue&) -> AddonConditionWatcher* {
return nullptr;
}},

{"max_client_version",
Expand All @@ -181,6 +198,33 @@ QList<ConditionCallback> s_conditionCallbacks{
}

return true;
},
[](QObject*, const QJsonValue&) -> AddonConditionWatcher* {
return nullptr;
}},

{"locales",
[](const QJsonValue&) -> bool {
// dynamic condition
return true;
},
[](QObject* parent, const QJsonValue& value) -> AddonConditionWatcher* {
QStringList locales;
for (const QJsonValue& v : value.toArray()) {
locales.append(v.toString().toLower());
}

return AddonConditionWatcherLocales::maybeCreate(parent, locales);
}},

{"trigger_time",
[](const QJsonValue&) -> bool {
// dynamic condition
return true;
},
[](QObject* parent, const QJsonValue& value) -> AddonConditionWatcher* {
return AddonConditionWatcherTriggerTimeSecs::maybeCreate(
parent, value.toInteger());
}},
};

Expand Down Expand Up @@ -317,25 +361,16 @@ void Addon::retranslate() {
void Addon::maybeCreateConditionWatchers(const QJsonObject& conditions) {
QList<AddonConditionWatcher*> watcherList;

{
QStringList locales;
for (const QJsonValue& value : conditions["locales"].toArray()) {
locales.append(value.toString().toLower());
}

AddonConditionWatcher* tmpWatcher =
AddonConditionWatcherLocales::maybeCreate(this, locales);
if (tmpWatcher) {
watcherList.append(tmpWatcher);
}
}

{
AddonConditionWatcher* tmpWatcher =
AddonConditionWatcherTriggerTimeSecs::maybeCreate(
this, conditions["trigger_time"].toInteger());
if (tmpWatcher) {
watcherList.append(tmpWatcher);
for (const QString& key : conditions.keys()) {
for (const ConditionCallback& condition : s_conditionCallbacks) {
if (condition.m_key == key) {
AddonConditionWatcher* conditionWatcher =
condition.m_dynamicCallback(this, conditions[key]);
if (conditionWatcher) {
watcherList.append(conditionWatcher);
}
break;
}
}
}

Expand Down Expand Up @@ -370,7 +405,7 @@ bool Addon::evaluateConditions(const QJsonObject& conditions) {
bool found = false;
for (const ConditionCallback& condition : s_conditionCallbacks) {
if (condition.m_key == key) {
if (!condition.m_callback(conditions[key])) {
if (!condition.m_staticCallback(conditions[key])) {
return false;
}
found = true;
Expand Down
8 changes: 4 additions & 4 deletions src/commands/commandui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include "closeeventhandler.h"
#include "commandlineparser.h"
#include "constants.h"
#include "filterproxymodel.h"
#include "fontloader.h"
#include "iaphandler.h"
#include "imageproviderfactory.h"
Expand All @@ -35,6 +34,7 @@
#include <lottie.h>
#include <nebula.h>

#include <QQmlApplicationEngine>
#include <QQmlContext>

#ifdef MVPN_DEBUG
Expand Down Expand Up @@ -203,8 +203,8 @@ int CommandUI::run(QStringList& tokens) {
}
#endif
// This object _must_ live longer than MozillaVPN to avoid shutdown crashes.
QmlEngineHolder* engineHolder = new QmlEngineHolder();
QQmlApplicationEngine* engine = QmlEngineHolder::instance()->engine();
QQmlApplicationEngine* engine = new QQmlApplicationEngine();
QmlEngineHolder engineHolder(engine);

// TODO pending #3398
QQmlContext* ctx = engine->rootContext();
Expand Down Expand Up @@ -565,7 +565,7 @@ int CommandUI::run(QStringList& tokens) {
engine->load(url);

NotificationHandler* notificationHandler =
NotificationHandler::create(engineHolder);
NotificationHandler::create(&engineHolder);

QObject::connect(vpn.controller(), &Controller::stateChanged,
notificationHandler,
Expand Down
2 changes: 2 additions & 0 deletions src/crashreporter/crashreporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@

#include "crashreporter.h"
#include "crashui.h"
#include "qmlengineholder.h"

using namespace std;

CrashReporter::CrashReporter(QObject* parent) : QObject(parent) {
m_ui = make_unique<CrashUI>();
new QmlEngineHolder(&m_engine);
}

bool CrashReporter::shouldPromptUser() {
Expand Down
4 changes: 2 additions & 2 deletions src/crashreporter/crashreporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
#define CRASHREPORTER_H

#include <QObject>
#include <QQmlApplicationEngine>
#include <memory>

#include "crashui.h"
#include "qmlengineholder.h"
#include "settingsholder.h"
#include "localizer.h"

Expand All @@ -29,7 +29,7 @@ class CrashReporter : public QObject {

private:
std::unique_ptr<CrashUI> m_ui;
QmlEngineHolder m_engineHolder;
QQmlApplicationEngine m_engine;
SettingsHolder settings;
Localizer localizer;
};
Expand Down
4 changes: 3 additions & 1 deletion src/crashreporter/crashui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "qmlengineholder.h"
#include "theme.h"

#include <QQmlApplicationEngine>
#include <QCoreApplication>
#include <QWindow>

Expand Down Expand Up @@ -62,7 +63,8 @@ void CrashUI::initialize() {
});

const QUrl url(QML_MAIN);
QmlEngineHolder::instance()->engine()->load(url);
qobject_cast<QQmlApplicationEngine*>(QmlEngineHolder::instance()->engine())
->load(url);
m_initialized = true;
}
}
Expand Down
Loading

0 comments on commit c38470e

Please sign in to comment.