• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef JSAPPIMPL_H
17 #define JSAPPIMPL_H
18 
19 #include <atomic>
20 #include <memory>
21 #include <thread>
22 
23 #include "JsApp.h"
24 #include "ace_ability.h"
25 #include "ace_run_args.h"
26 #include "device_config.h"
27 #include "device_type.h"
28 
29 class JsAppImpl : public JsApp {
30 public:
31     JsAppImpl();
~JsAppImpl()32     ~JsAppImpl() {}
33     JsAppImpl& operator=(const JsAppImpl&) = delete;
34     JsAppImpl(const JsAppImpl&) = delete;
35 
36     static JsAppImpl& GetInstance();
37     void Start() override;
38     void Restart() override;
39     void Interrupt() override;
40     std::string GetJSONTree() override;
41     std::string GetDefaultJSONTree() override;
42     void OrientationChanged(std::string commandOrientation) override;
43     void ResolutionChanged(int32_t changedOriginWidth, int32_t changedOriginHeight,
44                            int32_t changedWidth, int32_t changedHeight, int32_t screenDensity) override;
45     void SetArgsColorMode(const std::string& value) override;
46     void SetArgsAceVersion(const std::string& value) override;
47     void SetDeviceOrentation(const std::string& value);
48     std::string GetOrientation() const override;
49     std::string GetColorMode() const override;
50     void ColorModeChanged(const std::string commandColorMode) override;
51     void ReloadRuntimePage(const std::string currentPage) override;
52     void SetScreenDensity(const std::string value) override;
53     void SetConfigChanges(const std::string value) override;
54     bool MemoryRefresh(const std::string memoryRefreshArgs) const override;
55     void LoadDocument(const std::string, const std::string, const Json::Value) override;
56 
57 protected:
58     void SetJsAppArgs(OHOS::Ace::Platform::AceRunArgs& args);
59     void RunJsApp();
60     double watchScreenDensity = 320;  // Watch Screen Density
61     double phoneScreenDensity = 480;  // Phone Screen Density
62     double tvScreenDensity = 320;     // TV Screen Density
63     double tabletScreenDensity = 400; // Tablet Screen Density
64     double carScreenDensity = 320;    // Car Screen Density
65 
66 private:
67     void SetAssetPath(OHOS::Ace::Platform::AceRunArgs& args, const std::string) const;
68     void SetProjectModel(OHOS::Ace::Platform::AceRunArgs& args) const;
69     void SetPageProfile(OHOS::Ace::Platform::AceRunArgs& args, const std::string) const;
70     void SetDeviceWidth(OHOS::Ace::Platform::AceRunArgs& args, const int32_t) const;
71     void SetDeviceHeight(OHOS::Ace::Platform::AceRunArgs& args, const int32_t) const;
72     void SetWindowTitle(OHOS::Ace::Platform::AceRunArgs& args, const std::string) const;
73     void SetUrl(OHOS::Ace::Platform::AceRunArgs& args, const std::string) const;
74     void SetConfigChanges(OHOS::Ace::Platform::AceRunArgs& args, const std::string) const;
75     void SetColorMode(OHOS::Ace::Platform::AceRunArgs& args, const std::string) const;
76     void SetOrientation(OHOS::Ace::Platform::AceRunArgs& args, const std::string) const;
77     void SetAceVersionArgs(OHOS::Ace::Platform::AceRunArgs& args, const std::string) const;
78     void SetLanguage(OHOS::Ace::Platform::AceRunArgs& args, const std::string) const;
79     void SetRegion(OHOS::Ace::Platform::AceRunArgs& args, const std::string) const;
80     void SetScript(OHOS::Ace::Platform::AceRunArgs& args, const std::string) const;
81     void SetSystemResourcesPath(OHOS::Ace::Platform::AceRunArgs& args) const;
82     void SetAppResourcesPath(OHOS::Ace::Platform::AceRunArgs& args, const std::string) const;
83     void SetFormsEnabled(OHOS::Ace::Platform::AceRunArgs& args, bool formsEnabled) const;
84     void SetContainerSdkPath(OHOS::Ace::Platform::AceRunArgs& args, const std::string) const;
85     void SetOnRender(OHOS::Ace::Platform::AceRunArgs& args) const;
86     void SetOnRouterChange(OHOS::Ace::Platform::AceRunArgs& args) const;
87     void SetOnError(OHOS::Ace::Platform::AceRunArgs& args) const;
88     void SetComponentModeEnabled(OHOS::Ace::Platform::AceRunArgs& args, bool isComponentMode) const;
89     void AssignValueForWidthAndHeight(const int32_t origWidth, const int32_t origHeight,
90                                       const int32_t compWidth, const int32_t compHeight);
91     void AdaptDeviceType(OHOS::Ace::Platform::AceRunArgs& args, const std::string,
92                          const int32_t, double screenDendity = 0) const;
93     void ParseSystemParams(OHOS::Ace::Platform::AceRunArgs& args, Json::Value paramObj);
94     void SetSystemParams(OHOS::Ace::Platform::SystemParams& args, Json::Value paramObj);
95     void SetDeviceScreenDensity(const int32_t screenDensity, const std::string type);
96     std::string GetDeviceTypeName(const OHOS::Ace::DeviceType) const;
97     const double BASE_SCREEN_DENSITY = 160; // Device Baseline Screen Density
98     std::unique_ptr<OHOS::Ace::Platform::AceAbility> ability;
99     std::atomic<bool> isStop;
100     int32_t width = 0;
101     int32_t height = 0;
102     int32_t orignalWidth = 0;
103     int32_t orignalHeight = 0;
104     OHOS::Ace::Platform::AceRunArgs aceRunArgs;
105 };
106 
107 #endif // JSAPPIMPL_H
108