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 | #include <UserActivityLogger.h> | 16 | #include <UserActivityLogger.h> |
| 17 | #include <PathUtils.h> | 17 | #include <PathUtils.h> |
| 18 | 18 | ||
| 19 | #include <OffscreenUi.h> | ||
| 20 | |||
| 19 | #include "ScriptEngine.h" | 21 | #include "ScriptEngine.h" |
| 20 | #include "ScriptEngineLogging.h" | 22 | #include "ScriptEngineLogging.h" |
| 21 | 23 | ||
| @@ -367,28 +369,21 @@ QStringList ScriptEngines::getRunningScripts() { · 345 unmodified lines | |||
| 367 | 369 | ||
| 368 | void ScriptEngines::stopAllScripts(bool restart) { | 370 | void ScriptEngines::stopAllScripts(bool restart) { |
| 369 | QReadLocker lock(&_scriptEnginesHashLock); | 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 | for (QHash<QUrl, ScriptEngine*>::const_iterator it = _scriptEnginesHash.constBegin(); | 372 | for (QHash<QUrl, ScriptEngine*>::const_iterator it = _scriptEnginesHash.constBegin(); |
| 383 | it != _scriptEnginesHash.constEnd(); it++) { | 373 | it != _scriptEnginesHash.constEnd(); it++) { |
| 374 | // skip already stopped scripts | ||
| 384 | if (it.value()->isFinished() || it.value()->isStopping()) { | 375 | if (it.value()->isFinished() || it.value()->isStopping()) { |
| 385 | continue; | 376 | continue; |
| 386 | } | 377 | } |
| 378 | |||
| 379 | // queue user scripts if restarting | ||
| 387 | if (restart && it.value()->isUserLoaded()) { | 380 | if (restart && it.value()->isUserLoaded()) { |
| 388 | connect(it.value(), &ScriptEngine::finished, this, [this](QString scriptName, ScriptEngine* engine) { | 381 | connect(it.value(), &ScriptEngine::finished, this, [this](QString scriptName, ScriptEngine* engine) { |
| 389 | reloadScript(scriptName); | 382 | reloadScript(scriptName); |
| 390 | }); | 383 | }); |
| 391 | } | 384 | } |
| 385 | |||
| 386 | // stop all scripts | ||
| 392 | it.value()->stop(true); | 387 | it.value()->stop(true); |
| 393 | qCDebug(scriptengine) << "stopping script..." << it.key(); | 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 | void ScriptEngines::reloadAllScripts() { | 427 | void ScriptEngines::reloadAllScripts() { |
| 433 | DependencyManager::get<ScriptCache>()->clearCache(); | 428 | DependencyManager::get<ScriptCache>()->clearCache(); |
| 429 | DependencyManager::get<OffscreenUi>()->clearCache(); | ||
| 434 | emit scriptsReloading(); | 430 | emit scriptsReloading(); |
| 435 | stopAllScripts(true); | 431 | stopAllScripts(true); |
| 436 | } | 432 | } |