-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJHybridVersionCheckSpec.cpp
More file actions
123 lines (111 loc) · 5.82 KB
/
JHybridVersionCheckSpec.cpp
File metadata and controls
123 lines (111 loc) · 5.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
///
/// JHybridVersionCheckSpec.cpp
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © Marc Rousavy @ Margelo
///
#include "JHybridVersionCheckSpec.hpp"
#include <string>
#include <optional>
#include <NitroModules/Promise.hpp>
#include <NitroModules/JPromise.hpp>
namespace margelo::nitro::nitroversioncheck {
std::shared_ptr<JHybridVersionCheckSpec> JHybridVersionCheckSpec::JavaPart::getJHybridVersionCheckSpec() {
auto hybridObject = JHybridObject::JavaPart::getJHybridObject();
auto castHybridObject = std::dynamic_pointer_cast<JHybridVersionCheckSpec>(hybridObject);
if (castHybridObject == nullptr) [[unlikely]] {
throw std::runtime_error("Failed to downcast JHybridObject to JHybridVersionCheckSpec!");
}
return castHybridObject;
}
jni::local_ref<JHybridVersionCheckSpec::CxxPart::jhybriddata> JHybridVersionCheckSpec::CxxPart::initHybrid(jni::alias_ref<jhybridobject> jThis) {
return makeCxxInstance(jThis);
}
std::shared_ptr<JHybridObject> JHybridVersionCheckSpec::CxxPart::createHybridObject(const jni::local_ref<JHybridObject::JavaPart>& javaPart) {
auto castJavaPart = jni::dynamic_ref_cast<JHybridVersionCheckSpec::JavaPart>(javaPart);
if (castJavaPart == nullptr) [[unlikely]] {
throw std::runtime_error("Failed to cast JHybridObject::JavaPart to JHybridVersionCheckSpec::JavaPart!");
}
return std::make_shared<JHybridVersionCheckSpec>(castJavaPart);
}
void JHybridVersionCheckSpec::CxxPart::registerNatives() {
registerHybrid({
makeNativeMethod("initHybrid", JHybridVersionCheckSpec::CxxPart::initHybrid),
});
}
// Properties
std::string JHybridVersionCheckSpec::getVersion() {
static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<jni::JString>()>("getVersion");
auto __result = method(_javaPart);
return __result->toStdString();
}
std::string JHybridVersionCheckSpec::getBuildNumber() {
static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<jni::JString>()>("getBuildNumber");
auto __result = method(_javaPart);
return __result->toStdString();
}
std::string JHybridVersionCheckSpec::getPackageName() {
static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<jni::JString>()>("getPackageName");
auto __result = method(_javaPart);
return __result->toStdString();
}
std::optional<std::string> JHybridVersionCheckSpec::getInstallSource() {
static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<jni::JString>()>("getInstallSource");
auto __result = method(_javaPart);
return __result != nullptr ? std::make_optional(__result->toStdString()) : std::nullopt;
}
// Methods
std::string JHybridVersionCheckSpec::getCountry() {
static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<jni::JString>()>("getCountry");
auto __result = method(_javaPart);
return __result->toStdString();
}
std::shared_ptr<Promise<std::string>> JHybridVersionCheckSpec::getStoreUrl(const std::optional<std::string>& countryCode) {
static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>(jni::alias_ref<jni::JString> /* countryCode */)>("getStoreUrl");
auto __result = method(_javaPart, countryCode.has_value() ? jni::make_jstring(countryCode.value()) : nullptr);
return [&]() {
auto __promise = Promise<std::string>::create();
__result->cthis()->addOnResolvedListener([=](const jni::alias_ref<jni::JObject>& __boxedResult) {
auto __result = jni::static_ref_cast<jni::JString>(__boxedResult);
__promise->resolve(__result->toStdString());
});
__result->cthis()->addOnRejectedListener([=](const jni::alias_ref<jni::JThrowable>& __throwable) {
jni::JniException __jniError(__throwable);
__promise->reject(std::make_exception_ptr(__jniError));
});
return __promise;
}();
}
std::shared_ptr<Promise<std::string>> JHybridVersionCheckSpec::getLatestVersion(const std::optional<std::string>& countryCode) {
static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>(jni::alias_ref<jni::JString> /* countryCode */)>("getLatestVersion");
auto __result = method(_javaPart, countryCode.has_value() ? jni::make_jstring(countryCode.value()) : nullptr);
return [&]() {
auto __promise = Promise<std::string>::create();
__result->cthis()->addOnResolvedListener([=](const jni::alias_ref<jni::JObject>& __boxedResult) {
auto __result = jni::static_ref_cast<jni::JString>(__boxedResult);
__promise->resolve(__result->toStdString());
});
__result->cthis()->addOnRejectedListener([=](const jni::alias_ref<jni::JThrowable>& __throwable) {
jni::JniException __jniError(__throwable);
__promise->reject(std::make_exception_ptr(__jniError));
});
return __promise;
}();
}
std::shared_ptr<Promise<bool>> JHybridVersionCheckSpec::needsUpdate() {
static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>()>("needsUpdate");
auto __result = method(_javaPart);
return [&]() {
auto __promise = Promise<bool>::create();
__result->cthis()->addOnResolvedListener([=](const jni::alias_ref<jni::JObject>& __boxedResult) {
auto __result = jni::static_ref_cast<jni::JBoolean>(__boxedResult);
__promise->resolve(static_cast<bool>(__result->value()));
});
__result->cthis()->addOnRejectedListener([=](const jni::alias_ref<jni::JThrowable>& __throwable) {
jni::JniException __jniError(__throwable);
__promise->reject(std::make_exception_ptr(__jniError));
});
return __promise;
}();
}
} // namespace margelo::nitro::nitroversioncheck