Enable the property designEidth of the stage card on the previewer.

Signed-off-by: zhangyu <zhangyu578@huawei.com>
This commit is contained in:
zhangyu
2022-03-23 10:30:36 +08:00
parent 23f8c0e502
commit ed0025fc49
10 changed files with 183 additions and 47 deletions
+12 -5
View File
@@ -132,7 +132,6 @@ AceAbility::AceAbility(const AceRunArgs& runArgs) : runArgs_(runArgs)
resConfig.SetDensity(SystemProperties::GetResolution());
resConfig.SetDeviceType(SystemProperties::GetDeviceType());
container->SetResourceConfiguration(resConfig);
container->SetPageProfile((runArgs_.projectModel == ProjectModel::STAGE) ? runArgs_.pageProfile + ".json" : "");
}
AceAbility::~AceAbility()
@@ -187,11 +186,20 @@ void AceAbility::InitEnv()
} else {
paths.push_back(GetCustomAssetPath(runArgs_.assetPath) + ASSET_PATH_SHARE);
}
if (runArgs_.formsEnabled) {
paths.push_back(GetCustomAssetPath(runArgs_.assetPath + DELIMITER + runArgs_.url));
}
AceContainer::AddAssetPath(ACE_INSTANCE_ID, "", paths);
auto container = AceContainer::GetContainerInstance(ACE_INSTANCE_ID);
if (!container) {
LOGE("container is null, initialize the environment failed.");
return;
}
if (runArgs_.projectModel == ProjectModel::STAGE) {
if (runArgs_.formsEnabled) {
container->SetStageCardConfig(runArgs_.pageProfile, runArgs_.url);
} else {
container->SetPageProfile((runArgs_.pageProfile.empty() ? "" : runArgs_.pageProfile + ".json"));
}
}
AceContainer::SetResourcesPathAndThemeStyle(ACE_INSTANCE_ID, runArgs_.systemResourcesPath,
runArgs_.appResourcesPath, runArgs_.themeId, runArgs_.deviceConfig.colorMode);
@@ -212,7 +220,6 @@ void AceAbility::InitEnv()
// Should make it possible to update surface changes by using viewWidth and viewHeight.
view->NotifySurfaceChanged(runArgs_.deviceWidth, runArgs_.deviceHeight);
view->NotifyDensityChanged(runArgs_.deviceConfig.density);
}
void AceAbility::Start()
+36 -25
View File
@@ -19,6 +19,7 @@
#include "adapter/preview/entrance/ace_application_info.h"
#include "adapter/preview/entrance/dir_asset_provider.h"
#include "adapter/preview/osal/stage_card_parser.h"
#include "base/log/ace_trace.h"
#include "base/log/event_report.h"
#include "base/log/log.h"
@@ -172,6 +173,24 @@ void AceContainer::RunNativeEngineLoop()
taskExecutor_->PostTask([frontend = frontend_]() { frontend->RunNativeEngineLoop(); }, TaskExecutor::TaskType::JS);
}
void AceContainer::SetStageCardConfig(const std::string& pageProfile, const std::string& selectUrl)
{
std::string fullPageProfile = pageProfile + ".json";
std::string formConfigs;
RefPtr<StageCardParser> stageCardParser = AceType::MakeRefPtr<StageCardParser>();
if (!Framework::GetAssetContentImpl(assetManager_, fullPageProfile, formConfigs)) {
LOGI("Can not load the form config.");
return;
}
const std::string prefix("./js/");
stageCardParser->Parse(formConfigs, prefix + selectUrl);
auto cardFront = static_cast<CardFrontend*>(RawPtr(frontend_));
if (cardFront) {
cardFront->SetFormSrc(selectUrl);
cardFront->SetCardWindowConfig(stageCardParser->GetWindowConfig());
}
}
void AceContainer::InitializeCallback()
{
ACE_FUNCTION_TRACE();
@@ -358,9 +377,6 @@ void AceContainer::CreateContainer(int32_t instanceId, FrontendType type, const
if (front) {
front->UpdateState(Frontend::State::ON_CREATE);
front->SetJsMessageDispatcher(aceContainer);
if (type == FrontendType::JS_CARD && runArgs.projectModel == ProjectModel::STAGE) {
static_cast<CardFrontend*>(RawPtr(front))->SetFormSrc(runArgs.url);
}
}
auto platMessageBridge = aceContainer->GetMessageBridge();
platMessageBridge->SetJsMessageDispatcher(aceContainer);
@@ -454,7 +470,7 @@ void AceContainer::UpdateResourceConfiguration(const std::string& jsonStr)
void AceContainer::NativeOnConfigurationUpdated(int32_t instanceId)
{
auto container = AceType::DynamicCast<AceContainer>(AceEngine::Get().GetContainer(instanceId));
auto container = GetContainerInstance(instanceId);
if (!container) {
return;
}
@@ -565,7 +581,7 @@ bool AceContainer::Dump(const std::vector<std::string>& params)
void AceContainer::AddRouterChangeCallback(int32_t instanceId, const OnRouterChangeCallback& onRouterChangeCallback)
{
auto container = AceType::DynamicCast<AceContainer>(AceEngine::Get().GetContainer(instanceId));
auto container = GetContainerInstance(instanceId);
if (!container) {
return;
}
@@ -580,37 +596,32 @@ void AceContainer::AddRouterChangeCallback(int32_t instanceId, const OnRouterCha
void AceContainer::AddAssetPath(
int32_t instanceId, const std::string& packagePath, const std::vector<std::string>& paths)
{
auto container = AceType::DynamicCast<AceContainer>(AceEngine::Get().GetContainer(instanceId));
auto container = GetContainerInstance(instanceId);
if (!container) {
return;
}
for (const auto& path : paths) {
RefPtr<FlutterAssetManager> flutterAssetManager;
if (container->assetManager_) {
flutterAssetManager = AceType::DynamicCast<FlutterAssetManager>(container->assetManager_);
} else {
flutterAssetManager = Referenced::MakeRefPtr<FlutterAssetManager>();
container->assetManager_ = flutterAssetManager;
if (container->frontend_) {
container->frontend_->SetAssetManager(flutterAssetManager);
}
if (!container->assetManager_) {
RefPtr<FlutterAssetManager> flutterAssetManager = Referenced::MakeRefPtr<FlutterAssetManager>();
container->assetManager_ = flutterAssetManager;
if (container->frontend_) {
container->frontend_->SetAssetManager(flutterAssetManager);
}
}
if (flutterAssetManager) {
LOGD("Current path is: %{private}s", path.c_str());
auto dirAssetProvider = AceType::MakeRefPtr<DirAssetProvider>(
path, std::make_unique<flutter::DirectoryAssetBundle>(
fml::OpenDirectory(path.c_str(), false, fml::FilePermission::kRead)));
flutterAssetManager->PushBack(std::move(dirAssetProvider));
}
for (const auto& path : paths) {
LOGD("Current path is: %{private}s", path.c_str());
auto dirAssetProvider = AceType::MakeRefPtr<DirAssetProvider>(
path, std::make_unique<flutter::DirectoryAssetBundle>(
fml::OpenDirectory(path.c_str(), false, fml::FilePermission::kRead)));
container->assetManager_->PushBack(std::move(dirAssetProvider));
}
}
void AceContainer::SetResourcesPathAndThemeStyle(int32_t instanceId, const std::string& systemResourcesPath,
const std::string& appResourcesPath, const int32_t& themeId, const ColorMode& colorMode)
{
auto container = AceType::DynamicCast<AceContainer>(AceEngine::Get().GetContainer(instanceId));
auto container = GetContainerInstance(instanceId);
if (!container) {
return;
}
@@ -785,7 +796,7 @@ void AceContainer::InitDeviceInfo(int32_t instanceId, const AceRunArgs& runArgs)
runArgs.isRound);
SystemProperties::InitDeviceType(runArgs.deviceConfig.deviceType);
SystemProperties::SetColorMode(runArgs.deviceConfig.colorMode);
auto container = AceType::DynamicCast<AceContainer>(AceEngine::Get().GetContainer(instanceId));
auto container = GetContainerInstance(instanceId);
if (!container) {
LOGE("container is null, AceContainer::InitDeviceInfo failed.");
return;
+2
View File
@@ -178,6 +178,8 @@ public:
void RunNativeEngineLoop();
void SetStageCardConfig(const std::string& pageProfile, const std::string& selectUrl);
void SetPageProfile(const std::string& pageProfile)
{
pageProfile_ = pageProfile;
@@ -41,17 +41,17 @@ int main(int argc, const char* argv[])
#ifdef MAC_PLATFORM
std::string assetPathJs = "/Volumes/SSD2T/daily-test/preview/js/default";
std::string assetPathEts = "/Volumes/SSD2T/daily-test/preview/js/default_2.0";
std::string assetPathEtsStage = "/Volumes/SSD2T/daily-test/preview/js/ets";
std::string assetPathEtsStage = "/Volumes/SSD2T/daily-test/preview/js/default_stage/ets";
std::string appResourcesPath = "/Volumes/SSD2T/daily-test/preview/js/AppResources";
std::string appResourcesPathStage = "/Volumes/SSD2T/daily-test/preview/js";
std::string appResourcesPathStage = "/Volumes/SSD2T/daily-test/preview/js/default_stage";
std::string systemResourcesPath = "/Volumes/SSD2T/daily-test/preview/js/SystemResources";
std::string fontBasePath = "/Volumes/SSD2T/daily-test/preview/js/fonts";
#else
std::string assetPathJs = "D:\\Workspace\\preview\\js\\default";
std::string assetPathEts = "D:\\Workspace\\preview\\js\\default_2.0";
std::string assetPathEtsStage = "D:\\Workspace\\preview\\js\\ets";
std::string assetPathEtsStage = "D:\\Workspace\\preview\\js\\default_stage\\ets";
std::string appResourcesPath = "D:\\Workspace\\preview\\js\\AppResources\\assets\\entry";
std::string appResourcesPathStage = "D:\\Workspace\\preview\\js";
std::string appResourcesPathStage = "D:\\Workspace\\preview\\js\\default_stage";
std::string systemResourcesPath = "D:\\Workspace\\preview\\js\\SystemResources\\assets\\entry";
std::string fontBasePath = "D:\\Workspace\\preview\\js\\fonts";
#endif
@@ -45,23 +45,27 @@ int main(int argc, const char* argv[])
#ifdef MAC_PLATFORM
std::string assetPathJs = "/Volumes/SSD2T/daily-test/preview/js/default_card";
std::string url = "ets/pages/card/index/index";
std::string assetPathEtsStage = "/Volumes/SSD2T/daily-test/preview/js/default_card_stage/js";
std::string appResourcesPath = "/Volumes/SSD2T/daily-test/preview/js/AppResources";
std::string appResourcesPathStage = "/Volumes/SSD2T/daily-test/preview/js/default_card_stage";
std::string systemResourcesPath = "/Volumes/SSD2T/daily-test/preview/js/SystemResources";
std::string fontBasePath = "/Volumes/SSD2T/daily-test/preview/js/fonts";
constexpr double density = 2;
#else
std::string assetPathJs = "D:\\Workspace\\preview\\js\\default_card";
std::string url = "ets\\pages\\card\\index\\index";
std::string assetPathEtsStage = "D:\\Workspace\\preview\\js\\default_card_stage\\js";
std::string appResourcesPath = "D:\\Workspace\\preview\\js\\AppResources\\assets\\entry";
std::string appResourcesPathStage = "D:\\Workspace\\preview\\js\\default_card_stage";
std::string systemResourcesPath = "D:\\Workspace\\preview\\js\\SystemResources\\assets\\entry";
std::string fontBasePath = "D:\\Workspace\\preview\\js\\fonts";
constexpr double density = 1;
#endif
std::string pageProfile = "form_config";
std::string url = "widget1/pages/index/index";
OHOS::Ace::Platform::AceRunArgs args = {
.assetPath = assetPathJs,
.url = url,
.systemResourcesPath = systemResourcesPath,
.appResourcesPath = appResourcesPath,
.fontBasePath = fontBasePath,
@@ -74,7 +78,11 @@ int main(int argc, const char* argv[])
.onRender = std::move(renderCallback),
};
if (argc == MAX_ARGS_COUNT && !std::strcmp(argv[1], MODEL_STAGE)) {
args.assetPath = assetPathEtsStage;
args.appResourcesPath = appResourcesPathStage;
args.projectModel = OHOS::Ace::Platform::ProjectModel::STAGE;
args.pageProfile = pageProfile;
args.url = url;
}
auto ability = OHOS::Ace::Platform::AceAbility::CreateInstance(args);
@@ -46,22 +46,23 @@ int main(int argc, const char* argv[])
#ifdef MAC_PLATFORM
std::string assetPathJs = "/Volumes/SSD2T/daily-test/preview/js/default";
std::string assetPathEts = "/Volumes/SSD2T/daily-test/preview/js/default_2.0";
std::string assetPathEtsStage = "/Volumes/SSD2T/daily-test/preview/js/ets";
std::string assetPathEtsStage = "/Volumes/SSD2T/daily-test/preview/js/default_stage/ets";
std::string appResourcesPath = "/Volumes/SSD2T/daily-test/preview/js/AppResources";
std::string appResourcesPathStage = "/Volumes/SSD2T/daily-test/preview/js";
std::string appResourcesPathStage = "/Volumes/SSD2T/daily-test/preview/js/default_stage";
std::string systemResourcesPath = "/Volumes/SSD2T/daily-test/preview/js/SystemResources";
std::string fontBasePath = "/Volumes/SSD2T/daily-test/preview/js/fonts";
constexpr double density = 2;
#else
std::string assetPathJs = "D:\\Workspace\\preview\\js\\default";
std::string assetPathEts = "D:\\Workspace\\preview\\js\\default_2.0";
std::string assetPathEtsStage = "D:\\Workspace\\preview\\js\\ets";
std::string assetPathEtsStage = "D:\\Workspace\\preview\\js\\default_stage\\ets";
std::string appResourcesPath = "D:\\Workspace\\preview\\js\\AppResources\\assets\\entry";
std::string appResourcesPathStage = "D:\\Workspace\\preview\\js";
std::string appResourcesPathStage = "D:\\Workspace\\preview\\js\\default_stage";
std::string systemResourcesPath = "D:\\Workspace\\preview\\js\\SystemResources\\assets\\entry";
std::string fontBasePath = "D:\\Workspace\\preview\\js\\fonts";
constexpr double density = 1;
#endif
std::string pageProfile = "main_page";
OHOS::Ace::Platform::AceRunArgs args = {
.assetPath = assetPathJs,
.systemResourcesPath = systemResourcesPath,
@@ -81,9 +82,10 @@ int main(int argc, const char* argv[])
args.aceVersion = OHOS::Ace::Platform::AceVersion::ACE_2_0;
} else if (!std::strcmp(argv[1], MODEL_STAGE)) {
args.assetPath = assetPathEtsStage;
args.aceVersion = OHOS::Ace::Platform::AceVersion::ACE_2_0;
args.appResourcesPath = appResourcesPathStage;
args.aceVersion = OHOS::Ace::Platform::AceVersion::ACE_2_0;
args.projectModel = OHOS::Ace::Platform::ProjectModel::STAGE;
args.pageProfile = pageProfile;
}
}
@@ -41,20 +41,22 @@ int main(int argc, const char* argv[])
#ifdef MAC_PLATFORM
std::string assetPathJs = "/Volumes/SSD2T/daily-test/preview/js/default";
std::string assetPathEts = "/Volumes/SSD2T/daily-test/preview/js/default_2.0";
std::string assetPathEtsStage = "/Volumes/SSD2T/daily-test/preview/js/ets";
std::string assetPathEtsStage = "/Volumes/SSD2T/daily-test/preview/js/default_stage/ets";
std::string appResourcesPath = "/Volumes/SSD2T/daily-test/preview/js/AppResources";
std::string appResourcesPathStage = "/Volumes/SSD2T/daily-test/preview/js";
std::string appResourcesPathStage = "/Volumes/SSD2T/daily-test/preview/js/default_stage";
std::string systemResourcesPath = "/Volumes/SSD2T/daily-test/preview/js/SystemResources";
std::string fontBasePath = "/Volumes/SSD2T/daily-test/preview/js/fonts";
#else
std::string assetPathJs = "D:\\Workspace\\preview\\js\\default";
std::string assetPathEts = "D:\\Workspace\\preview\\js\\default_2.0";
std::string assetPathEtsStage = "D:\\Workspace\\preview\\js\\ets";
std::string assetPathEtsStage = "D:\\Workspace\\preview\\js\\default_stage\\ets";
std::string appResourcesPath = "D:\\Workspace\\preview\\js\\AppResources\\assets\\entry";
std::string appResourcesPathStage = "D:\\Workspace\\preview\\js";
std::string appResourcesPathStage = "D:\\Workspace\\preview\\js\\default_stage";
std::string systemResourcesPath = "D:\\Workspace\\preview\\js\\SystemResources\\assets\\entry";
std::string fontBasePath = "D:\\Workspace\\preview\\js\\fonts";
#endif
std::string pageProfile = "main_page";
OHOS::Ace::Platform::AceRunArgs args = {
.assetPath = assetPathJs,
.systemResourcesPath = systemResourcesPath,
@@ -75,9 +77,10 @@ int main(int argc, const char* argv[])
args.aceVersion = OHOS::Ace::Platform::AceVersion::ACE_2_0;
} else if (!std::strcmp(argv[1], MODEL_STAGE)) {
args.assetPath = assetPathEtsStage;
args.aceVersion = OHOS::Ace::Platform::AceVersion::ACE_2_0;
args.appResourcesPath = appResourcesPathStage;
args.aceVersion = OHOS::Ace::Platform::AceVersion::ACE_2_0;
args.projectModel = OHOS::Ace::Platform::ProjectModel::STAGE;
args.pageProfile = pageProfile;
}
}
+1
View File
@@ -50,6 +50,7 @@ template("ace_osal_preview_source_set") {
"log_wrapper.cpp",
"response_data.cpp",
"ressched_report.cpp",
"stage_card_parser.cpp",
"system_properties.cpp",
]
@@ -0,0 +1,56 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "adapter/preview/osal/stage_card_parser.h"
namespace OHOS::Ace {
StageCardParser::StageCardParser() : manifestWindow_(Referenced::MakeRefPtr<Framework::ManifestWindow>())
{}
WindowConfig& StageCardParser::GetWindowConfig()
{
return manifestWindow_->GetWindowConfig();
}
void StageCardParser::Parse(const std::string& contents, const std::string& selectUrl)
{
auto rootJson = JsonUtil::ParseJsonString(contents);
if (!rootJson || !rootJson->IsValid()) {
LOGE("the form config is illegal");
return;
}
std::unique_ptr<JsonValue> formConfig;
auto formConfigs = rootJson->GetValue("forms");
int32_t index = 0;
if (formConfigs && formConfigs->IsArray()) {
for (; index < formConfigs->GetArraySize(); ++index) {
formConfig = formConfigs->GetArrayItem(index);
if (formConfig && formConfig->Contains("src") && formConfig->GetString("src") == selectUrl) {
break;
}
}
}
if (index == formConfigs->GetArraySize()) {
LOGE("The configuration information for the url %{public}s does not exist", selectUrl.c_str());
return;
}
colorMode_ = formConfig->GetString("colorMode");
defaultDimension_ = formConfig->GetString("defaultDimension");
description_ = formConfig->GetString("description");
manifestWindow_->WindowParse(formConfig);
}
} // namespace OHOS::Ace::Framework
+46
View File
@@ -0,0 +1,46 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef FOUNDATION_ACE_ADAPTER_PREVIEW_OSAL_STAGE_CARD_PARSER_H
#define FOUNDATION_ACE_ADAPTER_PREVIEW_OSAL_STAGE_CARD_PARSER_H
#include <string>
#include "base/log/log.h"
#include "base/memory/referenced.h"
#include "base/utils/noncopyable.h"
#include "frameworks/base/json/json_util.h"
#include "frameworks/bridge/common/manifest/manifest_window.h"
namespace OHOS::Ace {
class StageCardParser : public Referenced {
public:
StageCardParser();
~StageCardParser() override = default;
void Parse(const std::string& contents, const std::string& selectUrl);
WindowConfig& GetWindowConfig();
private:
std::string colorMode_;
std::string defaultDimension_;
std::string description_;
RefPtr<Framework::ManifestWindow> manifestWindow_;
ACE_DISALLOW_COPY_AND_MOVE(StageCardParser);
};
} // namespace OHOS::Ace
#endif // FOUNDATION_ACE_ADAPTER_PREVIEW_OSAL_STAGE_CARD_PARSER_H