Loading...
Searching...
No Matches
score-plugin-js/JS/ApplicationPlugin.hpp
1#pragma once
2#include <score/plugins/application/GUIApplicationPlugin.hpp>
3
4#include <score_plugin_js_export.h>
5
6#include <core/application/ApplicationSettings.hpp>
7
8#include <QFileInfo>
9#include <QHash>
10#include <QJSValue>
11#include <QPointer>
12#include <QQmlComponent>
13#include <QQmlContext>
14#include <QQmlEngine>
15#include <QSet>
16
17#include <thread>
18#include <vector>
19
20namespace ossia::net
21{
22struct network_context;
23using network_context_ptr = std::shared_ptr<network_context>;
24}
25class QQuickWindow;
26namespace JS
27{
28// Exported like the other plugins' ApplicationPlugin: guiApplicationPlugin<T>()
29// dynamic_casts across the plugin boundary and needs the typeinfo visible.
30class SCORE_PLUGIN_JS_EXPORT ApplicationPlugin final
31 : public QObject
33{
34public:
36
37 void on_createdDocument(score::Document& doc) override;
38
39 ~ApplicationPlugin() override;
40 void initialize() override;
41 void afterStartup() override;
42 void runStartScripts();
43 void on_newDocument(score::Document& doc) override;
44
58 static QJSValue importModule(QQmlEngine& engine, const QString& path);
59
69 void registerCommandHandler(const QString& name, const QJSValue& fn, QJSEngine* engine);
70 void callCommandHandler(const QString& name, const QByteArray& payload);
71
72 // Used for processing whatever comes from the console
73 QQmlEngine m_consoleEngine;
74
75 // Used for instantiating JS::Script* to verify that the script is valid
76 // before updating, as well as for running JS UI scripts.
77 QQmlEngine m_scriptProcessUIEngine;
78 QQmlComponent* m_comp{};
79 QQuickWindow* m_window{};
80
81 std::atomic_bool m_processMessages{};
82 std::thread m_asioThread;
83 ossia::net::network_context_ptr m_asioContext;
84
87 {
88 QString source;
89 QString name;
90 QString file;
91 QString dir;
92 bool module{};
93 };
94
97 std::vector<StartScript> m_start_scripts;
98 bool m_start_script_failed{};
99
101 {
102 QJSValue fn;
103 QPointer<QJSEngine> engine;
104 };
105 QHash<QString, CommandHandler> m_commandHandlers;
106 QSet<QString> m_reportedMissingHandlers;
107};
108}
Definition score-plugin-js/JS/ApplicationPlugin.hpp:33
std::vector< StartScript > m_start_scripts
Definition score-plugin-js/JS/ApplicationPlugin.hpp:97
The Document class is the central part of the software.
Definition Document.hpp:51
Used to extend the software with application-wide data.
Definition GUIApplicationPlugin.hpp:97
Definition score-plugin-js/JS/ApplicationPlugin.hpp:101
One –script argument.
Definition score-plugin-js/JS/ApplicationPlugin.hpp:87
QString source
inline source or file contents; empty for a module
Definition score-plugin-js/JS/ApplicationPlugin.hpp:88
QString name
path as given, for diagnostics; empty when inline
Definition score-plugin-js/JS/ApplicationPlugin.hpp:89
QString dir
the script's folder, added as a QML import path
Definition score-plugin-js/JS/ApplicationPlugin.hpp:91
QString file
canonical path, what importModule() is given
Definition score-plugin-js/JS/ApplicationPlugin.hpp:90
Specializes ApplicationContext with the QMainWindow.
Definition GUIApplicationContext.hpp:15