Showing the changes to libraries/script-engine/src/ScriptEngines.cpp (1 of 3 files). Show all
Unified · Split
| @@ -456,7 +456,7 @@ void ScriptEngines::reloadAllScripts() { · 455 unmodified lines | ||
| 456 | 456 | } |
| 457 | 457 | |
| 458 | 458 | ScriptEnginePointer ScriptEngines::loadScript(const QUrl& scriptFilename, bool isUserLoaded, bool loadScriptFromEditor, |
| 459 | − bool activateMainWindow, bool reload) { | |
| 459 | + bool activateMainWindow, bool reload, bool exitWhenFinished) { | |
| 460 | 460 | if (thread() != QThread::currentThread()) { |
| 461 | 461 | ScriptEnginePointer result { nullptr }; |
| 462 | 462 | BLOCKING_INVOKE_METHOD(this, "loadScript", Q_RETURN_ARG(ScriptEnginePointer, result), |
| @@ -496,6 +496,11 @@ ScriptEnginePointer ScriptEngines::loadScript(const QUrl& scriptFilename, bool i · 33 unmodified lines | ||
| 496 | 496 | connect(scriptEngine.data(), &ScriptEngine::scriptLoaded, this, &ScriptEngines::onScriptEngineLoaded); |
| 497 | 497 | connect(scriptEngine.data(), &ScriptEngine::errorLoadingScript, this, &ScriptEngines::onScriptEngineError); |
| 498 | 498 | |
| 499 | + // Shutdown interface when script finishes, if requested | |
| 500 | + if (exitWhenFinished) { | |
| 501 | + connect(scriptEngine.data(), &ScriptEngine::finished, this, &ScriptEngines::exitWhenFinished); | |
| 502 | + } | |
| 503 | + | |
| 499 | 504 | // get the script engine object to load the script at the designated script URL |
| 500 | 505 | scriptEngine->loadURL(scriptUrl, reload); |
| 501 | 506 | } |
| @@ -536,6 +541,10 @@ void ScriptEngines::onScriptEngineLoaded(const QString& rawScriptURL) { · 34 unmodified lines | ||
| 536 | 541 | emit scriptCountChanged(); |
| 537 | 542 | } |
| 538 | 543 | |
| 544 | +void ScriptEngines::exitWhenFinished() { | |
| 545 | + qApp->quit(); | |
| 546 | +} | |
| 547 | + | |
| 539 | 548 | int ScriptEngines::runScriptInitializers(ScriptEnginePointer scriptEngine) { |
| 540 | 549 | int ii=0; |
| 541 | 550 | for (auto initializer : _scriptInitializers) { |