1 /*
2 * Copyright (c) 2021-2023 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 MAX_ARGS_COUNT = 2;
33
__anon75d5feae0202(const void*, const size_t bufferSize, const int32_t width, const int32_t height) 34 auto&& renderCallback = [](const void*, const size_t bufferSize, const int32_t width, const int32_t height) -> bool {
35 return true;
36 };
37
38 } // namespace
39
main(int argc,const char * argv[])40 int main(int argc, const char* argv[])
41 {
42 #ifdef MAC_PLATFORM
43 std::string assetPathJs = "/Volumes/SSD2T/daily-test/preview/js/default";
44 std::string assetPathEts = "/Volumes/SSD2T/daily-test/preview/js/default_2.0";
45 #elif WINDOWS_PLATFORM
46 std::string assetPathJs = "D:\\Workspace\\preview\\js\\default";
47 std::string assetPathEts = "D:\\Workspace\\preview\\js\\default_2.0";
48 #else
49 std::string assetPathJs = "/home/ubuntu/demo/preview/js/default";
50 std::string assetPathEts = "/home/ubuntu/demo/preview/js/default_2.0";
51 #endif
52 OHOS::Ace::Platform::AceRunArgs args = {
53 .assetPath = assetPathJs,
54 .deviceConfig.orientation = OHOS::Ace::DeviceOrientation::LANDSCAPE,
55 .deviceConfig.density = 1,
56 .deviceConfig.deviceType = OHOS::Ace::DeviceType::TV,
57 .windowTitle = "ACE TV",
58 .deviceWidth = 960,
59 .deviceHeight = 540,
60 .onRender = std::move(renderCallback),
61 };
62
63 if (argc == MAX_ARGS_COUNT && !std::strcmp(argv[1], ACE_VERSION_2)) {
64 args.assetPath = assetPathEts;
65 args.aceVersion = OHOS::Ace::Platform::AceVersion::ACE_2_0;
66 }
67
68 auto ability = OHOS::Ace::Platform::AceAbility::CreateInstance(args);
69 if (!ability) {
70 std::cerr << "Could not create AceAbility!" << std::endl;
71 return -1;
72 }
73 OHOS::Ace::Platform::KeyInputHandler::InitialTextInputCallback(ability->GetGlfwWindowController());
74 OHOS::Ace::Platform::TouchEventHandler::InitialTouchEventCallback(ability->GetGlfwWindowController());
75
76 std::thread timer([&ability]() {
77 int32_t getJSONTreeTimes = GET_INSPECTOR_TREE_TIMES;
78 while (getJSONTreeTimes--) {
79 std::this_thread::sleep_for(std::chrono::milliseconds(GET_INSPECTOR_TREE_INTERVAL));
80 std::string jsonTreeStr = ability->GetJSONTree();
81 // clear all information
82 std::ofstream fileCleaner(FILE_NAME, std::ios_base::out);
83 std::ofstream fileWriter(FILE_NAME, std::ofstream::app);
84 fileWriter << jsonTreeStr;
85 fileWriter << std::endl;
86 fileWriter.close();
87 }
88 });
89 ability->InitEnv();
90 std::cout << "Ace initialize done. run loop now" << std::endl;
91 ability->Start();
92
93 return 0;
94 }
95