Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qohosjsenv_p.h
Go to the documentation of this file.
1// Copyright (C) 2025 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QOHOSJSENV_H
5#define QOHOSJSENV_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtCore/private/qnapi_p.h>
19#include <QtCore/private/qohoslogger_p.h>
20#include <QtCore/qjsonarray.h>
21#include <QtCore/qjsonobject.h>
22#include <QtCore/qjsonvalue.h>
23#include <QtCore/qstring.h>
24
25#include <algorithm>
26#include <array>
27#include <cstdint>
28#include <iterator>
29#include <limits>
30#include <type_traits>
31#include <memory>
32#include <napi/native_api.h>
33#include <napi.h>
34#include <utility>
35
36QT_BEGIN_NAMESPACE
37
39
41{
42 template <typename T, typename Enable = void>
43 struct QNapiValue {
44 static QNapi::Value create(napi_env /*env*/, T /*value*/) {
45 static_assert(sizeof(T) == 0, "Unsupported type - provide proper QOhosJsEnv::QNapiValue"
46 " overload");
47 }
48 static Napi::Maybe<T> get(const QNapi::Value &/*value*/) {
49 static_assert(sizeof(T) == 0, "Unsupported type - provide proper QOhosJsEnv::QNapiValue"
50 " overload");
51 }
52 };
53
54 template <typename T>
55 static QNapi::Value toNapiValue(napi_env env, T &&value) {
56 return QNapiValue<typename std::decay<T>::type>::create(env, std::forward<T>(value));
57 }
58
59 template<typename ReturnType>
60 static ReturnType fromNapiValue(const QNapi::Value &value)
61 {
62 return QNapiValue<typename std::decay<ReturnType>::type>::get(value).UnwrapOr(ReturnType());
63 }
64};
65
66//
67// overloads of QNapiValue to support various types
68//
69
70template<>
76
77template<>
83
84template<>
90
91template<>
97
99{
101 env,
102 [&]() {
104 for (int i = 0; i < inputValue.length(); ++i)
106 return outputArray;
107 });
108}
109
136
138{
139 switch (inputValue.type()) {
140 case QJsonValue::Type::Array:
142 case QJsonValue::Type::Bool:
143 return QNapi::Boolean::New(env, inputValue.toBool());
144 case QJsonValue::Type::Double:
145 return QNapi::Number::New(env, inputValue.toDouble());
146 case QJsonValue::Type::Null:
148 return Napi::Env(env).Null();
149 case QJsonValue::Type::Object:
151 case QJsonValue::Type::String:
153 }
154
155 throw Napi::Error::New(env, "Got unsupported (impossible) QJsonValue");
156}
157
159{
160 if (inputValue.IsArray()) {
163 } else if (inputValue.IsBoolean()) {
165 return Napi::Just(QJsonValue(boolValue));
166 } else if (inputValue.IsNumber()) {
169 } else if (inputValue.IsObject()) {
172 } else if (inputValue.IsString()) {
175 } else {
176 return Napi::Nothing<QJsonValue>();
177 }
178}
179
187
189{
190 const auto transform = [](const QList<QJsonValue> &input) -> QJsonArray {
193 return result;
194 };
195
197 return listValue.IsJust()
199 : Napi::Nothing<QJsonArray>();
200}
201
216
218{
219 if (!inputValue.IsObject())
220 return Napi::Nothing<QJsonObject>();
221
223
225 bool allElementsSet = true;
226
227 for (const auto &inputElement : inputObject) {
230
232 if (optPropValue.IsNothing()) {
233 allElementsSet = false;
234 break;
235 }
236
238 }
239 }
240
241 return allElementsSet
242 ? Napi::Just(result)
244}
245
246}
247
248QT_END_NAMESPACE
249
250#endif // QOHOSJSENV_H
Combined button and popup list for selecting options.
std::shared_ptr< OperationStatus > startAbility(const Want &want, std::shared_ptr< StartOptions > options)
Starts an Ability for a given want and options; pass a null options to start without any start option...
void startNewAbilityInstance(QWidget *instanceWidget)
Starts another instance of the UIAbility used by the Qt app with specified widget inside.
void setAbilityInstanceDestroyEnabled(QWindow *instanceWindow, bool destroyEnabled)
Sets whether the Ability related with instanceWindow can be automatically destroyed by the system whe...
std::shared_ptr< OperationStatus > startAbilityByType(const QString &appType, const QJsonObject &wantParameters)
Starts an Ability for a given appType and wantParameters.
void startAppProcess(const QString &processId, const Want &requestWant, std::shared_ptr< StartOptions > options)
Starts application process for a given processId, requestWant and options; pass a null options to sta...
std::optional< QByteArray > tryGetOnContinueData(const Want &want)
Tries to get continuation / migration related data that was provided on the source device.
std::shared_ptr< OpenLinkOptions > createOpenLinkOptions()
static Napi::Maybe< T > get(const QNapi::Value &)
static QNapi::Value create(napi_env, T)
static QNapi::Value toNapiValue(napi_env env, T &&value)
static ReturnType fromNapiValue(const QNapi::Value &value)
enums::kit::ShareKit::systemShare::SelectionMode Enum
static constexpr std::array< std::pair< Enum, const char * >, 2 > enumeratorsNames
static constexpr std::array< std::pair< Enum, const char * >, 5 > enumeratorsNames
enums::kit::ShareKit::systemShare::ShareAbilityType Enum
enums::kit::ShareKit::systemShare::SharePreviewMode Enum
static constexpr std::array< std::pair< Enum, const char * >, 2 > enumeratorsNames
static constexpr std::array< std::pair< Enum, const char * >, 2 > enumeratorsNames
enums::ohos::app::ability::AbilityConstant::ContinueState Enum
static constexpr std::array< std::pair< Enum, const char * >, 10 > enumeratorsNames
enums::ohos::app::ability::AbilityConstant::LaunchReason Enum
static constexpr std::array< std::pair< Enum, const char * >, 3 > enumeratorsNames
enums::ohos::app::ability::AbilityConstant::OnContinueResult Enum
static constexpr std::array< std::pair< Enum, const char * >, 3 > enumeratorsNames
enums::ohos::app::ability::AbilityConstant::WindowMode Enum
static constexpr std::array< std::pair< Enum, const char * >, 3 > enumeratorsNames
enums::ohos::app::ability::ConfigurationConstant::ColorMode Enum
static constexpr std::array< std::pair< Enum, const char * >, 3 > enumeratorsNames
enums::ohos::app::ability::contextConstant::ProcessMode Enum
enums::ohos::app::ability::contextConstant::StartupVisibility Enum
static constexpr std::array< std::pair< Enum, const char * >, 2 > enumeratorsNames
static constexpr std::array< std::pair< Enum, const char * >, 3 > enumeratorsNames
enums::ohos::bundle::bundleManager::SupportWindowMode Enum
static constexpr std::array< std::pair< Enum, const char * >, 1 > enumeratorsNames