History

Add "ScriptGatekeeper" class and "PRELOADED_SCRIPT_WHITELIST" variable.

Kalila L committed 5 years ago

Commit 3ed98d01 parent bab76f79 files · +83 −1Browse files

Showing the changes to libraries/script-engine/src/ScriptGatekeeper.cpp (1 of 9 files). Show all

Unified · Split

libraries/script-engine/src/ScriptGatekeeper.cpp+41−0
@@ -0,0 +1,41 @@
1+//
2+// ScriptGatekeeper.cpp
3+// libraries/script-engine/src
4+//
5+// Created by Kalila L. on Mar 7 2021
6+// Copyright 2021 Vircadia contributors.
7+//
8+// Distributed under the Apache License, Version 2.0.
9+// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
10+//
11+
12+#include "ScriptGatekeeper.h"
13+
14+#include "BuildInfo.h"
15+#include "SettingHandle.h"
16+
17+void ScriptGatekeeper::initialize() {
18+ if (_initialized == true) {
19+ return;
20+ }
21+
22+ QVariant rawCurrentWhitelistValues = Setting::Handle<QVariant>(SCRIPT_WHITELIST_ENTRIES_KEY).get();
23+ QString settingsSafeValues = rawCurrentWhitelistValues.toString();
24+
25+ Setting::Handle<bool> whitelistEnabled{ SCRIPT_WHITELIST_ENABLED_KEY, false };
26+ Setting::Handle<bool> isFirstRun { Settings::firstRun, true };
27+
28+ QString preloadedVal = BuildInfo::PRELOADED_SCRIPT_WHITELIST;
29+
30+ if (settingsSafeValues.isEmpty() && !preloadedVal.isEmpty() && isFirstRun.get()) {
31+ // We assume that the whitelist should be enabled if a preloaded whitelist is attached, so we activate it if it's not already active.
32+ qDebug() << "hi" << !whitelistEnabled.get() << whitelistEnabled.get();
33+ if (!whitelistEnabled.get()) {
34+ whitelistEnabled.set(true);
35+ }
36+
37+ Setting::Handle<QVariant>(SCRIPT_WHITELIST_ENTRIES_KEY).set(preloadedVal);
38+ }
39+
40+ _initialized = true;
41+}