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>
30 QOhosJsState &jsState, std::function<QNapi::Value(QOhosJsState &, T)> promiseValueFactory,
38 QOhosJsState &jsState,
std::function<
void(
const QOhosCallbackInfo &)> timeoutFunc,
39 std::chrono::milliseconds delay);
56 const Napi::Error &error,
const std::vector<std::uint32_t> &suppressedErrorCodes,
57 const char *callerContextName);
62 QOhosJsState &,
const std::vector<std::uint32_t> &suppressedErrorCodes,
63 const char *callerContextName,
const std::function<
void()> &action);
67 QOhosJsState &jsState, std::function<QNapi::Value(QOhosJsState &, T)> promiseValueFactory,
70 auto promiseDeferred = QNapi::Promise::Deferred::New(jsState.env());
74 makeCallOnceConsumerWrapper<QOhosJsState &, T>(
75 [promiseDeferred, promiseValueFactory = std::move(promiseValueFactory)](QOhosJsState &jsState, T result) {
76 promiseDeferred.Resolve(promiseValueFactory(jsState, result));
79 return promiseDeferred.Promise();
85 auto optPropValue = QNapi::getOptionalPropOrEmpty<T>(object, propName);
86 return !optPropValue.IsEmpty()
87 ?
std::optional(optPropValue)
91template<
typename ConfigValue>
93 std::function<ConfigValue(QOhosJsState &)> initValueSupplier,
94 std::function<ConfigValue(QOhosJsState &,
const QNapi::Object &)> valueFetcher,
95 QOhosConsumer<ConfigValue> valueChangedHandler)
97 return makeQOhosDataSource<ConfigValue>(
98 std::move(initValueSupplier),
99 [valueFetcher = std::move(valueFetcher)](QOhosJsState &jsState, QOhosConsumer<ConfigValue> valueUpdatesConsumer)
mutable {
100 return registerOhosAppContextEnvironmentCallback(
104 "onConfigurationUpdated",
105 [valueFetcher = std::move(valueFetcher), valueUpdatesConsumer = std::move(valueUpdatesConsumer)](
const QOhosCallbackInfo &cbInfo) {
106 auto config = cbInfo.getFirstArg<QNapi::Object>(Q_FUNC_INFO);
107 valueUpdatesConsumer(valueFetcher(cbInfo.jsState(), config));
112 std::move(valueChangedHandler),
113 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.
void rethrowUnlessJsBusinessErrorIsOneOf(const Napi::Error &error, const std::vector< std::uint32_t > &suppressedErrorCodes, const char *callerContextName)
std::optional< std::uint32_t > tryGetCodeFromJsBusinessError(const Napi::Error &error)
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)
int setJsTimeout(QOhosJsState &jsState, std::function< void(const QOhosCallbackInfo &)> timeoutFunc, std::chrono::milliseconds delay)
bool runIgnoringJsBusinessError(QOhosJsState &, const std::vector< std::uint32_t > &suppressedErrorCodes, const char *callerContextName, const std::function< void()> &action)
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