• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 #include <fstream>
17 #include <iostream>
18 #include <sstream>
19 #include <thread>
20 
21 #include "adapter/preview/entrance/ace_ability.h"
22 #include "adapter/preview/entrance/ace_run_args.h"
23 
24 namespace {
25 
26 constexpr int32_t GET_INSPECTOR_TREE_TIMES = 12;
27 constexpr int32_t GET_INSPECTOR_TREE_INTERVAL = 5000;
28 constexpr char FILE_NAME[] = "InspectorTree.txt";
29 constexpr char ACE_VERSION_2[] = "2.0";
30 constexpr char MODEL_STAGE[] = "stage";
31 constexpr char MAX_ARGS_COUNT = 2;
32 
__anon63d4ed110202(const void*, const size_t bufferSize, const int32_t width, const int32_t height) 33 auto&& renderCallback = [](const void*, const size_t bufferSize, const int32_t width, const int32_t height) -> bool {
34     return true;
35 };
36 
37 } // namespace
38 
main(int argc,const char * argv[])39 int main(int argc, const char* argv[])
40 {
41 #ifdef MAC_PLATFORM
42     std::string assetPathJs = "/Volumes/SSD2T/daily-test/preview/js/default";
43     std::string assetPathEts = "/Volumes/SSD2T/daily-test/preview/js/default_2.0";
44     std::string assetPathEtsStage = "/Volumes/SSD2T/daily-test/preview/js/ets";
45     std::string appResourcesPath = "/Volumes/SSD2T/daily-test/preview/js/AppResources";
46     std::string appResourcesPathStage = "/Volumes/SSD2T/daily-test/preview/js";
47     std::string systemResourcesPath = "/Volumes/SSD2T/daily-test/preview/js/SystemResources";
48 #else
49     std::string assetPathJs = "D:\\Workspace\\preview\\js\\default";
50     std::string assetPathEts = "D:\\Workspace\\preview\\js\\default_2.0";
51     std::string assetPathEtsStage = "D:\\Workspace\\preview\\js\\ets";
52     std::string appResourcesPath = "D:\\Workspace\\preview\\js\\AppResources\\assets\\entry";
53     std::string appResourcesPathStage = "D:\\Workspace\\preview\\js";
54     std::string systemResourcesPath = "D:\\Workspace\\preview\\js\\SystemResources\\assets\\entry";
55 #endif
56     OHOS::Ace::Platform::AceRunArgs args = {
57         .assetPath = assetPathJs,
58         .systemResourcesPath = systemResourcesPath,
59         .appResourcesPath = appResourcesPath,
60         .deviceConfig.orientation = OHOS::Ace::DeviceOrientation::LANDSCAPE,
61         .deviceConfig.density = 1,
62         .deviceConfig.deviceType = OHOS::Ace::DeviceType::TABLET,
63         .windowTitle = "ACE Table",
64         .deviceWidth = 1280,
65         .deviceHeight = 800,
66         .onRender = std::move(renderCallback),
67     };
68 
69     if (argc == MAX_ARGS_COUNT) {
70         if (!std::strcmp(argv[1], ACE_VERSION_2)) {
71             args.assetPath = assetPathEts;
72             args.aceVersion = OHOS::Ace::Platform::AceVersion::ACE_2_0;
73         } else if (!std::strcmp(argv[1], MODEL_STAGE)) {
74             args.assetPath = assetPathEtsStage;
75             args.aceVersion = OHOS::Ace::Platform::AceVersion::ACE_2_0;
76             args.appResourcesPath = appResourcesPathStage;
77             args.projectModel = OHOS::Ace::Platform::ProjectModel::STAGE;
78         }
79     }
80 
81     auto ability = OHOS::Ace::Platform::AceAbility::CreateInstance(args);
82     if (!ability) {
83         std::cerr << "Could not create AceAbility!" << std::endl;
84         return -1;
85     }
86 
87     std::thread timer([&ability]() {
88         int32_t getJSONTreeTimes = GET_INSPECTOR_TREE_TIMES;
89         while (getJSONTreeTimes--) {
90             std::this_thread::sleep_for(std::chrono::milliseconds(GET_INSPECTOR_TREE_INTERVAL));
91             std::string jsonTreeStr = ability->GetJSONTree();
92             // clear all information
93             std::ofstream fileCleaner(FILE_NAME, std::ios_base::out);
94             std::ofstream fileWriter(FILE_NAME, std::ofstream::app);
95             fileWriter << jsonTreeStr;
96             fileWriter << std::endl;
97             fileWriter.close();
98         }
99     });
100     ability->InitEnv();
101     std::cout << "Ace initialize done. run loop now" << std::endl;
102     ability->Start();
103 
104     return 0;
105 }
106