Line data Source code
1 : /*
2 : * SPDX-License-Identifier: GPL-3.0-only
3 : * MuseScore-CLA-applies
4 : *
5 : * MuseScore Studio
6 : * Music Composition & Notation
7 : *
8 : * Copyright (C) 2024 MuseScore Limited and others
9 : *
10 : * This program is free software: you can redistribute it and/or modify
11 : * it under the terms of the GNU General Public License version 3 as
12 : * published by the Free Software Foundation.
13 : *
14 : * This program is distributed in the hope that it will be useful,
15 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 : * GNU General Public License for more details.
18 : *
19 : * You should have received a copy of the GNU General Public License
20 : * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 : */
22 : #ifndef MUSE_EXTENSIONS_API_EXTAPI_H
23 : #define MUSE_EXTENSIONS_API_EXTAPI_H
24 :
25 : #include <QObject>
26 : #include <QMap>
27 :
28 : #include "modularity/ioc.h"
29 : #include "api/iapiregister.h"
30 : #include "api/iapiengine.h"
31 :
32 : namespace muse::extensions::api {
33 : //! NOTE Used for qml and scripts
34 : class ExtApi : public QObject, public Contextable
35 : {
36 : Q_OBJECT
37 : Q_PROPERTY(QJSValue log READ log CONSTANT)
38 : Q_PROPERTY(QJSValue interactive READ interactive CONSTANT)
39 : Q_PROPERTY(QJSValue theme READ theme CONSTANT)
40 :
41 : Q_PROPERTY(QJSValue engraving READ engraving CONSTANT)
42 :
43 : Q_PROPERTY(QJSValue converter READ converter CONSTANT)
44 :
45 : //! NOTE Providing these APIs requires approval
46 : //Q_PROPERTY(QJSValue shortcuts READ shortcuts CONSTANT)
47 : //Q_PROPERTY(QJSValue navigation READ navigation CONSTANT)
48 : //Q_PROPERTY(QJSValue keyboard READ keyboard CONSTANT)
49 : //Q_PROPERTY(QJSValue accessibility READ accessibility CONSTANT)
50 :
51 : //! ATTENTION
52 : //! Don't add these APIs here.
53 : //! We do not control the authors of extensions;
54 : //! using these APIs they can deliberately or accidentally harm the user's system.
55 : //Q_PROPERTY(QJSValue process READ process CONSTANT)
56 : //Q_PROPERTY(QJSValue filesystem READ filesystem CONSTANT)
57 :
58 : Q_PROPERTY(QJSValue websocket READ websocket CONSTANT)
59 : Q_PROPERTY(QJSValue websocketserver READ websocketserver CONSTANT)
60 :
61 : GlobalInject<muse::api::IApiRegister> apiRegister;
62 :
63 : public:
64 : ExtApi(muse::api::IApiEngine* engine, QObject* parent);
65 : ~ExtApi();
66 :
67 0 : QJSValue log() const { return api("MuseApi.Log"); }
68 0 : QJSValue interactive() const { return api("MuseApi.Interactive"); }
69 0 : QJSValue theme() const { return api("MuseApi.Theme"); }
70 :
71 0 : QJSValue engraving() const { return api("MuseApi.Engraving"); }
72 :
73 0 : QJSValue converter() const { return api("MuseApi.Converter"); }
74 :
75 : QJSValue dispatcher() const { return api("MuseInternal.Dispatcher"); }
76 : QJSValue navigation() const { return api("MuseInternal.Navigation"); }
77 : QJSValue shortcuts() const { return api("MuseInternal.Shortcuts"); }
78 : QJSValue keyboard() const { return api("MuseInternal.Keyboard"); }
79 : QJSValue accessibility() const { return api("MuseInternal.Accessibility"); }
80 :
81 0 : QJSValue websocket() const { return api("MuseApi.Websocket"); }
82 0 : QJSValue websocketserver() const { return api("MuseApi.WebsocketServer"); }
83 :
84 : private:
85 : QJSValue api(const std::string& name) const;
86 :
87 : struct Api
88 : {
89 : muse::api::ApiObject* obj = nullptr;
90 : bool isNeedDelete = false;
91 : QJSValue jsval;
92 : };
93 :
94 : muse::api::IApiEngine* m_engine = nullptr;
95 : mutable QMap<std::string, Api> m_apis;
96 : };
97 : }
98 :
99 : #endif // MUSE_EXTENSIONS_API_EXTAPI_H
|