diff --git a/frameworks/js/napi/include/enable_notification.h b/frameworks/js/napi/include/enable_notification.h index 51b0faf9f635ef748b5b7a886d9d92e19aa47d22..70c2fb23d4a6985be1dd732a2474a555a9ae159d 100644 --- a/frameworks/js/napi/include/enable_notification.h +++ b/frameworks/js/napi/include/enable_notification.h @@ -39,6 +39,7 @@ struct AsyncCallbackInfoIsEnable { napi_async_work asyncWork = nullptr; IsEnableParams params; CallbackPromiseInfo info; + bool newInterface = false; bool allowed = false; }; diff --git a/frameworks/js/napi/src/enable_notification.cpp b/frameworks/js/napi/src/enable_notification.cpp index 322deb14711efd04cb29eb718ba815cb2fcaa488..71b10ba00760bb3c9646660935b3700a68b54a99 100644 --- a/frameworks/js/napi/src/enable_notification.cpp +++ b/frameworks/js/napi/src/enable_notification.cpp @@ -187,7 +187,11 @@ void AsyncCompleteCallbackIsNotificationEnabled(napi_env env, napi_status status AsyncCallbackInfoIsEnable *asynccallbackinfo = static_cast(data); napi_value result = nullptr; napi_get_boolean(env, asynccallbackinfo->allowed, &result); - Common::ReturnCallbackPromise(env, asynccallbackinfo->info, result); + if (asynccallbackinfo->newInterface) { + Common::CreateReturnValue(env, asynccallbackinfo->info, result); + } else { + Common::ReturnCallbackPromise(env, asynccallbackinfo->info, result); + } if (asynccallbackinfo->info.callback != nullptr) { napi_delete_reference(env, asynccallbackinfo->info.callback); } diff --git a/frameworks/js/napi/src/manager/napi_enable_notification.cpp b/frameworks/js/napi/src/manager/napi_enable_notification.cpp index 36de4d82744b3842d4a383d3f3c86610ee5601c7..d328bc47cc6dcb84675ccb4aaecbca1dc6947d94 100644 --- a/frameworks/js/napi/src/manager/napi_enable_notification.cpp +++ b/frameworks/js/napi/src/manager/napi_enable_notification.cpp @@ -210,8 +210,8 @@ napi_value NapiRequestEnableNotification(napi_env env, napi_callback_info info) return Common::NapiGetUndefined(env); } - AsyncCallbackInfoIsEnable *asynccallbackinfo = - new (std::nothrow) AsyncCallbackInfoIsEnable {.env = env, .asyncWork = nullptr, .params = params}; + AsyncCallbackInfoIsEnable *asynccallbackinfo = new (std::nothrow) AsyncCallbackInfoIsEnable { + .env = env, .params = params, .newInterface = true}; if (!asynccallbackinfo) { return Common::JSParaError(env, params.callback); } @@ -221,18 +221,29 @@ napi_value NapiRequestEnableNotification(napi_env env, napi_callback_info info) napi_value resourceName = nullptr; napi_create_string_latin1(env, "RequestEnableNotification", NAPI_AUTO_LENGTH, &resourceName); // Asynchronous function call - napi_create_async_work(env, - nullptr, - resourceName, + napi_create_async_work(env, nullptr, resourceName, [](napi_env env, void *data) { ANS_LOGI("RequestEnableNotification napi_create_async_work start"); AsyncCallbackInfoIsEnable *asynccallbackinfo = static_cast(data); std::string deviceId {""}; - asynccallbackinfo->info.errorCode = NotificationHelper::RequestEnableNotification(deviceId); - ANS_LOGI("asynccallbackinfo->info.errorCode = %{public}d", asynccallbackinfo->info.errorCode); + bool popFlag = false; + asynccallbackinfo->info.errorCode = NotificationHelper::RequestEnableNotification(deviceId, popFlag); + asynccallbackinfo->params.allowToPop = popFlag; + ANS_LOGI("asynccallbackinfo->info.errorCode = %{public}d, allowToPop = %{public}d", + asynccallbackinfo->info.errorCode, asynccallbackinfo->params.allowToPop); + if (asynccallbackinfo->info.errorCode == ERR_OK && asynccallbackinfo->params.allowToPop) { + ANS_LOGI("Begin to start notification dialog"); + auto *callbackInfo = static_cast(data); + StartNotificationDialog(callbackInfo); + } + }, + [](napi_env env, napi_status status, void *data) { + AsyncCallbackInfoIsEnable *asynccallbackinfo = static_cast(data); + if (!(asynccallbackinfo->info.errorCode == ERR_OK && asynccallbackinfo->params.allowToPop)) { + AsyncCompleteCallbackNapiIsNotificationEnabled(env, status, data); + } }, - AsyncCompleteCallbackNapiIsNotificationEnabled, (void *)asynccallbackinfo, &asynccallbackinfo->asyncWork);