From 9f3978d3d5547dea5a2ec388876712e5aa6d1e49 Mon Sep 17 00:00:00 2001 From: Kalila L Date: Thu, 17 Sep 2020 18:40:01 -0400 Subject: [PATCH] Update system to use a checkbox + setting instead. --- interface/src/Application.cpp | 13 +++++++++++++ interface/src/Application.h | 2 ++ interface/src/Menu.cpp | 4 ++++ interface/src/Menu.h | 1 + libraries/script-engine/src/ScriptEngine.cpp | 5 ++++- 5 files changed, 24 insertions(+), 1 deletion(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index fe2077f752..26ff27044d 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -354,6 +354,7 @@ static const QString DESKTOP_DISPLAY_PLUGIN_NAME = "Desktop"; static const QString ACTIVE_DISPLAY_PLUGIN_SETTING_NAME = "activeDisplayPlugin"; static const QString SYSTEM_TABLET = "com.highfidelity.interface.tablet.system"; static const QString KEEP_ME_LOGGED_IN_SETTING_NAME = "keepMeLoggedIn"; +static const QString CACHEBUST_SCRIPT_REQUIRE_SETTING_NAME = "cachebustScriptRequire"; static const float FOCUS_HIGHLIGHT_EXPANSION_FACTOR = 1.05f; @@ -1958,6 +1959,8 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo loadSettings(); updateVerboseLogging(); + + setCachebustRequire(); // Make sure we don't time out during slow operations at startup updateHeartbeat(); @@ -2591,6 +2594,16 @@ void Application::updateVerboseLogging() { QLoggingCategory::setFilterRules(rules); } +void Application::setCachebustRequire() { + auto menu = Menu::getInstance(); + if (!menu) { + return; + } + bool enable = menu->isOptionChecked(MenuOption::CachebustRequire); + + Setting::Handle{ CACHEBUST_SCRIPT_REQUIRE_SETTING_NAME, false }.set(enable); +} + void Application::domainConnectionRefused(const QString& reasonMessage, int reasonCodeInt, const QString& extraInfo) { DomainHandler::ConnectionRefusedReason reasonCode = static_cast(reasonCodeInt); diff --git a/interface/src/Application.h b/interface/src/Application.h index f42696cda0..eddf45686d 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -470,6 +470,8 @@ public slots: void setIsInterstitialMode(bool interstitialMode); void updateVerboseLogging(); + + void setCachebustRequire(); void changeViewAsNeeded(float boomLength); diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index e460b4b56b..8870d852ba 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -365,6 +365,10 @@ Menu::Menu() { // Developer > Scripting > Verbose Logging addCheckableActionToQMenuAndActionHash(scriptingOptionsMenu, MenuOption::VerboseLogging, 0, false, qApp, SLOT(updateVerboseLogging())); + + // Developer > Scripting > Enable Cachebusting of Script.require + addCheckableActionToQMenuAndActionHash(scriptingOptionsMenu, MenuOption::CachebustRequire, 0, false, + qApp, SLOT(setCachebustRequire())); // Developer > Scripting > Enable Speech Control API #if defined(Q_OS_MAC) || defined(Q_OS_WIN) diff --git a/interface/src/Menu.h b/interface/src/Menu.h index d33b3b0f5e..c7ca64eb5a 100644 --- a/interface/src/Menu.h +++ b/interface/src/Menu.h @@ -54,6 +54,7 @@ namespace MenuOption { const QString BookmarkAvatarEntities = "Bookmark Avatar Entities"; const QString BookmarkLocation = "Bookmark Location"; const QString CalibrateCamera = "Calibrate Camera"; + const QString CachebustRequire = "Enable Cachebusting of Script.require"; const QString CenterPlayerInView = "Center Player In View"; const QString Chat = "Chat..."; const QString ClearDiskCaches = "Clear Disk Caches (requires restart)"; diff --git a/libraries/script-engine/src/ScriptEngine.cpp b/libraries/script-engine/src/ScriptEngine.cpp index 3b2a122e71..c2fa5bee04 100644 --- a/libraries/script-engine/src/ScriptEngine.cpp +++ b/libraries/script-engine/src/ScriptEngine.cpp @@ -1873,9 +1873,12 @@ QScriptValue ScriptEngine::require(const QString& moduleId) { // modules get cached in `Script.require.cache` and (similar to Node.js) users can access it // to inspect particular entries and invalidate them by deleting the key: // `delete Script.require.cache[Script.require.resolve(moduleId)];` + + // Check to see if + Setting::Handle getCachebustSetting {"cachebustScriptRequire", false }; // cacheMeta is just used right now to tell deleted keys apart from undefined ones - bool invalidateCache = module.isUndefined() && cacheMeta.property(moduleId).isValid(); + bool invalidateCache = getCachebustSetting.get() || (module.isUndefined() && cacheMeta.property(moduleId).isValid()); // reset the cacheMeta record so invalidation won't apply next time, even if the module fails to load cacheMeta.setProperty(modulePath, QScriptValue());