Showing the changes to libraries/script-engine/src/ScriptEngines.cpp (1 of 4 files). Show all
Unified · Split
| @@ -16,6 +16,8 @@ · 15 unmodified lines | ||
| 16 | 16 | #include <UserActivityLogger.h> |
| 17 | 17 | #include <PathUtils.h> |
| 18 | 18 | |
| 19 | +#include <OffscreenUi.h> | |
| 20 | + | |
| 19 | 21 | #include "ScriptEngine.h" |
| 20 | 22 | #include "ScriptEngineLogging.h" |
| 21 | 23 | |
| @@ -367,28 +369,21 @@ QStringList ScriptEngines::getRunningScripts() { · 345 unmodified lines | ||
| 367 | 369 | |
| 368 | 370 | void ScriptEngines::stopAllScripts(bool restart) { |
| 369 | 371 | QReadLocker lock(&_scriptEnginesHashLock); |
| 370 | − if (restart) { | |
| 371 | − // Delete all running scripts from cache so that they are re-downloaded when they are restarted | |
| 372 | − auto scriptCache = DependencyManager::get<ScriptCache>(); | |
| 373 | − for (QHash<QUrl, ScriptEngine*>::const_iterator it = _scriptEnginesHash.constBegin(); | |
| 374 | − it != _scriptEnginesHash.constEnd(); it++) { | |
| 375 | − if (!it.value()->isFinished()) { | |
| 376 | − scriptCache->deleteScript(it.key()); | |
| 377 | − } | |
| 378 | − } | |
| 379 | − } | |
| 380 | − | |
| 381 | − // Stop and possibly restart all currently running scripts | |
| 382 | 372 | for (QHash<QUrl, ScriptEngine*>::const_iterator it = _scriptEnginesHash.constBegin(); |
| 383 | 373 | it != _scriptEnginesHash.constEnd(); it++) { |
| 374 | + // skip already stopped scripts | |
| 384 | 375 | if (it.value()->isFinished() || it.value()->isStopping()) { |
| 385 | 376 | continue; |
| 386 | 377 | } |
| 378 | + | |
| 379 | + // queue user scripts if restarting | |
| 387 | 380 | if (restart && it.value()->isUserLoaded()) { |
| 388 | 381 | connect(it.value(), &ScriptEngine::finished, this, [this](QString scriptName, ScriptEngine* engine) { |
| 389 | 382 | reloadScript(scriptName); |
| 390 | 383 | }); |
| 391 | 384 | } |
| 385 | + | |
| 386 | + // stop all scripts | |
| 392 | 387 | it.value()->stop(true); |
| 393 | 388 | qCDebug(scriptengine) << "stopping script..." << it.key(); |
| 394 | 389 | } |
| @@ -431,6 +426,7 @@ void ScriptEngines::setScriptsLocation(const QString& scriptsLocation) { · 36 unmodified lines | ||
| 431 | 426 | |
| 432 | 427 | void ScriptEngines::reloadAllScripts() { |
| 433 | 428 | DependencyManager::get<ScriptCache>()->clearCache(); |
| 429 | + DependencyManager::get<OffscreenUi>()->clearCache(); | |
| 434 | 430 | emit scriptsReloading(); |
| 435 | 431 | stopAllScripts(true); |
| 436 | 432 | } |