Compare commits
14
Commits
e328780ee5
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1527d558d4 | ||
|
|
cfe2dfc815 | ||
|
|
e590a5a28f | ||
|
|
4bcee5ba9f | ||
|
|
d95694d934 | ||
|
|
0a221c5405 | ||
|
|
644887278a | ||
|
|
c82c1439a7 | ||
|
|
4613919277 | ||
|
|
bde990ac82 | ||
|
|
a14b10d62f | ||
|
|
06f4a95020 | ||
|
|
6c99ae75f6 | ||
|
|
8b6e24fa61 |
No files matched your search
@@ -16,6 +16,9 @@ node_modules/
|
|||||||
# HarmonyOS / DevEco common outputs
|
# HarmonyOS / DevEco common outputs
|
||||||
.local/
|
.local/
|
||||||
.cache/
|
.cache/
|
||||||
|
local.properties
|
||||||
|
AppScope/*.p12
|
||||||
|
AppScope/*.mobileprovision
|
||||||
|
|
||||||
# Logs
|
# Logs
|
||||||
*.log
|
*.log
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"app": {
|
||||||
|
"bundleName": "com.xiaobai.mrpsimulator",
|
||||||
|
"vendor": "xiaobai",
|
||||||
|
"versionCode": 1000000,
|
||||||
|
"versionName": "1.0.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,53 +1,110 @@
|
|||||||
# MRP Simulator HarmonyOS
|
# MRP Simulator HarmonyOS
|
||||||
|
|
||||||
MRP 模拟器鸿蒙化项目。
|
HarmonyOS 侧的 MRP 模拟器 POC/Alpha 工程。
|
||||||
|
|
||||||
当前目标不是直接做“大而全”的正式产品,而是先完成一轮 **HarmonyOS 技术验证 / POC**,验证现有 MRP 模拟器能力是否能在鸿蒙侧形成稳定闭环。
|
当前代码状态不是“纯方案仓库”,而是已经包含:
|
||||||
|
- **标准 HarmonyOS/DevEco 工程壳**
|
||||||
|
- **ArkTS 壳层页面与运行页占位链路**
|
||||||
|
- **Native/NAPI/C++ 最小骨架**
|
||||||
|
- **RunPage -> Native smoke start -> pullFrame() 占位渲染** 的首轮联调路径
|
||||||
|
|
||||||
## 当前阶段
|
---
|
||||||
|
|
||||||
处于 **第一阶段:方案收敛 + 技术验证准备**。
|
## 当前仓库结构(最小可导入)
|
||||||
|
|
||||||
当前共识:
|
|
||||||
- 一期按 **POC / Alpha** 推进
|
|
||||||
- 先做 **单实例、本地导入、可启动、可渲染、可输入、可退出、可存档**
|
|
||||||
- 推荐路线:
|
|
||||||
- **ArkTS 做应用壳/UI**
|
|
||||||
- **C++ 做模拟器核心**
|
|
||||||
- **NAPI 做粗粒度桥接**
|
|
||||||
- 服务端/BFF 暂不进入运行时闭环,只在后续按需参与外围能力
|
|
||||||
|
|
||||||
## 目录说明
|
|
||||||
|
|
||||||
```text
|
```text
|
||||||
.
|
.
|
||||||
├─ docs/
|
├─ AppScope/
|
||||||
│ ├─ project/
|
│ └─ app.json5
|
||||||
│ ├─ product/
|
├─ build-profile.json5
|
||||||
│ ├─ architecture/
|
├─ hvigorfile.ts
|
||||||
│ ├─ harmonyos/
|
├─ hvigorw
|
||||||
│ └─ qa/
|
├─ hvigorw.bat
|
||||||
├─ research/
|
├─ local.properties.example
|
||||||
├─ prototypes/
|
├─ oh-package.json5
|
||||||
└─ scripts/
|
├─ entry/
|
||||||
|
│ ├─ build-profile.json5
|
||||||
|
│ ├─ oh-package.json5
|
||||||
|
│ └─ src/main/
|
||||||
|
│ ├─ module.json5
|
||||||
|
│ ├─ ets/
|
||||||
|
│ ├─ cpp/
|
||||||
|
│ └─ resources/
|
||||||
|
└─ README.md
|
||||||
```
|
```
|
||||||
|
|
||||||
## 当前文档
|
---
|
||||||
|
|
||||||
- 项目链路:`docs/project/AGENT_CHAIN.md`
|
## 先说明 3 个容易误解的点
|
||||||
- 项目概览:`docs/project/PROJECT_OVERVIEW.md`
|
|
||||||
- 一期范围:`docs/product/MVP_SCOPE.md`
|
|
||||||
- 第一轮架构判断:`docs/architecture/ARCHITECTURE_V1.md`
|
|
||||||
- 鸿蒙技术路线:`docs/harmonyos/HARMONYOS_TECH_ROUTE_V1.md`
|
|
||||||
- 下一步行动项:`docs/project/NEXT_ACTIONS.md`
|
|
||||||
|
|
||||||
## 下一步
|
### 1. `local.properties`
|
||||||
|
这是**本地机器文件**,不应提交真实值进仓库。
|
||||||
|
仓库提供了:
|
||||||
|
- `local.properties.example`
|
||||||
|
|
||||||
1. 明确现有 MRP 模拟器代码资产与语言栈
|
你需要自己复制一份:
|
||||||
2. 识别可复用核心与必须重写部分
|
|
||||||
3. 建立 HarmonyOS POC 工程骨架
|
|
||||||
4. 选定首批样例集并形成验证基线
|
|
||||||
|
|
||||||
## 状态说明
|
```bash
|
||||||
|
cp local.properties.example local.properties
|
||||||
|
```
|
||||||
|
|
||||||
当前仓库以 **方案与技术验证文档** 为主,代码实现将在明确现有内核资产后逐步落地。
|
然后把 `hwsdk.dir` 改成你本机 HarmonyOS SDK 路径。
|
||||||
|
|
||||||
|
### 2. 签名文件
|
||||||
|
仓库**不再引用**不存在的:
|
||||||
|
- `AppScope/debug.p12`
|
||||||
|
- `AppScope/debug.mobileprovision`
|
||||||
|
|
||||||
|
原因:这些是本地/团队环境相关文件,硬编码到仓库会直接阻塞初始化。
|
||||||
|
|
||||||
|
### 3. `hvigorw` / `hvigorw.bat`
|
||||||
|
已补入仓库。它们会优先调用:
|
||||||
|
- 本地 `node_modules/.bin/hvigor`
|
||||||
|
- 或系统中的 `hvigor`
|
||||||
|
|
||||||
|
如果你的环境里还没有 `hvigor`,先用 DevEco Studio 打开项目同步,或自行安装 hvigor。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 初始化步骤(可复现)
|
||||||
|
|
||||||
|
### 方式 A:DevEco Studio 导入(推荐)
|
||||||
|
1. 克隆仓库
|
||||||
|
2. 复制模板:`local.properties.example -> local.properties`
|
||||||
|
3. 修改 `local.properties` 中的 `hwsdk.dir`
|
||||||
|
4. 用 DevEco Studio 打开**仓库根目录**
|
||||||
|
5. 等待工程同步完成
|
||||||
|
6. 如需构建/运行,在 DevEco 中补本地调试签名配置
|
||||||
|
|
||||||
|
### 方式 B:命令行初始化
|
||||||
|
前提:本机已具备 `node` 和 `hvigor`
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cp local.properties.example local.properties
|
||||||
|
# 编辑 local.properties,填入 hwsdk.dir
|
||||||
|
./hvigorw tasks
|
||||||
|
```
|
||||||
|
|
||||||
|
如果 `./hvigorw` 提示找不到 `hvigor`,先回到方式 A,用 DevEco 完成首次同步。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 当前可验证结果
|
||||||
|
|
||||||
|
当前工程已具备以下最小可验证链路:
|
||||||
|
- `EntryAbility` 可加载 `ShellRootPage`
|
||||||
|
- 运行页可进入 native smoke 启动路径
|
||||||
|
- `pullFrame()` 已接到 ArkTS 层
|
||||||
|
- 页面可显示测试帧元数据与测试占位渲染块
|
||||||
|
|
||||||
|
这意味着:
|
||||||
|
- **可以导入工程**
|
||||||
|
- **可以继续做 Native/NAPI 联调**
|
||||||
|
- 但**还不是完整可运行的 MRP 模拟器产品**
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 下一阶段重点
|
||||||
|
- 把 `pullFrame()` 的占位帧替换为真实 native 帧
|
||||||
|
- 把 `loadPackage(appId)` 替换为真实 MRP 包路径/入口
|
||||||
|
- 把输入映射从 smoke path 替换为真实内核事件分发
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
# SETUP
|
||||||
|
|
||||||
|
## 目标
|
||||||
|
让别人拿到仓库后,能按固定步骤完成:
|
||||||
|
- 初始化项目
|
||||||
|
- 导入 DevEco Studio
|
||||||
|
- 继续做 ArkTS + Native/NAPI 联调
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 1. 准备本地文件
|
||||||
|
仓库不提交真实 `local.properties`,请自行复制:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cp local.properties.example local.properties
|
||||||
|
```
|
||||||
|
|
||||||
|
然后修改:
|
||||||
|
|
||||||
|
```properties
|
||||||
|
hwsdk.dir=/absolute/path/to/HarmonyOS/Sdk
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 2. 导入 DevEco Studio
|
||||||
|
- 打开仓库根目录:`mrp-simulator-harmonyos`
|
||||||
|
- 等待工程同步
|
||||||
|
- 若 IDE 提示补全依赖/构建环境,按 IDE 引导完成
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 3. 关于签名
|
||||||
|
当前仓库已移除对不存在签名文件的硬引用。
|
||||||
|
|
||||||
|
如果你要实际构建/运行:
|
||||||
|
- 在 DevEco 中配置本地 debug signing
|
||||||
|
- 或按团队规范补本地签名材料
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 4. 关于 hvigorw
|
||||||
|
仓库已提供:
|
||||||
|
- `hvigorw`
|
||||||
|
- `hvigorw.bat`
|
||||||
|
|
||||||
|
如果本机还没有 `hvigor`:
|
||||||
|
- 先用 DevEco Studio 打开并同步
|
||||||
|
- 或自行安装 hvigor 后再执行命令行任务
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 5. 最小自检清单
|
||||||
|
导入后至少确认:
|
||||||
|
- 根目录可识别为 HarmonyOS 工程
|
||||||
|
- `entry` 模块可识别
|
||||||
|
- `entry/src/main/ets` 存在
|
||||||
|
- `entry/src/main/cpp` 存在
|
||||||
|
- `entry/src/main/resources` 存在
|
||||||
|
- `EntryAbility` 与 `ShellRootPage` 可被 IDE 正常索引
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
{
|
||||||
|
"app": {
|
||||||
|
"products": [
|
||||||
|
{
|
||||||
|
"name": "default",
|
||||||
|
"compatibleSdkVersion": "5.0.0(12)",
|
||||||
|
"runtimeOS": "HarmonyOS"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"buildModeSet": [
|
||||||
|
{
|
||||||
|
"name": "debug"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "release"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"modules": [
|
||||||
|
{
|
||||||
|
"name": "entry",
|
||||||
|
"srcPath": "./entry",
|
||||||
|
"targets": [
|
||||||
|
{
|
||||||
|
"name": "default",
|
||||||
|
"applyToProducts": [
|
||||||
|
"default"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,82 @@
|
|||||||
|
# ArkTS 壳层最小可演示闭环说明 v1
|
||||||
|
|
||||||
|
项目:mrp-simulator-harmonyos
|
||||||
|
|
||||||
|
## 1. 运行入口在哪里
|
||||||
|
|
||||||
|
运行入口在:
|
||||||
|
- `entry/src/main/ets/pages/ShellRootPage.ets`
|
||||||
|
- `entry/src/main/ets/pages/AppListPage.ets`
|
||||||
|
|
||||||
|
当前可见入口:
|
||||||
|
1. App 启动进入 `ShellRootPage`
|
||||||
|
2. 默认路由进入 `AppListPage`
|
||||||
|
3. 用户点击 **“可运行”应用卡片**
|
||||||
|
4. 通过 `onNavigateRun(appId)` 切到 `RunPage`
|
||||||
|
|
||||||
|
## 2. 页面流如何走
|
||||||
|
|
||||||
|
当前最小页面流:
|
||||||
|
- `AppListPage -> ImportPage -> AppListPage`
|
||||||
|
- `AppListPage -> RunPage -> AppListPage`
|
||||||
|
|
||||||
|
具体链路:
|
||||||
|
1. **列表页**
|
||||||
|
- 展示应用列表
|
||||||
|
- 展示运行入口提示
|
||||||
|
- 点击“导入应用”进入 `ImportPage`
|
||||||
|
- 点击“可运行”卡片进入 `RunPage`
|
||||||
|
2. **导入页**
|
||||||
|
- 选择文件
|
||||||
|
- 展示预览
|
||||||
|
- 点击“开始导入”
|
||||||
|
- 导入成功后返回列表页
|
||||||
|
- 返回列表页时触发列表刷新 token
|
||||||
|
3. **运行页**
|
||||||
|
- 进入时根据 `appId` 发起 `startSession(appId)`
|
||||||
|
- 状态从 `starting -> running`
|
||||||
|
- 点击退出后回到列表页
|
||||||
|
|
||||||
|
## 3. 哪些接口已经为 NAPI 预留
|
||||||
|
|
||||||
|
### 3.1 App 列表相关
|
||||||
|
- `entry/src/main/ets/adapters/NativeAppAdapter.ts`
|
||||||
|
- `listInstalledApps()`
|
||||||
|
|
||||||
|
### 3.2 导入相关
|
||||||
|
- `entry/src/main/ets/adapters/NativeImportAdapter.ts`
|
||||||
|
- `pickFile()`
|
||||||
|
- `inspectPackage(fileUri)`
|
||||||
|
- `importPackage(fileUri)`
|
||||||
|
|
||||||
|
### 3.3 运行时相关
|
||||||
|
- `entry/src/main/ets/adapters/NativeRuntimeAdapter.ts`
|
||||||
|
- `startSession(appId)`
|
||||||
|
- `restartSession(appId)`
|
||||||
|
- `stopSession()`
|
||||||
|
- `notifyPageShow()`
|
||||||
|
- `notifyPageHide()`
|
||||||
|
|
||||||
|
### 3.4 Service 收口层
|
||||||
|
- `entry/src/main/ets/services/AppService.ts`
|
||||||
|
- `entry/src/main/ets/services/ImportService.ts`
|
||||||
|
- `entry/src/main/ets/services/RuntimeService.ts`
|
||||||
|
|
||||||
|
说明:
|
||||||
|
- 后续 NAPI 接入时,优先替换 Adapter 内部实现
|
||||||
|
- 页面层和 Store 层不直接碰 native 细节
|
||||||
|
|
||||||
|
## 4. 当前可见结果
|
||||||
|
|
||||||
|
当前已经具备:
|
||||||
|
- 列表页可见运行入口与导入入口
|
||||||
|
- 导入成功后返回列表并刷新
|
||||||
|
- 运行页可见 `starting / running / stopped` 状态展示
|
||||||
|
- 运行页工具栏根据状态控制按钮可用性
|
||||||
|
|
||||||
|
## 5. 本轮不做的事
|
||||||
|
|
||||||
|
本轮不继续扩大量新页面/组件,只收口:
|
||||||
|
- 现有页面可见闭环
|
||||||
|
- 现有 Adapter/NAPI 接缝
|
||||||
|
- 现有运行入口与状态提示
|
||||||
@@ -13,6 +13,31 @@ MRP 模拟器鸿蒙化
|
|||||||
|
|
||||||
## HarmonyOS Senior Engineer Backlog
|
## HarmonyOS Senior Engineer Backlog
|
||||||
|
|
||||||
|
### HOS-PRIO-001 Native/NAPI/C++ 最小工程骨架(最高优先级)
|
||||||
|
交付:
|
||||||
|
- 实际目录进入主仓库:
|
||||||
|
- `entry/src/main/cpp/`
|
||||||
|
- `entry/src/main/cpp/napi/`
|
||||||
|
- `entry/src/main/cpp/runtime/`
|
||||||
|
- `entry/src/main/cpp/platform/`
|
||||||
|
- `entry/src/main/cpp/render/`
|
||||||
|
- `entry/src/main/cpp/input/`
|
||||||
|
- 最小文件骨架进入主仓库:
|
||||||
|
- `CMakeLists.txt`
|
||||||
|
- `module_init.cpp`
|
||||||
|
- `facade_binding.cpp`
|
||||||
|
- `MrpFacade.h/.cpp`
|
||||||
|
- `MrpRuntime.h/.cpp`
|
||||||
|
- `FrameBuffer.h/.cpp`
|
||||||
|
- `InputEvent.h`
|
||||||
|
- `InputDispatcher.cpp`
|
||||||
|
- 必须 **直接 commit + push 到 main**
|
||||||
|
|
||||||
|
规则:
|
||||||
|
- 这项优先级高于文档补充
|
||||||
|
- 先把 native 骨架推进仓库,再补解释文档
|
||||||
|
- 不允许继续只产出文档、不产出 native 目录和文件
|
||||||
|
|
||||||
### HOS-001 POC 文件级骨架清单
|
### HOS-001 POC 文件级骨架清单
|
||||||
交付:
|
交付:
|
||||||
- ArkTS 侧骨架文件清单
|
- ArkTS 侧骨架文件清单
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"apiType": "stageMode",
|
||||||
|
"buildOption": {
|
||||||
|
"externalNativeOptions": {
|
||||||
|
"path": "src/main/cpp/CMakeLists.txt",
|
||||||
|
"arguments": "",
|
||||||
|
"cppFlags": "-std=c++17"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"targets": [
|
||||||
|
{
|
||||||
|
"name": "default",
|
||||||
|
"runtimeOS": "HarmonyOS"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
import { hapTasks } from '@ohos/hvigor-ohos-plugin';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
system: hapTasks,
|
||||||
|
plugins: []
|
||||||
|
};
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"modelVersion": "5.0.0",
|
||||||
|
"name": "entry",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "Entry module for MRP simulator HarmonyOS app",
|
||||||
|
"dependencies": {}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.5)
|
||||||
|
project(mrp_napi)
|
||||||
|
|
||||||
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
|
||||||
|
add_library(mrp_napi SHARED
|
||||||
|
napi/module_init.cpp
|
||||||
|
napi/facade_binding.cpp
|
||||||
|
platform/MrpFacade.cpp
|
||||||
|
runtime/MrpRuntime.cpp
|
||||||
|
render/FrameBuffer.cpp
|
||||||
|
input/InputDispatcher.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
target_include_directories(mrp_napi PRIVATE
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/platform
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/runtime
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/render
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/input
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/napi
|
||||||
|
)
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
#include "InputEvent.h"
|
||||||
|
|
||||||
|
bool DispatchInput(const MrpInputEvent &event)
|
||||||
|
{
|
||||||
|
(void)event;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
#ifndef MRP_INPUT_INPUT_EVENT_H
|
||||||
|
#define MRP_INPUT_INPUT_EVENT_H
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
struct MrpInputEvent {
|
||||||
|
std::string type = "key";
|
||||||
|
std::string action = "down";
|
||||||
|
int32_t keyCode = 0;
|
||||||
|
int32_t x = 0;
|
||||||
|
int32_t y = 0;
|
||||||
|
int64_t timestamp = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
bool DispatchInput(const MrpInputEvent &event);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,224 @@
|
|||||||
|
#include <node_api.h>
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "../input/InputEvent.h"
|
||||||
|
#include "../platform/MrpFacade.h"
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
MrpFacade g_facade;
|
||||||
|
|
||||||
|
napi_value MakeString(napi_env env, const std::string &value)
|
||||||
|
{
|
||||||
|
napi_value result;
|
||||||
|
napi_create_string_utf8(env, value.c_str(), value.size(), &result);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
napi_value MakeCommonResult(napi_env env, const CommonResult &result)
|
||||||
|
{
|
||||||
|
napi_value obj;
|
||||||
|
napi_create_object(env, &obj);
|
||||||
|
|
||||||
|
napi_value ok;
|
||||||
|
napi_get_boolean(env, result.ok, &ok);
|
||||||
|
napi_set_named_property(env, obj, "ok", ok);
|
||||||
|
|
||||||
|
napi_value errorCode;
|
||||||
|
napi_create_int32(env, result.errorCode, &errorCode);
|
||||||
|
napi_set_named_property(env, obj, "errorCode", errorCode);
|
||||||
|
|
||||||
|
napi_set_named_property(env, obj, "errorMessage", MakeString(env, result.errorMessage));
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string GetStringProperty(napi_env env, napi_value obj, const char *name, const std::string &fallback)
|
||||||
|
{
|
||||||
|
bool hasProperty = false;
|
||||||
|
napi_has_named_property(env, obj, name, &hasProperty);
|
||||||
|
if (!hasProperty) {
|
||||||
|
return fallback;
|
||||||
|
}
|
||||||
|
|
||||||
|
napi_value value;
|
||||||
|
napi_get_named_property(env, obj, name, &value);
|
||||||
|
size_t length = 0;
|
||||||
|
napi_get_value_string_utf8(env, value, nullptr, 0, &length);
|
||||||
|
std::string result(length, '\0');
|
||||||
|
napi_get_value_string_utf8(env, value, result.data(), length + 1, &length);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t GetIntProperty(napi_env env, napi_value obj, const char *name, int32_t fallback)
|
||||||
|
{
|
||||||
|
bool hasProperty = false;
|
||||||
|
napi_has_named_property(env, obj, name, &hasProperty);
|
||||||
|
if (!hasProperty) {
|
||||||
|
return fallback;
|
||||||
|
}
|
||||||
|
|
||||||
|
napi_value value;
|
||||||
|
napi_get_named_property(env, obj, name, &value);
|
||||||
|
int32_t result = fallback;
|
||||||
|
napi_get_value_int32(env, value, &result);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GetBoolProperty(napi_env env, napi_value obj, const char *name, bool fallback)
|
||||||
|
{
|
||||||
|
bool hasProperty = false;
|
||||||
|
napi_has_named_property(env, obj, name, &hasProperty);
|
||||||
|
if (!hasProperty) {
|
||||||
|
return fallback;
|
||||||
|
}
|
||||||
|
|
||||||
|
napi_value value;
|
||||||
|
napi_get_named_property(env, obj, name, &value);
|
||||||
|
bool result = fallback;
|
||||||
|
napi_get_value_bool(env, value, &result);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
napi_value Init(napi_env env, napi_callback_info info)
|
||||||
|
{
|
||||||
|
size_t argc = 1;
|
||||||
|
napi_value argv[1] = {nullptr};
|
||||||
|
napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||||
|
|
||||||
|
InitOptions options;
|
||||||
|
if (argc == 1 && argv[0] != nullptr) {
|
||||||
|
options.workDir = GetStringProperty(env, argv[0], "workDir", "");
|
||||||
|
options.width = GetIntProperty(env, argv[0], "width", 240);
|
||||||
|
options.height = GetIntProperty(env, argv[0], "height", 320);
|
||||||
|
options.debug = GetBoolProperty(env, argv[0], "debug", false);
|
||||||
|
}
|
||||||
|
|
||||||
|
return MakeCommonResult(env, g_facade.Init(options));
|
||||||
|
}
|
||||||
|
|
||||||
|
napi_value LoadPackage(napi_env env, napi_callback_info info)
|
||||||
|
{
|
||||||
|
size_t argc = 1;
|
||||||
|
napi_value argv[1] = {nullptr};
|
||||||
|
napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||||
|
|
||||||
|
std::string packagePath;
|
||||||
|
if (argc == 1 && argv[0] != nullptr) {
|
||||||
|
size_t length = 0;
|
||||||
|
napi_get_value_string_utf8(env, argv[0], nullptr, 0, &length);
|
||||||
|
packagePath.resize(length);
|
||||||
|
napi_get_value_string_utf8(env, argv[0], packagePath.data(), length + 1, &length);
|
||||||
|
}
|
||||||
|
|
||||||
|
return MakeCommonResult(env, g_facade.LoadPackage(packagePath));
|
||||||
|
}
|
||||||
|
|
||||||
|
napi_value Start(napi_env env, napi_callback_info info)
|
||||||
|
{
|
||||||
|
(void)info;
|
||||||
|
return MakeCommonResult(env, g_facade.Start());
|
||||||
|
}
|
||||||
|
|
||||||
|
napi_value Pause(napi_env env, napi_callback_info info)
|
||||||
|
{
|
||||||
|
(void)info;
|
||||||
|
return MakeCommonResult(env, g_facade.Pause());
|
||||||
|
}
|
||||||
|
|
||||||
|
napi_value Resume(napi_env env, napi_callback_info info)
|
||||||
|
{
|
||||||
|
(void)info;
|
||||||
|
return MakeCommonResult(env, g_facade.Resume());
|
||||||
|
}
|
||||||
|
|
||||||
|
napi_value SendInput(napi_env env, napi_callback_info info)
|
||||||
|
{
|
||||||
|
size_t argc = 1;
|
||||||
|
napi_value argv[1] = {nullptr};
|
||||||
|
napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||||
|
|
||||||
|
MrpInputEvent event;
|
||||||
|
if (argc == 1 && argv[0] != nullptr) {
|
||||||
|
event.type = GetStringProperty(env, argv[0], "type", "key");
|
||||||
|
event.action = GetStringProperty(env, argv[0], "action", "down");
|
||||||
|
event.keyCode = GetIntProperty(env, argv[0], "keyCode", 0);
|
||||||
|
event.x = GetIntProperty(env, argv[0], "x", 0);
|
||||||
|
event.y = GetIntProperty(env, argv[0], "y", 0);
|
||||||
|
event.timestamp = static_cast<int64_t>(GetIntProperty(env, argv[0], "timestamp", 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
return MakeCommonResult(env, g_facade.SendInput(event));
|
||||||
|
}
|
||||||
|
|
||||||
|
napi_value PullFrame(napi_env env, napi_callback_info info)
|
||||||
|
{
|
||||||
|
(void)info;
|
||||||
|
FrameResult frame = g_facade.PullFrame();
|
||||||
|
|
||||||
|
napi_value obj;
|
||||||
|
napi_create_object(env, &obj);
|
||||||
|
|
||||||
|
napi_value ok;
|
||||||
|
napi_get_boolean(env, frame.ok, &ok);
|
||||||
|
napi_set_named_property(env, obj, "ok", ok);
|
||||||
|
|
||||||
|
napi_value hasNewFrame;
|
||||||
|
napi_get_boolean(env, frame.hasNewFrame, &hasNewFrame);
|
||||||
|
napi_set_named_property(env, obj, "hasNewFrame", hasNewFrame);
|
||||||
|
|
||||||
|
napi_value width;
|
||||||
|
napi_create_int32(env, frame.width, &width);
|
||||||
|
napi_set_named_property(env, obj, "width", width);
|
||||||
|
|
||||||
|
napi_value height;
|
||||||
|
napi_create_int32(env, frame.height, &height);
|
||||||
|
napi_set_named_property(env, obj, "height", height);
|
||||||
|
|
||||||
|
napi_set_named_property(env, obj, "pixelFormat", MakeString(env, frame.pixelFormat));
|
||||||
|
|
||||||
|
void *data = nullptr;
|
||||||
|
napi_value buffer;
|
||||||
|
napi_create_arraybuffer(env, frame.buffer.size(), &data, &buffer);
|
||||||
|
if (data != nullptr && !frame.buffer.empty()) {
|
||||||
|
std::memcpy(data, frame.buffer.data(), frame.buffer.size());
|
||||||
|
}
|
||||||
|
napi_set_named_property(env, obj, "buffer", buffer);
|
||||||
|
|
||||||
|
napi_value frameId;
|
||||||
|
napi_create_int64(env, frame.frameId, &frameId);
|
||||||
|
napi_set_named_property(env, obj, "frameId", frameId);
|
||||||
|
|
||||||
|
napi_value errorCode;
|
||||||
|
napi_create_int32(env, frame.errorCode, &errorCode);
|
||||||
|
napi_set_named_property(env, obj, "errorCode", errorCode);
|
||||||
|
|
||||||
|
napi_set_named_property(env, obj, "errorMessage", MakeString(env, frame.errorMessage));
|
||||||
|
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
napi_value Release(napi_env env, napi_callback_info info)
|
||||||
|
{
|
||||||
|
(void)info;
|
||||||
|
return MakeCommonResult(env, g_facade.Release());
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
napi_value ExportMrpFacade(napi_env env, napi_value exports)
|
||||||
|
{
|
||||||
|
napi_property_descriptor descriptors[] = {
|
||||||
|
{"init", nullptr, Init, nullptr, nullptr, nullptr, napi_default, nullptr},
|
||||||
|
{"loadPackage", nullptr, LoadPackage, nullptr, nullptr, nullptr, napi_default, nullptr},
|
||||||
|
{"start", nullptr, Start, nullptr, nullptr, nullptr, napi_default, nullptr},
|
||||||
|
{"pause", nullptr, Pause, nullptr, nullptr, nullptr, napi_default, nullptr},
|
||||||
|
{"resume", nullptr, Resume, nullptr, nullptr, nullptr, napi_default, nullptr},
|
||||||
|
{"sendInput", nullptr, SendInput, nullptr, nullptr, nullptr, napi_default, nullptr},
|
||||||
|
{"pullFrame", nullptr, PullFrame, nullptr, nullptr, nullptr, napi_default, nullptr},
|
||||||
|
{"release", nullptr, Release, nullptr, nullptr, nullptr, napi_default, nullptr},
|
||||||
|
};
|
||||||
|
|
||||||
|
napi_define_properties(env, exports, sizeof(descriptors) / sizeof(descriptors[0]), descriptors);
|
||||||
|
return exports;
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
#include <node_api.h>
|
||||||
|
|
||||||
|
napi_value ExportMrpFacade(napi_env env, napi_value exports);
|
||||||
|
|
||||||
|
static napi_value InitModule(napi_env env, napi_value exports)
|
||||||
|
{
|
||||||
|
return ExportMrpFacade(env, exports);
|
||||||
|
}
|
||||||
|
|
||||||
|
static napi_module g_mrpModule = {
|
||||||
|
1,
|
||||||
|
0,
|
||||||
|
nullptr,
|
||||||
|
InitModule,
|
||||||
|
"mrp_napi",
|
||||||
|
nullptr,
|
||||||
|
{0},
|
||||||
|
};
|
||||||
|
|
||||||
|
extern "C" __attribute__((constructor)) void RegisterMrpModule(void)
|
||||||
|
{
|
||||||
|
napi_module_register(&g_mrpModule);
|
||||||
|
}
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
#include "MrpFacade.h"
|
||||||
|
|
||||||
|
#include "../render/FrameBuffer.h"
|
||||||
|
#include "../runtime/MrpRuntime.h"
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
MrpRuntime g_runtime;
|
||||||
|
}
|
||||||
|
|
||||||
|
CommonResult MrpFacade::Init(const InitOptions &options)
|
||||||
|
{
|
||||||
|
options_ = options;
|
||||||
|
return g_runtime.Init(options.width, options.height, options.debug);
|
||||||
|
}
|
||||||
|
|
||||||
|
CommonResult MrpFacade::LoadPackage(const std::string &packagePath)
|
||||||
|
{
|
||||||
|
packagePath_ = packagePath;
|
||||||
|
return g_runtime.LoadPackage(packagePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
CommonResult MrpFacade::Start()
|
||||||
|
{
|
||||||
|
return g_runtime.Start();
|
||||||
|
}
|
||||||
|
|
||||||
|
CommonResult MrpFacade::Pause()
|
||||||
|
{
|
||||||
|
return g_runtime.Pause();
|
||||||
|
}
|
||||||
|
|
||||||
|
CommonResult MrpFacade::Resume()
|
||||||
|
{
|
||||||
|
return g_runtime.Resume();
|
||||||
|
}
|
||||||
|
|
||||||
|
CommonResult MrpFacade::SendInput(const MrpInputEvent &event)
|
||||||
|
{
|
||||||
|
DispatchInput(event);
|
||||||
|
return CommonResult{true, 0, ""};
|
||||||
|
}
|
||||||
|
|
||||||
|
FrameResult MrpFacade::PullFrame()
|
||||||
|
{
|
||||||
|
FrameBuffer frameBuffer(g_runtime.Width(), g_runtime.Height());
|
||||||
|
frameBuffer.FillTestPattern(g_runtime.NextFrameId());
|
||||||
|
|
||||||
|
FrameResult result;
|
||||||
|
result.ok = true;
|
||||||
|
result.hasNewFrame = true;
|
||||||
|
result.width = g_runtime.Width();
|
||||||
|
result.height = g_runtime.Height();
|
||||||
|
result.pixelFormat = "RGBA_8888";
|
||||||
|
result.buffer = frameBuffer.Data();
|
||||||
|
result.frameId = g_runtime.CurrentFrameId();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
CommonResult MrpFacade::Release()
|
||||||
|
{
|
||||||
|
packagePath_.clear();
|
||||||
|
return g_runtime.Release();
|
||||||
|
}
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
#ifndef MRP_PLATFORM_MRP_FACADE_H
|
||||||
|
#define MRP_PLATFORM_MRP_FACADE_H
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "../input/InputEvent.h"
|
||||||
|
|
||||||
|
struct InitOptions {
|
||||||
|
std::string workDir;
|
||||||
|
int32_t width = 240;
|
||||||
|
int32_t height = 320;
|
||||||
|
bool debug = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct CommonResult {
|
||||||
|
bool ok = false;
|
||||||
|
int32_t errorCode = 0;
|
||||||
|
std::string errorMessage;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct FrameResult {
|
||||||
|
bool ok = false;
|
||||||
|
bool hasNewFrame = false;
|
||||||
|
int32_t width = 0;
|
||||||
|
int32_t height = 0;
|
||||||
|
std::string pixelFormat = "RGBA_8888";
|
||||||
|
std::vector<uint8_t> buffer;
|
||||||
|
int64_t frameId = 0;
|
||||||
|
int32_t errorCode = 0;
|
||||||
|
std::string errorMessage;
|
||||||
|
};
|
||||||
|
|
||||||
|
class MrpFacade {
|
||||||
|
public:
|
||||||
|
CommonResult Init(const InitOptions &options);
|
||||||
|
CommonResult LoadPackage(const std::string &packagePath);
|
||||||
|
CommonResult Start();
|
||||||
|
CommonResult Pause();
|
||||||
|
CommonResult Resume();
|
||||||
|
CommonResult SendInput(const MrpInputEvent &event);
|
||||||
|
FrameResult PullFrame();
|
||||||
|
CommonResult Release();
|
||||||
|
|
||||||
|
private:
|
||||||
|
InitOptions options_;
|
||||||
|
std::string packagePath_;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
#include "FrameBuffer.h"
|
||||||
|
|
||||||
|
FrameBuffer::FrameBuffer(int32_t width, int32_t height)
|
||||||
|
: width_(width), height_(height), rgba_(static_cast<size_t>(width) * static_cast<size_t>(height) * 4U, 0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void FrameBuffer::FillTestPattern(int64_t frameId)
|
||||||
|
{
|
||||||
|
for (int32_t y = 0; y < height_; ++y) {
|
||||||
|
for (int32_t x = 0; x < width_; ++x) {
|
||||||
|
const size_t index = static_cast<size_t>(y * width_ + x) * 4U;
|
||||||
|
rgba_[index] = static_cast<uint8_t>((x + frameId) % 255);
|
||||||
|
rgba_[index + 1] = static_cast<uint8_t>((y + frameId) % 255);
|
||||||
|
rgba_[index + 2] = static_cast<uint8_t>((x + y) % 255);
|
||||||
|
rgba_[index + 3] = 255;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::vector<uint8_t> &FrameBuffer::Data() const
|
||||||
|
{
|
||||||
|
return rgba_;
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
#ifndef MRP_RENDER_FRAME_BUFFER_H
|
||||||
|
#define MRP_RENDER_FRAME_BUFFER_H
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
class FrameBuffer {
|
||||||
|
public:
|
||||||
|
FrameBuffer(int32_t width, int32_t height);
|
||||||
|
|
||||||
|
void FillTestPattern(int64_t frameId);
|
||||||
|
const std::vector<uint8_t> &Data() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
int32_t width_;
|
||||||
|
int32_t height_;
|
||||||
|
std::vector<uint8_t> rgba_;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
#include "MrpRuntime.h"
|
||||||
|
|
||||||
|
CommonResult MrpRuntime::Init(int32_t width, int32_t height, bool debug)
|
||||||
|
{
|
||||||
|
width_ = width > 0 ? width : 240;
|
||||||
|
height_ = height > 0 ? height : 320;
|
||||||
|
debug_ = debug;
|
||||||
|
frameId_ = 0;
|
||||||
|
state_ = State::Initialized;
|
||||||
|
return CommonResult{true, 0, ""};
|
||||||
|
}
|
||||||
|
|
||||||
|
CommonResult MrpRuntime::LoadPackage(const std::string &packagePath)
|
||||||
|
{
|
||||||
|
if (state_ != State::Initialized && state_ != State::Released) {
|
||||||
|
return CommonResult{false, 1001, "runtime not initialized"};
|
||||||
|
}
|
||||||
|
(void)packagePath;
|
||||||
|
state_ = State::Loaded;
|
||||||
|
return CommonResult{true, 0, ""};
|
||||||
|
}
|
||||||
|
|
||||||
|
CommonResult MrpRuntime::Start()
|
||||||
|
{
|
||||||
|
if (state_ != State::Loaded && state_ != State::Paused) {
|
||||||
|
return CommonResult{false, 1002, "runtime not ready to start"};
|
||||||
|
}
|
||||||
|
state_ = State::Running;
|
||||||
|
return CommonResult{true, 0, ""};
|
||||||
|
}
|
||||||
|
|
||||||
|
CommonResult MrpRuntime::Pause()
|
||||||
|
{
|
||||||
|
if (state_ != State::Running) {
|
||||||
|
return CommonResult{false, 1003, "runtime not running"};
|
||||||
|
}
|
||||||
|
state_ = State::Paused;
|
||||||
|
return CommonResult{true, 0, ""};
|
||||||
|
}
|
||||||
|
|
||||||
|
CommonResult MrpRuntime::Resume()
|
||||||
|
{
|
||||||
|
if (state_ != State::Paused) {
|
||||||
|
return CommonResult{false, 1004, "runtime not paused"};
|
||||||
|
}
|
||||||
|
state_ = State::Running;
|
||||||
|
return CommonResult{true, 0, ""};
|
||||||
|
}
|
||||||
|
|
||||||
|
CommonResult MrpRuntime::Release()
|
||||||
|
{
|
||||||
|
state_ = State::Released;
|
||||||
|
frameId_ = 0;
|
||||||
|
return CommonResult{true, 0, ""};
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t MrpRuntime::Width() const
|
||||||
|
{
|
||||||
|
return width_;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t MrpRuntime::Height() const
|
||||||
|
{
|
||||||
|
return height_;
|
||||||
|
}
|
||||||
|
|
||||||
|
int64_t MrpRuntime::NextFrameId()
|
||||||
|
{
|
||||||
|
return ++frameId_;
|
||||||
|
}
|
||||||
|
|
||||||
|
int64_t MrpRuntime::CurrentFrameId() const
|
||||||
|
{
|
||||||
|
return frameId_;
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
#ifndef MRP_RUNTIME_MRP_RUNTIME_H
|
||||||
|
#define MRP_RUNTIME_MRP_RUNTIME_H
|
||||||
|
|
||||||
|
#include "../platform/MrpFacade.h"
|
||||||
|
|
||||||
|
class MrpRuntime {
|
||||||
|
public:
|
||||||
|
CommonResult Init(int32_t width, int32_t height, bool debug);
|
||||||
|
CommonResult LoadPackage(const std::string &packagePath);
|
||||||
|
CommonResult Start();
|
||||||
|
CommonResult Pause();
|
||||||
|
CommonResult Resume();
|
||||||
|
CommonResult Release();
|
||||||
|
|
||||||
|
int32_t Width() const;
|
||||||
|
int32_t Height() const;
|
||||||
|
int64_t NextFrameId();
|
||||||
|
int64_t CurrentFrameId() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
enum class State {
|
||||||
|
Idle,
|
||||||
|
Initialized,
|
||||||
|
Loaded,
|
||||||
|
Running,
|
||||||
|
Paused,
|
||||||
|
Released,
|
||||||
|
};
|
||||||
|
|
||||||
|
State state_ = State::Idle;
|
||||||
|
int32_t width_ = 240;
|
||||||
|
int32_t height_ = 320;
|
||||||
|
bool debug_ = false;
|
||||||
|
int64_t frameId_ = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -1,23 +1,59 @@
|
|||||||
const sleep = (ms: number): Promise<void> => new Promise((resolve) => setTimeout(resolve, ms))
|
import nativeMrp from 'libmrp_napi.so'
|
||||||
|
|
||||||
export class NativeRuntimeAdapter {
|
export interface NativeFrameDTO {
|
||||||
async startSession(_appId: string): Promise<void> {
|
ok: boolean
|
||||||
await sleep(600)
|
hasNewFrame: boolean
|
||||||
|
width: number
|
||||||
|
height: number
|
||||||
|
pixelFormat: 'RGBA_8888'
|
||||||
|
buffer?: ArrayBuffer
|
||||||
|
frameId?: number
|
||||||
|
errorCode?: number
|
||||||
|
errorMessage?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
async restartSession(_appId: string): Promise<void> {
|
function assertOk(result: { ok: boolean; errorCode?: number; errorMessage?: string }, action: string): void {
|
||||||
await sleep(400)
|
if (!result.ok) {
|
||||||
|
throw new Error(`${action} failed: ${result.errorCode ?? -1} ${result.errorMessage ?? ''}`.trim())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class NativeRuntimeAdapter {
|
||||||
|
async startSession(appId: string): Promise<void> {
|
||||||
|
assertOk(nativeMrp.init({
|
||||||
|
workDir: '/data/storage/el2/base/files/mrp',
|
||||||
|
width: 240,
|
||||||
|
height: 320,
|
||||||
|
debug: true,
|
||||||
|
}), 'init')
|
||||||
|
assertOk(nativeMrp.loadPackage(appId), 'loadPackage')
|
||||||
|
assertOk(nativeMrp.start(), 'start')
|
||||||
|
}
|
||||||
|
|
||||||
|
async restartSession(appId: string): Promise<void> {
|
||||||
|
await this.stopSession()
|
||||||
|
await this.startSession(appId)
|
||||||
}
|
}
|
||||||
|
|
||||||
async stopSession(): Promise<void> {
|
async stopSession(): Promise<void> {
|
||||||
return
|
assertOk(nativeMrp.release(), 'release')
|
||||||
|
}
|
||||||
|
|
||||||
|
async pullFrame(): Promise<NativeFrameDTO> {
|
||||||
|
return nativeMrp.pullFrame() as NativeFrameDTO
|
||||||
}
|
}
|
||||||
|
|
||||||
async notifyPageShow(): Promise<void> {
|
async notifyPageShow(): Promise<void> {
|
||||||
|
const result = nativeMrp.resume()
|
||||||
|
if (!result.ok) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async notifyPageHide(): Promise<void> {
|
async notifyPageHide(): Promise<void> {
|
||||||
|
const result = nativeMrp.pause()
|
||||||
|
if (!result.ok) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
import nativeMrp from 'libmrp_napi.so';
|
||||||
|
|
||||||
|
export function smokeTestNativeInit(): boolean {
|
||||||
|
const result = nativeMrp.init({
|
||||||
|
workDir: '/data/storage/el2/base/files/mrp',
|
||||||
|
width: 240,
|
||||||
|
height: 320,
|
||||||
|
debug: true,
|
||||||
|
});
|
||||||
|
return !!result?.ok;
|
||||||
|
}
|
||||||
@@ -1,10 +1,43 @@
|
|||||||
@Component
|
@Component
|
||||||
export struct RuntimeContainer {
|
export struct RuntimeContainer {
|
||||||
|
@Prop hint: string = 'Runtime Surface Placeholder'
|
||||||
|
@Prop hasFrame: boolean = false
|
||||||
|
@Prop frameId: number = 0
|
||||||
|
@Prop frameWidth: number = 0
|
||||||
|
@Prop frameHeight: number = 0
|
||||||
|
|
||||||
|
private frameColor(): string {
|
||||||
|
const palette: string[] = ['#DCEBFF', '#C6F6D5', '#FEEBC8', '#FED7E2', '#E9D8FD']
|
||||||
|
return this.hasFrame ? palette[this.frameId % palette.length] : '#F3F4F6'
|
||||||
|
}
|
||||||
|
|
||||||
build() {
|
build() {
|
||||||
|
Column({ space: 12 }) {
|
||||||
|
Text('MRP Runtime Surface Placeholder')
|
||||||
|
.fontSize(18)
|
||||||
|
.fontWeight(FontWeight.Medium)
|
||||||
|
Stack() {
|
||||||
Column() {
|
Column() {
|
||||||
Text('Runtime Surface Placeholder')
|
Text(this.hasFrame ? `测试帧 #${this.frameId}` : '尚未拉到测试帧')
|
||||||
|
.fontSize(18)
|
||||||
|
.fontWeight(FontWeight.Bold)
|
||||||
|
Text(this.hasFrame ? `${this.frameWidth} x ${this.frameHeight}` : '等待 pullFrame()')
|
||||||
|
.fontSize(14)
|
||||||
|
.fontColor('#666666')
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
.width('88%')
|
||||||
|
.aspectRatio(3 / 4)
|
||||||
|
.backgroundColor(this.frameColor())
|
||||||
|
.borderRadius(16)
|
||||||
|
.padding(16)
|
||||||
|
Text(this.hint)
|
||||||
|
.fontSize(14)
|
||||||
|
.fontColor('#666666')
|
||||||
|
}
|
||||||
|
.justifyContent(FlexAlign.Center)
|
||||||
|
.alignItems(HorizontalAlign.Center)
|
||||||
.width('100%')
|
.width('100%')
|
||||||
.height('100%')
|
.layoutWeight(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,7 +2,11 @@
|
|||||||
export struct RuntimeToolbar {
|
export struct RuntimeToolbar {
|
||||||
onBack?: () => void
|
onBack?: () => void
|
||||||
onRestart?: () => void
|
onRestart?: () => void
|
||||||
|
onPullFrame?: () => void
|
||||||
onExit?: () => void
|
onExit?: () => void
|
||||||
|
@Prop canRestart: boolean = true
|
||||||
|
@Prop canPullFrame: boolean = true
|
||||||
|
@Prop canExit: boolean = true
|
||||||
|
|
||||||
build() {
|
build() {
|
||||||
Row({ space: 12 }) {
|
Row({ space: 12 }) {
|
||||||
@@ -11,12 +15,23 @@ export struct RuntimeToolbar {
|
|||||||
this.onBack()
|
this.onBack()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
Button('重启').onClick(() => {
|
Button('重启')
|
||||||
|
.enabled(this.canRestart)
|
||||||
|
.onClick(() => {
|
||||||
if (this.onRestart) {
|
if (this.onRestart) {
|
||||||
this.onRestart()
|
this.onRestart()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
Button('退出').onClick(() => {
|
Button('拉帧')
|
||||||
|
.enabled(this.canPullFrame)
|
||||||
|
.onClick(() => {
|
||||||
|
if (this.onPullFrame) {
|
||||||
|
this.onPullFrame()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
Button('退出')
|
||||||
|
.enabled(this.canExit)
|
||||||
|
.onClick(() => {
|
||||||
if (this.onExit) {
|
if (this.onExit) {
|
||||||
this.onExit()
|
this.onExit()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import UIAbility from '@ohos.app.ability.UIAbility';
|
||||||
|
import window from '@ohos.window';
|
||||||
|
import hilog from '@ohos.hilog';
|
||||||
|
|
||||||
|
const DOMAIN = 0xFF00;
|
||||||
|
const TAG = 'EntryAbility';
|
||||||
|
|
||||||
|
export default class EntryAbility extends UIAbility {
|
||||||
|
onWindowStageCreate(windowStage: window.WindowStage): void {
|
||||||
|
windowStage.loadContent('pages/ShellRootPage', (err) => {
|
||||||
|
if (err.code) {
|
||||||
|
hilog.error(DOMAIN, TAG, 'Failed to load ShellRootPage: %{public}s', JSON.stringify(err));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
hilog.info(DOMAIN, TAG, 'ShellRootPage loaded');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
Vendored
+44
@@ -0,0 +1,44 @@
|
|||||||
|
declare module 'libmrp_napi.so' {
|
||||||
|
export function init(options: {
|
||||||
|
workDir: string;
|
||||||
|
width: number;
|
||||||
|
height: number;
|
||||||
|
debug?: boolean;
|
||||||
|
}): {
|
||||||
|
ok: boolean;
|
||||||
|
errorCode?: number;
|
||||||
|
errorMessage?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function loadPackage(packagePath: string): {
|
||||||
|
ok: boolean;
|
||||||
|
errorCode?: number;
|
||||||
|
errorMessage?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function start(): { ok: boolean; errorCode?: number; errorMessage?: string };
|
||||||
|
export function pause(): { ok: boolean; errorCode?: number; errorMessage?: string };
|
||||||
|
export function resume(): { ok: boolean; errorCode?: number; errorMessage?: string };
|
||||||
|
export function sendInput(event: {
|
||||||
|
type: 'key' | 'touch';
|
||||||
|
action: 'down' | 'up' | 'move';
|
||||||
|
keyCode?: number;
|
||||||
|
x?: number;
|
||||||
|
y?: number;
|
||||||
|
timestamp?: number;
|
||||||
|
}): { ok: boolean; errorCode?: number; errorMessage?: string };
|
||||||
|
|
||||||
|
export function pullFrame(): {
|
||||||
|
ok: boolean;
|
||||||
|
hasNewFrame: boolean;
|
||||||
|
width: number;
|
||||||
|
height: number;
|
||||||
|
pixelFormat: 'RGBA_8888';
|
||||||
|
buffer?: ArrayBuffer;
|
||||||
|
frameId?: number;
|
||||||
|
errorCode?: number;
|
||||||
|
errorMessage?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function release(): { ok: boolean; errorCode?: number; errorMessage?: string };
|
||||||
|
}
|
||||||
@@ -65,6 +65,7 @@ export struct AppListPage {
|
|||||||
Column() {
|
Column() {
|
||||||
Text(`${this.refreshTick}-${this.refreshToken}`).fontSize(1).opacity(0)
|
Text(`${this.refreshTick}-${this.refreshToken}`).fontSize(1).opacity(0)
|
||||||
PageHeader({ title: '应用列表' })
|
PageHeader({ title: '应用列表' })
|
||||||
|
StatusBanner({ text: '运行入口:点击“可运行”应用卡片进入运行页;导入入口:点击下方“导入应用”。' })
|
||||||
if (this.selectedAppId) {
|
if (this.selectedAppId) {
|
||||||
StatusBanner({ text: `已选择应用:${this.selectedAppId}` })
|
StatusBanner({ text: `已选择应用:${this.selectedAppId}` })
|
||||||
}
|
}
|
||||||
@@ -81,6 +82,7 @@ export struct AppListPage {
|
|||||||
items: this.store.items,
|
items: this.store.items,
|
||||||
onItemTap: (appId: string) => this.openRunPage(appId)
|
onItemTap: (appId: string) => this.openRunPage(appId)
|
||||||
})
|
})
|
||||||
|
ImportEntryButton({ onTap: () => this.openImportPage() })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.width('100%')
|
.width('100%')
|
||||||
|
|||||||
@@ -45,6 +45,10 @@ export struct RunPage {
|
|||||||
await this.store.restartSession()
|
await this.store.restartSession()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async onPullFrame(): Promise<void> {
|
||||||
|
await this.store.refreshFrame()
|
||||||
|
}
|
||||||
|
|
||||||
private async onExit(): Promise<void> {
|
private async onExit(): Promise<void> {
|
||||||
await this.store.stopSession()
|
await this.store.stopSession()
|
||||||
if (this.onBack) {
|
if (this.onBack) {
|
||||||
@@ -59,15 +63,26 @@ export struct RunPage {
|
|||||||
if (this.appId) {
|
if (this.appId) {
|
||||||
StatusBanner({ text: `当前应用:${this.appId}` })
|
StatusBanner({ text: `当前应用:${this.appId}` })
|
||||||
}
|
}
|
||||||
|
StatusBanner({ text: this.store.runtimeHint })
|
||||||
if (this.store.error) {
|
if (this.store.error) {
|
||||||
StatusBanner({ text: this.store.error.message })
|
StatusBanner({ text: this.store.error.message })
|
||||||
}
|
}
|
||||||
RuntimeToolbar({
|
RuntimeToolbar({
|
||||||
|
canRestart: this.store.canRestart,
|
||||||
|
canPullFrame: this.store.phase === 'running',
|
||||||
|
canExit: this.store.canExit,
|
||||||
onBack: () => this.onBackClick(),
|
onBack: () => this.onBackClick(),
|
||||||
onRestart: () => this.onRestart(),
|
onRestart: () => this.onRestart(),
|
||||||
|
onPullFrame: () => this.onPullFrame(),
|
||||||
onExit: () => this.onExit()
|
onExit: () => this.onExit()
|
||||||
})
|
})
|
||||||
RuntimeContainer()
|
RuntimeContainer({
|
||||||
|
hint: this.store.runtimeHint,
|
||||||
|
hasFrame: this.store.frame.hasFrame,
|
||||||
|
frameId: this.store.frame.frameId,
|
||||||
|
frameWidth: this.store.frame.width,
|
||||||
|
frameHeight: this.store.frame.height,
|
||||||
|
})
|
||||||
if (this.store.phase !== 'running') {
|
if (this.store.phase !== 'running') {
|
||||||
RuntimeStatusOverlay({ text: `当前状态:${this.store.phase}` })
|
RuntimeStatusOverlay({ text: `当前状态:${this.store.phase}` })
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,13 @@
|
|||||||
import { NativeRuntimeAdapter } from '../adapters/NativeRuntimeAdapter'
|
import { NativeRuntimeAdapter } from '../adapters/NativeRuntimeAdapter'
|
||||||
|
|
||||||
|
export interface RuntimeFrameVM {
|
||||||
|
hasFrame: boolean
|
||||||
|
width: number
|
||||||
|
height: number
|
||||||
|
frameId: number
|
||||||
|
pixelFormat: string
|
||||||
|
}
|
||||||
|
|
||||||
export class RuntimeService {
|
export class RuntimeService {
|
||||||
constructor(private readonly adapter: NativeRuntimeAdapter = new NativeRuntimeAdapter()) {}
|
constructor(private readonly adapter: NativeRuntimeAdapter = new NativeRuntimeAdapter()) {}
|
||||||
|
|
||||||
@@ -15,6 +23,20 @@ export class RuntimeService {
|
|||||||
await this.adapter.stopSession()
|
await this.adapter.stopSession()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async pullFrame(): Promise<RuntimeFrameVM> {
|
||||||
|
const frame = await this.adapter.pullFrame()
|
||||||
|
if (!frame.ok) {
|
||||||
|
throw new Error(frame.errorMessage || 'pullFrame failed')
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
hasFrame: frame.hasNewFrame,
|
||||||
|
width: frame.width,
|
||||||
|
height: frame.height,
|
||||||
|
frameId: frame.frameId ?? 0,
|
||||||
|
pixelFormat: frame.pixelFormat,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async onPageShow(): Promise<void> {
|
async onPageShow(): Promise<void> {
|
||||||
await this.adapter.notifyPageShow()
|
await this.adapter.notifyPageShow()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { RuntimeService } from '../services/RuntimeService'
|
import { RuntimeService } from '../services/RuntimeService'
|
||||||
|
import type { RuntimeFrameVM } from '../services/RuntimeService'
|
||||||
import type { UiError } from '../models/UiError'
|
import type { UiError } from '../models/UiError'
|
||||||
import type { RuntimePhase } from '../models/RuntimeSessionState'
|
import type { RuntimePhase } from '../models/RuntimeSessionState'
|
||||||
import { StoreObserver } from './StoreObserver'
|
import { StoreObserver } from './StoreObserver'
|
||||||
@@ -9,6 +10,14 @@ export class RuntimeSessionStore extends StoreObserver {
|
|||||||
error: UiError | null = null
|
error: UiError | null = null
|
||||||
canRestart: boolean = false
|
canRestart: boolean = false
|
||||||
canExit: boolean = false
|
canExit: boolean = false
|
||||||
|
runtimeHint: string = '等待启动'
|
||||||
|
frame: RuntimeFrameVM = {
|
||||||
|
hasFrame: false,
|
||||||
|
width: 0,
|
||||||
|
height: 0,
|
||||||
|
frameId: 0,
|
||||||
|
pixelFormat: 'RGBA_8888',
|
||||||
|
}
|
||||||
|
|
||||||
constructor(private readonly service: RuntimeService = new RuntimeService()) {
|
constructor(private readonly service: RuntimeService = new RuntimeService()) {
|
||||||
super()
|
super()
|
||||||
@@ -20,15 +29,19 @@ export class RuntimeSessionStore extends StoreObserver {
|
|||||||
this.error = null
|
this.error = null
|
||||||
this.canRestart = false
|
this.canRestart = false
|
||||||
this.canExit = false
|
this.canExit = false
|
||||||
|
this.runtimeHint = '正在初始化 Native/NAPI...'
|
||||||
this.notify()
|
this.notify()
|
||||||
try {
|
try {
|
||||||
await this.service.start(appId)
|
await this.service.start(appId)
|
||||||
this.phase = 'running'
|
this.phase = 'running'
|
||||||
this.canRestart = true
|
this.canRestart = true
|
||||||
this.canExit = true
|
this.canExit = true
|
||||||
} catch (_error) {
|
this.runtimeHint = 'Native/NAPI 已连通,准备拉取测试帧'
|
||||||
|
await this.refreshFrame()
|
||||||
|
} catch (error) {
|
||||||
this.phase = 'error'
|
this.phase = 'error'
|
||||||
this.error = { message: '启动失败', retryable: true }
|
this.error = { message: '启动失败', retryable: true }
|
||||||
|
this.runtimeHint = error instanceof Error ? error.message : 'Native/NAPI 启动失败'
|
||||||
}
|
}
|
||||||
this.notify()
|
this.notify()
|
||||||
}
|
}
|
||||||
@@ -40,15 +53,19 @@ export class RuntimeSessionStore extends StoreObserver {
|
|||||||
this.phase = 'starting'
|
this.phase = 'starting'
|
||||||
this.error = null
|
this.error = null
|
||||||
this.canRestart = false
|
this.canRestart = false
|
||||||
|
this.runtimeHint = '正在重启 Native/NAPI...'
|
||||||
this.notify()
|
this.notify()
|
||||||
try {
|
try {
|
||||||
await this.service.restart(this.currentAppId)
|
await this.service.restart(this.currentAppId)
|
||||||
this.phase = 'running'
|
this.phase = 'running'
|
||||||
this.canRestart = true
|
this.canRestart = true
|
||||||
this.canExit = true
|
this.canExit = true
|
||||||
} catch (_error) {
|
this.runtimeHint = '重启完成,准备重新拉取测试帧'
|
||||||
|
await this.refreshFrame()
|
||||||
|
} catch (error) {
|
||||||
this.phase = 'error'
|
this.phase = 'error'
|
||||||
this.error = { message: '重启失败', retryable: true }
|
this.error = { message: '重启失败', retryable: true }
|
||||||
|
this.runtimeHint = error instanceof Error ? error.message : '重启失败'
|
||||||
}
|
}
|
||||||
this.notify()
|
this.notify()
|
||||||
}
|
}
|
||||||
@@ -58,6 +75,28 @@ export class RuntimeSessionStore extends StoreObserver {
|
|||||||
this.phase = 'stopped'
|
this.phase = 'stopped'
|
||||||
this.canExit = false
|
this.canExit = false
|
||||||
this.canRestart = false
|
this.canRestart = false
|
||||||
|
this.runtimeHint = '运行会话已释放'
|
||||||
|
this.frame = {
|
||||||
|
hasFrame: false,
|
||||||
|
width: 0,
|
||||||
|
height: 0,
|
||||||
|
frameId: 0,
|
||||||
|
pixelFormat: 'RGBA_8888',
|
||||||
|
}
|
||||||
|
this.notify()
|
||||||
|
}
|
||||||
|
|
||||||
|
async refreshFrame(): Promise<void> {
|
||||||
|
try {
|
||||||
|
const frame = await this.service.pullFrame()
|
||||||
|
this.frame = frame
|
||||||
|
this.runtimeHint = frame.hasFrame
|
||||||
|
? `已拉到测试帧 #${frame.frameId}(${frame.width}x${frame.height} ${frame.pixelFormat})`
|
||||||
|
: '当前未返回新帧'
|
||||||
|
} catch (error) {
|
||||||
|
this.runtimeHint = error instanceof Error ? error.message : 'pullFrame 失败'
|
||||||
|
this.error = { message: '拉帧失败', retryable: true }
|
||||||
|
}
|
||||||
this.notify()
|
this.notify()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
{
|
||||||
|
"module": {
|
||||||
|
"name": "entry",
|
||||||
|
"type": "entry",
|
||||||
|
"description": "$string:module_desc",
|
||||||
|
"mainElement": "EntryAbility",
|
||||||
|
"deviceTypes": [
|
||||||
|
"phone",
|
||||||
|
"tablet"
|
||||||
|
],
|
||||||
|
"deliveryWithInstall": true,
|
||||||
|
"installationFree": false,
|
||||||
|
"pages": "$profile:main_pages",
|
||||||
|
"abilities": [
|
||||||
|
{
|
||||||
|
"name": "EntryAbility",
|
||||||
|
"srcEntry": "./ets/entryability/EntryAbility.ets",
|
||||||
|
"description": "$string:entry_ability_desc",
|
||||||
|
"icon": "$media:app_icon",
|
||||||
|
"label": "$string:app_name",
|
||||||
|
"startWindowIcon": "$media:app_icon",
|
||||||
|
"startWindowBackground": "$color:start_window_background",
|
||||||
|
"exported": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"color": [
|
||||||
|
{
|
||||||
|
"name": "start_window_background",
|
||||||
|
"value": "#FFFFFF"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"string": [
|
||||||
|
{
|
||||||
|
"name": "app_name",
|
||||||
|
"value": "MRP Simulator"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "module_desc",
|
||||||
|
"value": "MRP simulator HarmonyOS entry module"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "entry_ability_desc",
|
||||||
|
"value": "MRP simulator entry ability"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="256" height="256" viewBox="0 0 256 256">
|
||||||
|
<rect width="256" height="256" rx="48" fill="#0A59F7"/>
|
||||||
|
<text x="128" y="148" text-anchor="middle" font-size="84" fill="#FFFFFF" font-family="sans-serif">M</text>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 262 B |
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"src": [
|
||||||
|
"pages/ShellRootPage"
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"modelVersion": "5.0.0",
|
||||||
|
"dependencies": {},
|
||||||
|
"execution": {}
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
import { appTasks } from '@ohos/hvigor-ohos-plugin';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
system: appTasks,
|
||||||
|
plugins: []
|
||||||
|
};
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
#!/usr/bin/env sh
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
if [ -x "./node_modules/.bin/hvigor" ]; then
|
||||||
|
exec ./node_modules/.bin/hvigor "$@"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if command -v hvigor >/dev/null 2>&1; then
|
||||||
|
exec hvigor "$@"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "hvigor not found." >&2
|
||||||
|
echo "Open this project in DevEco Studio first, or install hvigor in your environment, then rerun ./hvigorw." >&2
|
||||||
|
exit 127
|
||||||
+17
@@ -0,0 +1,17 @@
|
|||||||
|
@echo off
|
||||||
|
setlocal
|
||||||
|
|
||||||
|
if exist .\node_modules\.bin\hvigor.cmd (
|
||||||
|
.\node_modules\.bin\hvigor.cmd %*
|
||||||
|
exit /b %errorlevel%
|
||||||
|
)
|
||||||
|
|
||||||
|
where hvigor >nul 2>nul
|
||||||
|
if %errorlevel%==0 (
|
||||||
|
hvigor %*
|
||||||
|
exit /b %errorlevel%
|
||||||
|
)
|
||||||
|
|
||||||
|
echo hvigor not found.
|
||||||
|
echo Open this project in DevEco Studio first, or install hvigor in your environment, then rerun hvigorw.bat.
|
||||||
|
exit /b 127
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
# Copy this file to local.properties and replace the path with your local HarmonyOS SDK path.
|
||||||
|
# Example (Windows): hwsdk.dir=C:\\Users\\you\\Huawei\\Sdk
|
||||||
|
# Example (macOS/Linux): hwsdk.dir=/Users/you/Huawei/Sdk
|
||||||
|
hwsdk.dir=/absolute/path/to/HarmonyOS/Sdk
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"modelVersion": "5.0.0",
|
||||||
|
"name": "mrp-simulator-harmonyos",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "HarmonyOS shell for MRP simulator",
|
||||||
|
"dependencies": {}
|
||||||
|
}
|
||||||
@@ -4,3 +4,6 @@
|
|||||||
- 样例整理脚本
|
- 样例整理脚本
|
||||||
- 调研辅助脚本
|
- 调研辅助脚本
|
||||||
- 构建/验证辅助脚本
|
- 构建/验证辅助脚本
|
||||||
|
|
||||||
|
当前可用:
|
||||||
|
- `check-init-env.sh`:检查仓库是否具备最小初始化前置(工程壳、wrapper、local.properties、hwsdk.dir、hvigor/node)
|
||||||
Executable
+88
@@ -0,0 +1,88 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
ROOT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
|
||||||
|
cd "$ROOT_DIR"
|
||||||
|
|
||||||
|
status() {
|
||||||
|
printf '%-32s %s\n' "$1" "$2"
|
||||||
|
}
|
||||||
|
|
||||||
|
check_file() {
|
||||||
|
local path="$1"
|
||||||
|
if [ -e "$path" ]; then
|
||||||
|
status "$path" "OK"
|
||||||
|
else
|
||||||
|
status "$path" "MISSING"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
FAILED=0
|
||||||
|
|
||||||
|
echo "[MRP HarmonyOS Init Check]"
|
||||||
|
echo "root=$ROOT_DIR"
|
||||||
|
|
||||||
|
echo "\n# Project shell files"
|
||||||
|
check_file "AppScope/app.json5" || FAILED=1
|
||||||
|
check_file "build-profile.json5" || FAILED=1
|
||||||
|
check_file "hvigorfile.ts" || FAILED=1
|
||||||
|
check_file "oh-package.json5" || FAILED=1
|
||||||
|
check_file "entry/hvigorfile.ts" || FAILED=1
|
||||||
|
check_file "entry/oh-package.json5" || FAILED=1
|
||||||
|
check_file "entry/build-profile.json5" || FAILED=1
|
||||||
|
check_file "entry/src/main/module.json5" || FAILED=1
|
||||||
|
check_file "entry/src/main/resources" || FAILED=1
|
||||||
|
check_file "entry/src/main/ets" || FAILED=1
|
||||||
|
check_file "entry/src/main/cpp" || FAILED=1
|
||||||
|
|
||||||
|
echo "\n# Wrapper / runtime tools"
|
||||||
|
if [ -x "./hvigorw" ]; then
|
||||||
|
status "./hvigorw" "OK"
|
||||||
|
else
|
||||||
|
status "./hvigorw" "NOT_EXECUTABLE"
|
||||||
|
FAILED=1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if command -v hvigor >/dev/null 2>&1; then
|
||||||
|
status "hvigor" "FOUND"
|
||||||
|
else
|
||||||
|
status "hvigor" "MISSING"
|
||||||
|
FAILED=1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if command -v node >/dev/null 2>&1; then
|
||||||
|
status "node" "FOUND: $(node -v)"
|
||||||
|
else
|
||||||
|
status "node" "MISSING"
|
||||||
|
FAILED=1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "\n# Local machine files"
|
||||||
|
if [ -f "local.properties" ]; then
|
||||||
|
status "local.properties" "FOUND"
|
||||||
|
HWSDK_DIR="$(sed -n 's/^hwsdk\.dir=//p' local.properties | tail -1)"
|
||||||
|
if [ -z "$HWSDK_DIR" ]; then
|
||||||
|
status "hwsdk.dir" "EMPTY"
|
||||||
|
FAILED=1
|
||||||
|
elif [[ "$HWSDK_DIR" == "/absolute/path/to/HarmonyOS/Sdk" ]]; then
|
||||||
|
status "hwsdk.dir" "PLACEHOLDER"
|
||||||
|
FAILED=1
|
||||||
|
elif [ -d "$HWSDK_DIR" ]; then
|
||||||
|
status "hwsdk.dir" "CONFIGURED"
|
||||||
|
else
|
||||||
|
status "hwsdk.dir" "PATH_NOT_FOUND"
|
||||||
|
FAILED=1
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
status "local.properties" "MISSING"
|
||||||
|
FAILED=1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "\n# Conclusion"
|
||||||
|
if [ "$FAILED" -eq 0 ]; then
|
||||||
|
echo "INIT_PREREQUISITES_OK"
|
||||||
|
else
|
||||||
|
echo "INIT_PREREQUISITES_BLOCKED"
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
Reference in new issue
Block a user