Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F32508365
D5574.1767076621.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D5574.1767076621.diff
View Options
diff --git a/native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp b/native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp
--- a/native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp
+++ b/native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp
@@ -1000,22 +1000,41 @@
CommCoreModule::setDeviceID(jsi::Runtime &rt, const jsi::String &deviceType) {
std::string type = deviceType.utf8(rt);
std::string deviceID;
+ std::string deviceIDGenerationError;
+
try {
deviceID = DeviceIDGenerator::generateDeviceID(type);
} catch (std::invalid_argument &e) {
- throw jsi::JSError(
- rt,
- "setDeviceID: incorrect function argument. Must be one of: "
- "KEYSERVER, WEB, MOBILE.");
+ deviceIDGenerationError =
+ "setDeviceID: incorrect function argument. Must be one of: KEYSERVER, "
+ "WEB, MOBILE.";
}
- GlobalDBSingleton::instance.scheduleOrRun([&rt, deviceID]() {
- try {
- DatabaseManager::getQueryExecutor().setDeviceID(deviceID);
- } catch (const std::exception &e) {
- throw jsi::JSError(rt, e.what());
- }
- });
- return jsi::String::createFromUtf8(rt, deviceID);
+
+ return createPromiseAsJSIValue(
+ rt, [=](jsi::Runtime &innerRt, std::shared_ptr<Promise> promise) {
+ taskType job = [this,
+ &innerRt,
+ promise,
+ deviceIDGenerationError,
+ deviceID]() {
+ std::string error = deviceIDGenerationError;
+ if (!error.size()) {
+ try {
+ DatabaseManager::getQueryExecutor().setDeviceID(deviceID);
+ } catch (const std::exception &e) {
+ error = e.what();
+ }
+ }
+ this->jsInvoker_->invokeAsync([&innerRt, promise, error, deviceID]() {
+ if (error.size()) {
+ promise->reject(error);
+ } else {
+ promise->resolve(jsi::String::createFromUtf8(innerRt, deviceID));
+ }
+ });
+ };
+ GlobalDBSingleton::instance.scheduleOrRun(job);
+ });
}
jsi::Value CommCoreModule::getDeviceID(jsi::Runtime &rt) {
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Dec 30, 6:37 AM (1 h, 58 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5866583
Default Alt Text
D5574.1767076621.diff (2 KB)
Attached To
Mode
D5574: [CommCoreModule] update `setDeviceID` to return JSI Promise instead of value
Attached
Detach File
Event Timeline
Log In to Comment