Phosphor
Qt6 / Wayland library suite for window-management tools
 
Loading...
Searching...
No Matches
ScriptedAlgorithmLoader.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 fuddlesworth
2// SPDX-License-Identifier: LGPL-2.1-or-later
3
4#pragma once
5
6#include <phosphortiles_export.h>
8#include <QByteArray>
9#include <QHash>
10#include <QObject>
11#include <QString>
12
13#include <memory>
14
15namespace PhosphorTiles {
16
17class ITileAlgorithmRegistry;
18class ScriptedAlgorithmWatchdog;
19
37class PHOSPHORTILES_EXPORT ScriptedAlgorithmLoader : public QObject
38{
39 Q_OBJECT
40
41public:
53 explicit ScriptedAlgorithmLoader(const QString& subdirectory, ITileAlgorithmRegistry* registry,
54 QObject* parent = nullptr);
56
81
86
93 QString userAlgorithmDir() const;
94
95Q_SIGNALS:
100
101private:
102 class JsScanStrategy;
103 QStringList performScan(const QStringList& directoriesInScanOrder);
104
105 void loadFromDirectory(const QString& dir, bool isUserDir, const QString& canonicalUserDir);
106 QStringList algorithmDirectories() const;
107 QStringList validatedJsFiles(const QString& dirPath, int maxFiles) const;
108
109 QString m_subdirectory;
110 ITileAlgorithmRegistry* m_registry = nullptr;
121 std::shared_ptr<ScriptedAlgorithmWatchdog> m_watchdog;
122 std::unique_ptr<JsScanStrategy> m_strategy;
123 std::unique_ptr<PhosphorFsLoader::WatchedDirectorySet> m_watcher;
124 QHash<QString, QString> m_scriptIdToPath;
131 QByteArray m_lastScriptSignature;
132};
133
134} // namespace PhosphorTiles
Abstract contract for a tiling-algorithm registry.
Definition ITileAlgorithmRegistry.h:41
Discovers, loads, and hot-reloads ScriptedAlgorithm instances.
Definition ScriptedAlgorithmLoader.h:38
void ensureUserDirectoryExists()
Create the user algorithm directory if it does not exist.
QString userAlgorithmDir() const
Writable user directory path for custom algorithms.
void algorithmsChanged()
Emitted after any add/remove/reload of scripted algorithms.
void scanAndRegister(PhosphorFsLoader::LiveReload liveReload=PhosphorFsLoader::LiveReload::On)
Discover and load all .js algorithms from system + user dirs.
ScriptedAlgorithmLoader(const QString &subdirectory, ITileAlgorithmRegistry *registry, QObject *parent=nullptr)
Construct a loader for subdirectory under XDG data dirs.
LiveReload
Opt-in policy for directory watching.
Definition WatchedDirectorySet.h:34
Definition AutotileEngine.h:71