7#include <QtCore/private/qnapi_p.h>
8#include <QtCore/private/qohoscommon_p.h>
9#include <QtCore/private/qohosjstools_p.h>
10#include <QtCore/qglobal.h>
16#include <qohosplugincore.h>
17#include <qohosutils.h>
29 JsState &jsState, std::function<QNapi::Value(JsState &, T)> promiseValueFactory,
30 const QOhosConsumer<JsState &, QOhosConsumer<JsState &, T>> &asyncCallFunc);
38 std::chrono::milliseconds delay);
52 const Napi::Error &error,
std::uint32_t suppressedErrorCode,
const char *callerContextName);
57 JsState &,
std::uint32_t suppressedErrorCode,
const char *callerContextName,
58 const std::function<
void()> &action);
62 std::function<T(
JsState &)> initialValueReader,
63 std::function<
std::shared_ptr<
void>(
JsState &, QOhosConsumer<T>)> changeListenerFactory,
64 QOhosConsumer<T> valueChangedHandler,
65 QOhosConsumer<std::function<
void()>> targetThreadExecutor,
66 std::string callerContextName = {});
70 JsState &jsState, std::function<QNapi::Value(JsState &, T)> promiseValueFactory,
71 const QOhosConsumer<JsState &, QOhosConsumer<JsState &, T>> &asyncCallFunc)
73 auto promiseDeferred = QNapi::Promise::Deferred::New(jsState.env());
77 makeCallOnceConsumerWrapper<
JsState &, T>(
78 [promiseDeferred, promiseValueFactory = std::move(promiseValueFactory)](
JsState &jsState, T result) {
79 promiseDeferred.Resolve(promiseValueFactory(jsState, result));
82 return promiseDeferred.Promise();
88 auto optPropValue = QNapi::getOptionalPropOrEmpty<T>(object, propName);
89 return !optPropValue.IsEmpty()
90 ?
std::optional(optPropValue)
96 std::function<T(
JsState &)> initialValueReader,
97 std::function<
std::shared_ptr<
void>(
JsState &, QOhosConsumer<T>)> changeListenerFactory,
98 QOhosConsumer<T> valueChangedHandler,
99 QOhosConsumer<std::function<
void()>> targetThreadExecutor,
100 std::string callerContextName)
102 return makeQOhosDataSource<T>(
103 [initialValueReader =
std::move(initialValueReader)](QOhosJsState &jsState) {
104 return initialValueReader(
static_cast<
JsState &>(jsState));
106 [changeListenerFactory = std::move(changeListenerFactory)](
107 QOhosJsState &jsState, QOhosConsumer<T> valueUpdatesConsumer) {
108 return changeListenerFactory(
static_cast<
JsState &>(jsState),
std::move(valueUpdatesConsumer));
110 std::move(valueChangedHandler),
111 std::move(targetThreadExecutor),
112 std::move(callerContextName));
115template<
typename ConfigValue>
118 std::function<ConfigValue(
QtOhos::
JsState &,
const QNapi::Object &)> valueFetcher,
119 QOhosConsumer<ConfigValue> valueChangedHandler)
121 return QtOhos::makeDataSource<ConfigValue>(
122 std::move(initValueSupplier),
123 [valueFetcher =
std::move(valueFetcher)](
QtOhos::
JsState &jsState, QOhosConsumer<ConfigValue> valueUpdatesConsumer)
mutable {
124 return registerOhosAppContextEnvironmentCallback(
128 "onConfigurationUpdated",
129 [valueFetcher =
std::move(valueFetcher), valueUpdatesConsumer = std::move(valueUpdatesConsumer)](
const QtOhos::
CallbackInfo &cbInfo) {
130 auto config = cbInfo.getFirstArg<QNapi::Object>(Q_FUNC_INFO);
131 valueUpdatesConsumer(valueFetcher(cbInfo
.jsState(), config));
136 std::move(valueChangedHandler),
137 QtOhos::invokeInQtThread,
std::vector< QOhosDisplayInfo > getRegisteredDisplayInfos()
static std::shared_ptr< QOhosDisplayManager > create(QtOhos::JsState &jsState, CreateInfo createInfo)
QOhosDisplayInfo::JsDisplayId JsDisplayId
JsState & jsState() const
QPoint mapFromDisplayToGlobal(const QPoint &displayOffset, QOhosDisplayInfo::JsDisplayId jsDisplayId)
Combined button and popup list for selecting options.
void clearJsTimeout(JsState &jsState, int timerId)
std::optional< std::uint32_t > tryGetCodeFromJsBusinessError(const Napi::Error &error)
int setJsTimeout(JsState &jsState, std::function< void(const CallbackInfo &)> timeoutFunc, std::chrono::milliseconds delay)
bool runIgnoringJsBusinessError(JsState &, std::uint32_t suppressedErrorCode, const char *callerContextName, const std::function< void()> &action)
QNapi::Promise adaptAsyncCallResultToJsPromise(JsState &jsState, std::function< QNapi::Value(JsState &, T)> promiseValueFactory, const QOhosConsumer< JsState &, QOhosConsumer< JsState &, T > > &asyncCallFunc)
std::optional< T > getOptionalProperty(const QNapi::Object &object, const std::string &propName)
QNapi::Promise makeResolvedPromise(QNapi::Value valueForResolve)
QOhosSupplier< T > makeDataSource(std::function< T(JsState &)> initialValueReader, std::function< std::shared_ptr< void >(JsState &, QOhosConsumer< T >)> changeListenerFactory, QOhosConsumer< T > valueChangedHandler, QOhosConsumer< std::function< void()> > targetThreadExecutor, std::string callerContextName={})
void rethrowUnlessJsBusinessErrorIs(const Napi::Error &error, std::uint32_t suppressedErrorCode, const char *callerContextName)
QOhosSupplier< ConfigValue > makeOhosConfigValueDataSource(std::function< ConfigValue(QtOhos::JsState &)> initValueSupplier, std::function< ConfigValue(QtOhos::JsState &, const QNapi::Object &)> valueFetcher, QOhosConsumer< ConfigValue > valueChangedHandler)
QOhosConsumer< QtOhos::JsState &, JsDisplayId, QRectF > displayAvailableAreaChangedCb
QOhosConsumer< QtOhos::JsState &, std::vector< QOhosDisplayInfo > > displaysUpdatedCb