Line data Source code
1 : /*
2 : * SPDX-License-Identifier: GPL-3.0-only
3 : * MuseScore/Audacity CLA applies
4 : *
5 : * Copyright (C) MuseScore/Audacity and others
6 : *
7 : * This program is free software: you can redistribute it and/or modify
8 : * it under the terms of the GNU General Public License version 3 as
9 : * published by the Free Software Foundation.
10 : *
11 : * This program is distributed in the hope that it will be useful,
12 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 : * GNU General Public License for more details.
15 : *
16 : * You should have received a copy of the GNU General Public License
17 : * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 : */
19 : #include "extensionsession.h"
20 :
21 : #include "extensions/extensionstypes.h"
22 :
23 : using namespace muse;
24 : using namespace muse::extensions;
25 :
26 0 : ExtensionSession::ExtensionSession(const modularity::ContextPtr& iocContext, const Manifest& manifest, const io::path_t& scriptPath)
27 0 : : m_engine(iocContext, muse::api::ApiContext {
28 0 : manifest.apiversion,
29 0 : io::dirpath(manifest.path),
30 0 : manifest.uri.toString() })
31 : {
32 0 : m_engine.setScriptPath(scriptPath);
33 :
34 : static int index = 0;
35 0 : m_fsKey = std::to_string(index++) + "_" + manifest.uri.toString();
36 :
37 0 : fsRestriction()->addAllowedPathBase(m_fsKey, io::dirpath(manifest.path));
38 0 : }
39 :
40 0 : ExtensionSession::~ExtensionSession()
41 : {
42 0 : fsRestriction()->removeAllowedPathBase(m_fsKey);
43 0 : }
44 :
45 0 : Ret ExtensionSession::evaluate()
46 : {
47 0 : return m_engine.evaluate();
48 : }
49 :
50 0 : Ret ExtensionSession::call(const QString& function, const QJSValueList& arguments, QJSValue* result)
51 : {
52 0 : return m_engine.call(function, arguments, result);
53 : }
54 :
55 0 : QJSValue ExtensionSession::exports() const
56 : {
57 0 : return m_engine.exports();
58 : }
59 :
60 0 : QJSValue ExtensionSession::toScriptValue(const QVariant& value)
61 : {
62 0 : return m_engine.jsEngine()->toScriptValue(value);
63 : }
64 :
65 0 : QJSValue ExtensionSession::wrapQObject(QObject* object)
66 : {
67 0 : QJSEngine::setObjectOwnership(object, QJSEngine::CppOwnership);
68 0 : return m_engine.jsEngine()->newQObject(object);
69 : }
|