Discovers, loads, and hot-reloads ScriptedAlgorithm instances. More...
#include <phosphor-tiles/include/PhosphorTiles/ScriptedAlgorithmLoader.h>
Signals | |
| void | algorithmsChanged () |
| Emitted after any add/remove/reload of scripted algorithms. | |
Public Member Functions | |
| ScriptedAlgorithmLoader (const QString &subdirectory, ITileAlgorithmRegistry *registry, QObject *parent=nullptr) | |
Construct a loader for subdirectory under XDG data dirs. | |
| ~ScriptedAlgorithmLoader () override | |
| void | scanAndRegister (PhosphorFsLoader::LiveReload liveReload=PhosphorFsLoader::LiveReload::On) |
| Discover and load all .js algorithms from system + user dirs. | |
| void | ensureUserDirectoryExists () |
| Create the user algorithm directory if it does not exist. | |
| QString | userAlgorithmDir () const |
| Writable user directory path for custom algorithms. | |
Discovers, loads, and hot-reloads ScriptedAlgorithm instances.
Scans system and user algorithm directories for .js files, creates ScriptedAlgorithm instances, and registers them with the injected ITileAlgorithmRegistry. Watches directories and files via QFileSystemWatcher with debounced refresh so that new/modified/ deleted scripts are picked up automatically.
The application injects the subdirectory name (relative to QStandardPaths::GenericDataLocation) at construction — the library is brand-agnostic. For PlasmaZones this is "plasmazones/algorithms".
User scripts under writableLocation/<subdirectory>/ override system scripts with the same filename (system dirs come from every XDG GenericDataLocation entry, in order).
|
explicit |
Construct a loader for subdirectory under XDG data dirs.
subdirectory is a relative path (no leading slash) appended to every QStandardPaths::GenericDataLocation entry. Pass the empty string to disable all discovery (the loader becomes a no-op).
registry is the tile-algorithm registry the loader registers discovered scripts against. Caller owns registry and must keep it alive for the loader's lifetime.
|
override |
|
signal |
Emitted after any add/remove/reload of scripted algorithms.
| void PhosphorTiles::ScriptedAlgorithmLoader::ensureUserDirectoryExists | ( | ) |
Create the user algorithm directory if it does not exist.
| void PhosphorTiles::ScriptedAlgorithmLoader::scanAndRegister | ( | PhosphorFsLoader::LiveReload | liveReload = PhosphorFsLoader::LiveReload::On | ) |
Discover and load all .js algorithms from system + user dirs.
Clears existing scripted algorithms from the registry, then rescans all algorithm directories. System directories are loaded first so that user directories can override by filename.
liveReload defaults to On so production callers (daemon, editor, settings) get hot-reload by default. Pass Off from tests / batch-import contexts that want a one-shot scan with no background watcher attached. The flag is forwarded to the underlying WatchedDirectorySet and inherits its one-way-enable semantics: once any call passes On, the watcher stays armed for the loader's lifetime.
Idempotent on the registry: a re-scan that resolves to an empty directory set still drives the diff path so previously-registered scripts get unregistered as stale.
Change-detection is observable via the algorithmsChanged signal, which fires from inside the strategy when the on-disk script set differs from the previous scan's signature.
| QString PhosphorTiles::ScriptedAlgorithmLoader::userAlgorithmDir | ( | ) | const |
Writable user directory path for custom algorithms.
QStandardPaths::writableLocation(GenericDataLocation), or empty string if the subdirectory was empty.