7#include <QtCore/private/qcore_ohos_p.h>
8#include <QtCore/private/qnapi_p.h>
9#include <QtCore/private/qohoscommon_p.h>
10#include <QtCore/private/qohosjstools_p.h>
11#include <QtCore/qglobal.h>
17#include <qohosutils.h>
29 QOhosJsState &jsState, std::function<QNapi::Value(QOhosJsState &, T)> promiseValueFactory,
37 QOhosJsState &jsState,
std::function<
void(
const QOhosCallbackInfo &)> timeoutFunc,
38 std::chrono::milliseconds delay);
55 const Napi::Error &error,
std::uint32_t suppressedErrorCode,
const char *callerContextName);
60 QOhosJsState &,
std::uint32_t suppressedErrorCode,
const char *callerContextName,
61 const std::function<
void()> &action);
65 QOhosJsState &jsState, std::function<QNapi::Value(QOhosJsState &, T)> promiseValueFactory,
68 auto promiseDeferred = QNapi::Promise::Deferred::New(jsState.env());
72 makeCallOnceConsumerWrapper<QOhosJsState &, T>(
73 [promiseDeferred, promiseValueFactory = std::move(promiseValueFactory)](QOhosJsState &jsState, T result) {
74 promiseDeferred.Resolve(promiseValueFactory(jsState, result));
77 return promiseDeferred.Promise();
83 auto optPropValue = QNapi::getOptionalPropOrEmpty<T>(object, propName);
84 return !optPropValue.IsEmpty()
85 ?
std::optional(optPropValue)
89template<
typename ConfigValue>
91 std::function<ConfigValue(QOhosJsState &)> initValueSupplier,
92 std::function<ConfigValue(QOhosJsState &,
const QNapi::Object &)> valueFetcher,
93 QOhosConsumer<ConfigValue> valueChangedHandler)
95 return makeQOhosDataSource<ConfigValue>(
96 std::move(initValueSupplier),
97 [valueFetcher = std::move(valueFetcher)](QOhosJsState &jsState, QOhosConsumer<ConfigValue> valueUpdatesConsumer)
mutable {
98 return registerOhosAppContextEnvironmentCallback(
102 "onConfigurationUpdated",
103 [valueFetcher = std::move(valueFetcher), valueUpdatesConsumer = std::move(valueUpdatesConsumer)](
const QOhosCallbackInfo &cbInfo) {
104 auto config = cbInfo.getFirstArg<QNapi::Object>(Q_FUNC_INFO);
105 valueUpdatesConsumer(valueFetcher(cbInfo.jsState(), config));
110 std::move(valueChangedHandler),
111 QtOhos::invokeInQtThread,
std::vector< QOhosDisplayInfo > getRegisteredDisplayInfos()
static std::shared_ptr< QOhosDisplayManager > create(QOhosJsState &jsState, CreateInfo createInfo)
QOhosDisplayInfo::JsDisplayId JsDisplayId
QPoint mapFromDisplayToGlobal(const QPoint &displayOffset, QOhosDisplayInfo::JsDisplayId jsDisplayId)
Combined button and popup list for selecting options.
std::optional< std::uint32_t > tryGetCodeFromJsBusinessError(const Napi::Error &error)
bool runIgnoringJsBusinessError(QOhosJsState &, std::uint32_t suppressedErrorCode, const char *callerContextName, const std::function< void()> &action)
QNapi::Promise adaptAsyncCallResultToJsPromise(QOhosJsState &jsState, std::function< QNapi::Value(QOhosJsState &, T)> promiseValueFactory, const QOhosConsumer< QOhosJsState &, QOhosConsumer< QOhosJsState &, T > > &asyncCallFunc)
std::optional< T > getOptionalProperty(const QNapi::Object &object, const std::string &propName)
QNapi::Promise makeResolvedPromise(QNapi::Value valueForResolve)
void rethrowUnlessJsBusinessErrorIs(const Napi::Error &error, std::uint32_t suppressedErrorCode, const char *callerContextName)
int setJsTimeout(QOhosJsState &jsState, std::function< void(const QOhosCallbackInfo &)> timeoutFunc, std::chrono::milliseconds delay)
QOhosSupplier< ConfigValue > makeOhosConfigValueDataSource(std::function< ConfigValue(QOhosJsState &)> initValueSupplier, std::function< ConfigValue(QOhosJsState &, const QNapi::Object &)> valueFetcher, QOhosConsumer< ConfigValue > valueChangedHandler)
void clearJsTimeout(QOhosJsState &jsState, int timerId)
QOhosConsumer< QOhosJsState &, JsDisplayId, QRectF > displayAvailableAreaChangedCb