1 /* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef JS_UI_APPEARANCE_H 17 #define JS_UI_APPEARANCE_H 18 19 #include <string> 20 21 #include "napi/native_api.h" 22 #include "napi/native_common.h" 23 #include "napi/native_node_api.h" 24 #include "ui_appearance_ability_client.h" 25 26 namespace OHOS { 27 namespace ArkUi::UiAppearance { 28 struct AsyncContext { 29 napi_async_work work = nullptr; 30 napi_deferred deferred = nullptr; 31 napi_ref callbackRef = nullptr; 32 int32_t jsSetArg = -1; 33 double jsFontScale = 0; 34 double jsFontWeightScale = 0; 35 std::string errMsg; 36 UiAppearanceAbilityInterface::ErrCode status; 37 UiAppearanceAbilityInterface::DarkMode mode; 38 std::string fontScale; 39 std::string fontWeightScale; 40 }; 41 42 class JsUiAppearance final { 43 public: 44 static void OnExecute(napi_env env, void* data); 45 static void OnComplete(napi_env env, napi_status status, void* data); 46 static void OnSetFontScale(napi_env env, void* data); 47 static void OnSetFontWeightScale(napi_env env, void* data); 48 static napi_status CheckArgs(napi_env env, size_t argc, napi_value* argv); 49 static napi_status CheckFontScaleArgs(napi_env env, size_t argc, napi_value* argv); 50 static UiAppearanceAbilityInterface::DarkMode ConvertJsDarkMode2Enum(int32_t jsVal); 51 }; 52 53 napi_value JSSetDarkModeSync(napi_env env, napi_callback_info info); 54 napi_value JSGetDarkModeSync(napi_env env, napi_callback_info info); 55 napi_value JSSetFontScaleSync(napi_env env, napi_callback_info info); 56 napi_value JSGetFontScaleSync(napi_env env, napi_callback_info info); 57 napi_value JSSetFontWeightScaleSync(napi_env env, napi_callback_info info); 58 napi_value JSGetFontWeightScaleSync(napi_env env, napi_callback_info info); 59 } // namespace ArkUi::UiAppearance 60 } // namespace OHOS 61 #endif // JS_UI_APPEARANCE_H