• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef APPEXECFWK_STANDARD_KITS_APPKIT_NAPI_PACKAGE_PACKAGE_H
16 #define APPEXECFWK_STANDARD_KITS_APPKIT_NAPI_PACKAGE_PACKAGE_H
17 #include <native_engine/native_value.h>
18 
19 #include "hilog_wrapper.h"
20 #include "napi/native_api.h"
21 #include "napi/native_common.h"
22 #include "napi/native_node_api.h"
23 #include "nlohmann/json.hpp"
24 #include "js_runtime_utils.h"
25 #include "js_runtime.h"
26 
27 namespace OHOS {
28 namespace AppExecFwk {
29 struct CheckPackageHasInstalledResponse {
30     bool result = false;
31 };
32 struct CheckPackageHasInstalledOptions {
33     std::unique_ptr<NativeReference> jsSuccessRef = nullptr;
34     std::unique_ptr<NativeReference> jsFailRef = nullptr;
35     std::unique_ptr<NativeReference> jsCompleteRef = nullptr;
36     std::string bundleName;
37     bool isString = false;
38     CheckPackageHasInstalledResponse response;
39     ~CheckPackageHasInstalledOptions();
40 };
41 class JsPackage {
42 public:
43     JsPackage() = default;
44     ~JsPackage() = default;
45 
46     static void Finalizer(NativeEngine *engine, void *data, void *hint);
47     static NativeValue* HasInstalled(NativeEngine *engine, NativeCallbackInfo *info);
48 private:
49     NativeValue* OnHasInstalled(NativeEngine &engine, NativeCallbackInfo &info);
50     NativeValue* CreateHasInstalled(NativeEngine &engine, const OHOS::AppExecFwk::CheckPackageHasInstalledOptions &
51         hasInstalledOptions);
52     void JsParseCheckPackageHasInstalledOptions(NativeEngine &engine, const NativeCallbackInfo &info,
53         std::shared_ptr<CheckPackageHasInstalledOptions> hasInstalledOptions);
54 };
55 }  // namespace AppExecFwk
56 }  // namespace OHOS
57 #endif /* APPEXECFWK_STANDARD_KITS_APPKIT_NAPI_PACKAGE_PACKAGE_H */