1 /*
2 * Copyright (c) 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 "JsApp.h"
17
18 #include "FileSystem.h"
19 #include "JsAppImpl.h"
20 #include "PreviewerEngineLog.h"
21
22 using namespace std;
23
24 static std::vector<std::string> liteDevice = {"liteWearable", "smartVision"};
25
JsApp()26 JsApp::JsApp()
27 : pipeName(""),
28 pipePort(""),
29 jsAppPath(""),
30 bundleName("undefined"),
31 urlPath(""),
32 isFinished(true),
33 isRunning(true),
34 isDebug(false),
35 debugServerPort(0),
36 jsHeapSize(0),
37 colorMode(""),
38 orientation(""),
39 aceVersion(""),
40 screenDensity(""),
41 configChanges("")
42 {
43 }
44
Stop()45 void JsApp::Stop()
46 {
47 ILOG("JsApp::Stop start stop js app.");
48 auto start = std::chrono::system_clock::now();
49 while (!isFinished) {
50 JsAppImpl::GetInstance().Interrupt();
51 this_thread::sleep_for(chrono::milliseconds(1));
52 auto end = std::chrono::system_clock::now();
53 auto passedSecond = chrono::duration_cast<chrono::seconds>(end - start).count();
54 if (passedSecond > 10) { // The restart timeout interval is 10 seconds.
55 ILOG("Restart js app time out!");
56 return;
57 }
58 }
59 ILOG("JsApp::Stop js app stop finished.");
60 }
61
IsLiteDevice(std::string deviceType)62 bool JsApp::IsLiteDevice(std::string deviceType)
63 {
64 auto iter = find(liteDevice.begin(), liteDevice.end(), deviceType);
65 if (iter == liteDevice.end()) {
66 return false;
67 }
68 return true;
69 }
70
SetPipeName(const std::string & name)71 void JsApp::SetPipeName(const std::string& name)
72 {
73 pipeName = name;
74 }
75
SetPipePort(const std::string & port)76 void JsApp::SetPipePort(const std::string& port)
77 {
78 pipePort = port;
79 }
80
SetJsAppPath(const string & value)81 void JsApp::SetJsAppPath(const string& value)
82 {
83 jsAppPath = value;
84 }
85
SetScreenDensity(const std::string value)86 void JsApp::SetScreenDensity(const std::string value)
87 {
88 screenDensity = value;
89 }
90
SetConfigChanges(const std::string value)91 void JsApp::SetConfigChanges(const std::string value)
92 {
93 configChanges = value;
94 }
95
SetUrlPath(const string & value)96 void JsApp::SetUrlPath(const string& value)
97 {
98 urlPath = value;
99 }
100
SetBundleName(const string & name)101 void JsApp::SetBundleName(const string& name)
102 {
103 bundleName = name;
104 FileSystem::SetBundleName(name);
105 FileSystem::MakeVirtualFileSystemPath();
106 }
107
SetRunning(bool flag)108 void JsApp::SetRunning(bool flag)
109 {
110 isRunning = flag;
111 }
112
GetRunning()113 bool JsApp::GetRunning()
114 {
115 return isRunning;
116 }
117
SetIsDebug(bool value)118 void JsApp::SetIsDebug(bool value)
119 {
120 isDebug = value;
121 }
122
SetDebugServerPort(uint16_t value)123 void JsApp::SetDebugServerPort(uint16_t value)
124 {
125 debugServerPort = value;
126 }
127
SetJSHeapSize(uint32_t size)128 void JsApp::SetJSHeapSize(uint32_t size)
129 {
130 jsHeapSize = size;
131 }
132
GetJSONTree()133 string JsApp::GetJSONTree()
134 {
135 return "";
136 }
137
GetDefaultJSONTree()138 string JsApp::GetDefaultJSONTree()
139 {
140 return "";
141 }
142
SetArgsColorMode(const string & value)143 void JsApp::SetArgsColorMode(const string& value)
144 {
145 colorMode = value;
146 }
147
SetArgsAceVersion(const string & value)148 void JsApp::SetArgsAceVersion(const string& value)
149 {
150 aceVersion = value;
151 }
152
ColorModeChanged(const std::string commandColorMode)153 void JsApp::ColorModeChanged(const std::string commandColorMode)
154 {
155 colorMode = commandColorMode;
156 };
157
GetColorMode() const158 std::string JsApp::GetColorMode() const
159 {
160 return colorMode;
161 }
162
GetOrientation() const163 std::string JsApp::GetOrientation() const
164 {
165 return orientation;
166 }
167
OrientationChanged(std::string commandOrientation)168 void JsApp::OrientationChanged(std::string commandOrientation)
169 {
170 orientation = commandOrientation;
171 };
172
ResolutionChanged(int32_t,int32_t,int32_t,int32_t,int32_t)173 void JsApp::ResolutionChanged(int32_t, int32_t, int32_t, int32_t, int32_t) {};
174
ReloadRuntimePage(const std::string)175 void JsApp::ReloadRuntimePage(const std::string) {};
176
MemoryRefresh(const std::string) const177 bool JsApp::MemoryRefresh(const std::string) const
178 {
179 return false;
180 }
181
LoadDocument(const std::string,const std::string,const Json::Value)182 void JsApp::LoadDocument(const std::string, const std::string, const Json::Value) {};
183