代码拉取完成,页面将自动刷新
同步操作将从 OpenHarmony/ide_previewer 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
/*
* Copyright (c) 2023 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 <chrono>
#include <thread>
#include <vector>
#include <new>
#include "CommandLineInterface.h"
#include "CommandParser.h"
#include "CppTimer.h"
#include "CppTimerManager.h"
#include "CrashHandler.h"
#include "Interrupter.h"
#include "JsAppImpl.h"
#include "PreviewerEngineLog.h"
#include "SharedData.h"
#include "TraceTool.h"
#include "VirtualScreenImpl.h"
static const int NOTIFY_INTERVAL_TIME = 1000; // Unit millisecond
static void ApplyConfig()
{
std::string richConfigArgs = CommandParser::GetInstance().GetConfigPath();
if (richConfigArgs.empty()) {
ELOG("No persistent properties path found.");
}
CommandLineInterface::GetInstance().ReadAndApplyConfig(richConfigArgs);
}
static void NotifyInspectorChanged()
{
if (!VirtualScreenImpl::GetInstance().isFrameUpdated) {
return;
}
VirtualScreenImpl::GetInstance().isFrameUpdated = false;
static std::string jsonTreeLast = "";
std::string jsonTree = JsAppImpl::GetInstance().GetJSONTree();
if (jsonTree == jsonTreeLast) {
return;
}
jsonTreeLast = jsonTree;
Json2::Value commandResult = JsonReader::CreateObject();
commandResult.Add("version", CommandLineInterface::COMMAND_VERSION.c_str());
commandResult.Add("command", "inspector");
commandResult.Add("result", jsonTree.c_str());
CommandLineInterface::GetInstance().SendJsonData(commandResult);
ILOG("Send inspector json tree.");
}
static void ProcessCommand()
{
if (!CommandParser::GetInstance().IsSet("d")) {
static CppTimer inspectorNotifytimer(NotifyInspectorChanged);
inspectorNotifytimer.Start(NOTIFY_INTERVAL_TIME); // Notify per second
CppTimerManager::GetTimerManager().AddCppTimer(inspectorNotifytimer);
}
VirtualScreenImpl::GetInstance().InitFrameCountTimer();
while (!Interrupter::IsInterrupt()) {
CommandLineInterface::GetInstance().ProcessCommand();
CppTimerManager::GetTimerManager().RunTimerTick();
std::this_thread::sleep_for(std::chrono::milliseconds(1));
}
JsAppImpl::GetInstance().Stop();
}
static void InitSharedData()
{
CommandParser& parser = CommandParser::GetInstance();
if (parser.IsSet("l")) {
SharedData<std::string>(SharedDataType::LANGUAGE, parser.Value("l"));
} else {
SharedData<std::string>(SharedDataType::LANGUAGE, "zh_CN");
}
std::string lanInfo = SharedData<std::string>::GetData(SharedDataType::LANGUAGE);
SharedData<std::string>(SharedDataType::LAN, lanInfo.substr(0, lanInfo.find("_")));
SharedData<std::string>(SharedDataType::REGION, lanInfo.substr(lanInfo.find("_") + 1, lanInfo.length() - 1));
ILOG("Start language is : %s", SharedData<std::string>::GetData(SharedDataType::LANGUAGE).c_str());
}
static void NewHandler()
{
ELOG("Custom new handler: memory allocation failed.");
}
int main(int argc, char* argv[])
{
ILOG("RichPreviewer enter the main function.");
std::set_new_handler(NewHandler); // 设置全局new处理函数
auto richCrashHandler = std::make_unique<CrashHandler>();
// init exception handler
richCrashHandler->InitExceptionHandler();
// Parsing User Commands
CommandParser& parser = CommandParser::GetInstance();
int ret = parser.ParseArgs(argc, argv);
if (ret >= 0) {
return ret;
}
InitSharedData();
if (parser.IsSet("s")) {
CommandLineInterface::GetInstance().Init(parser.Value("s"));
}
TraceTool::GetInstance().HandleTrace("Enter the main function");
std::thread commandThead(ProcessCommand);
commandThead.detach();
VirtualScreenImpl::GetInstance().InitResolution();
ApplyConfig();
JsAppImpl::GetInstance().InitJsApp();
std::this_thread::sleep_for(std::chrono::milliseconds(500)); // sleep 500 ms
return 0;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。