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