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