diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index b76e3f8dca..c1f972eb30 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -355,6 +355,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; @@ -1966,6 +1967,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(); @@ -2600,6 +2603,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 16dadc8bf0..5cb5fdd5c0 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -472,6 +472,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 e175309f06..19cc7eacaa 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -4,14 +4,14 @@ // // Created by Stephen Birarda on 8/12/13. // Copyright 2013 High Fidelity, Inc. +// Copyright 2020 Vircadia contributors. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // - -// For happ(ier) development of QML, use these two things: -// This forces QML files to be pulled from the source as you edit it: set environment variable HIFI_USE_SOURCE_TREE_RESOURCES=1 -// Use this to live reload: DependencyManager::get()->clearCache(); +// For happ(ier) development of QML, use these two things: +// This forces QML files to be pulled from the source as you edit it: set environment variable HIFI_USE_SOURCE_TREE_RESOURCES=1 +// Use this to live reload: DependencyManager::get()->clearCache(); #include "Menu.h" #include @@ -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..cac8e77f9e 100644 --- a/interface/src/Menu.h +++ b/interface/src/Menu.h @@ -4,6 +4,7 @@ // // Created by Stephen Birarda on 8/12/13. // Copyright 2013 High Fidelity, Inc. +// Copyright 2020 Vircadia contributors. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html @@ -54,6 +55,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 88c682370c..9480b498ba 100644 --- a/libraries/script-engine/src/ScriptEngine.cpp +++ b/libraries/script-engine/src/ScriptEngine.cpp @@ -1941,9 +1941,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 we should invalidate the cache based on a user setting. + 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()); diff --git a/libraries/script-engine/src/ScriptEngine.h b/libraries/script-engine/src/ScriptEngine.h index 219453875e..8cbeed58af 100644 --- a/libraries/script-engine/src/ScriptEngine.h +++ b/libraries/script-engine/src/ScriptEngine.h @@ -4,6 +4,7 @@ // // Created by Brad Hefta-Gaub on 12/14/13. // Copyright 2013 High Fidelity, Inc. +// Copyright 2020 Vircadia contributors. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html