mirror of
https://github.com/overte-org/overte.git
synced 2025-04-15 17:20:12 +02:00
Merge pull request #15866 from huffman/feat/override-default-scripts
DEV-164: Add defaultScriptsOverride option
This commit is contained in:
commit
f235778a6e
4 changed files with 31 additions and 7 deletions
|
@ -839,6 +839,8 @@ bool setupEssentials(int& argc, char** argv, bool runningMarkerExisted) {
|
|||
QCoreApplication::addLibraryPath(audioDLLPath);
|
||||
#endif
|
||||
|
||||
QString defaultScriptsOverrideOption = getCmdOption(argc, constArgv, "--defaultScriptsOverride");
|
||||
|
||||
DependencyManager::registerInheritance<LimitedNodeList, NodeList>();
|
||||
DependencyManager::registerInheritance<AvatarHashMap, AvatarManager>();
|
||||
DependencyManager::registerInheritance<EntityDynamicFactoryInterface, InterfaceDynamicFactory>();
|
||||
|
@ -860,7 +862,7 @@ bool setupEssentials(int& argc, char** argv, bool runningMarkerExisted) {
|
|||
DependencyManager::set<AccountManager>(std::bind(&Application::getUserAgent, qApp));
|
||||
#endif
|
||||
DependencyManager::set<StatTracker>();
|
||||
DependencyManager::set<ScriptEngines>(ScriptEngine::CLIENT_SCRIPT);
|
||||
DependencyManager::set<ScriptEngines>(ScriptEngine::CLIENT_SCRIPT, defaultScriptsOverrideOption);
|
||||
DependencyManager::set<ScriptInitializerMixin, NativeScriptInitializers>();
|
||||
DependencyManager::set<Preferences>();
|
||||
DependencyManager::set<recording::Deck>();
|
||||
|
|
|
@ -86,6 +86,7 @@ int main(int argc, const char* argv[]) {
|
|||
QCommandLineOption responseTokensOption("tokens", "set response tokens <json>", "json");
|
||||
QCommandLineOption displayNameOption("displayName", "set user display name <string>", "string");
|
||||
QCommandLineOption setBookmarkOption("setBookmark", "set bookmark key=value pair", "string");
|
||||
QCommandLineOption defaultScriptOverrideOption("defaultScriptsOverride", "override defaultsScripts.js", "string");
|
||||
|
||||
parser.addOption(urlOption);
|
||||
parser.addOption(noLauncherOption);
|
||||
|
@ -99,6 +100,7 @@ int main(int argc, const char* argv[]) {
|
|||
parser.addOption(responseTokensOption);
|
||||
parser.addOption(displayNameOption);
|
||||
parser.addOption(setBookmarkOption);
|
||||
parser.addOption(defaultScriptOverrideOption);
|
||||
|
||||
if (!parser.parse(arguments)) {
|
||||
std::cout << parser.errorText().toStdString() << std::endl; // Avoid Qt log spam
|
||||
|
|
|
@ -29,6 +29,7 @@ static const QString DESKTOP_LOCATION = QStandardPaths::writableLocation(QStanda
|
|||
static const bool HIFI_SCRIPT_DEBUGGABLES { true };
|
||||
static const QString SETTINGS_KEY { "RunningScripts" };
|
||||
static const QUrl DEFAULT_SCRIPTS_LOCATION { "file:///~//defaultScripts.js" };
|
||||
|
||||
// Using a QVariantList so this is human-readable in the settings file
|
||||
static Setting::Handle<QVariantList> runningScriptsHandle(SETTINGS_KEY, { QVariant(DEFAULT_SCRIPTS_LOCATION) });
|
||||
|
||||
|
@ -64,8 +65,8 @@ void ScriptEngines::onErrorLoadingScript(const QString& url) {
|
|||
emit errorLoadingScript(url);
|
||||
}
|
||||
|
||||
ScriptEngines::ScriptEngines(ScriptEngine::Context context)
|
||||
: _context(context)
|
||||
ScriptEngines::ScriptEngines(ScriptEngine::Context context, const QUrl& defaultScriptsOverride)
|
||||
: _context(context), _defaultScriptsOverride(defaultScriptsOverride)
|
||||
{
|
||||
_scriptsModelFilter.setSourceModel(&_scriptsModel);
|
||||
_scriptsModelFilter.sort(0, Qt::AscendingOrder);
|
||||
|
@ -322,13 +323,22 @@ void ScriptEngines::loadScripts() {
|
|||
|
||||
// loads all saved scripts
|
||||
auto runningScripts = runningScriptsHandle.get();
|
||||
bool defaultScriptsOverrideSet = !_defaultScriptsOverride.isEmpty();
|
||||
|
||||
for (auto script : runningScripts) {
|
||||
auto string = script.toString();
|
||||
if (!string.isEmpty()) {
|
||||
loadScript(string);
|
||||
auto url = script.toUrl();
|
||||
if (!url.isEmpty()) {
|
||||
if (defaultScriptsOverrideSet && url == DEFAULT_SCRIPTS_LOCATION) {
|
||||
_defaultScriptsWasRunning = true;
|
||||
} else {
|
||||
loadScript(url);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (defaultScriptsOverrideSet) {
|
||||
loadScript(_defaultScriptsOverride, false);
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptEngines::saveScripts() {
|
||||
|
@ -359,6 +369,10 @@ void ScriptEngines::saveScripts() {
|
|||
}
|
||||
}
|
||||
|
||||
if (_defaultScriptsWasRunning) {
|
||||
list.append(DEFAULT_SCRIPTS_LOCATION);
|
||||
}
|
||||
|
||||
runningScriptsHandle.set(list);
|
||||
}
|
||||
|
||||
|
|
|
@ -56,7 +56,7 @@ class ScriptEngines : public QObject, public Dependency {
|
|||
public:
|
||||
using ScriptInitializer = ScriptInitializerMixin::ScriptInitializer;
|
||||
|
||||
ScriptEngines(ScriptEngine::Context context);
|
||||
ScriptEngines(ScriptEngine::Context context, const QUrl& defaultScriptsOverride = QUrl());
|
||||
void registerScriptInitializer(ScriptInitializer initializer);
|
||||
int runScriptInitializers(ScriptEnginePointer engine);
|
||||
void loadScripts();
|
||||
|
@ -284,6 +284,12 @@ protected:
|
|||
std::atomic<bool> _isReloading { false };
|
||||
bool _defaultScriptsLocationOverridden { false };
|
||||
QString _debugScriptUrl;
|
||||
|
||||
// If this is set, defaultScripts.js will not be run if it is in the settings,
|
||||
// and this will be run instead. This script will not be persisted to settings.
|
||||
const QUrl _defaultScriptsOverride { };
|
||||
// If an override is set, this will be true if defaultScripts.js was previously running.
|
||||
bool _defaultScriptsWasRunning { false };
|
||||
};
|
||||
|
||||
QUrl normalizeScriptURL(const QUrl& rawScriptURL);
|
||||
|
|
Loading…
Reference in a new issue