docs: set Chinese as default language (README-CN.md -> README.md)
This commit is contained in:
parent
7e250e8b42
commit
6518ae4a73
227
README-CN.md
227
README-CN.md
@ -1,227 +0,0 @@
|
|||||||
# HarmonyOS Electron HAP
|
|
||||||
|
|
||||||
[English](./README.md) | 简体中文
|
|
||||||
|
|
||||||
这是一个基于 HarmonyOS 平台的 Electron 应用程序包(HAP)项目,支持在鸿蒙设备上运行 Electron 应用。
|
|
||||||
|
|
||||||
## 项目结构
|
|
||||||
|
|
||||||
```
|
|
||||||
ohos_electron_hap/
|
|
||||||
├── AppScope/ # 应用范围配置
|
|
||||||
├── chromium/ # Chromium 模块
|
|
||||||
├── electron/ # Electron 主模块
|
|
||||||
├── web_engine/ # Web 引擎组件
|
|
||||||
├── hvigor/ # 构建工具配置
|
|
||||||
├── build-profile.json5 # 项目构建配置
|
|
||||||
├── hvigorfile.ts # 构建脚本
|
|
||||||
└── oh-package.json5 # 项目依赖配置
|
|
||||||
```
|
|
||||||
|
|
||||||
## 快速开始
|
|
||||||
|
|
||||||
### 环境要求
|
|
||||||
|
|
||||||
- **DevEco Studio**: 4.0 或更高版本
|
|
||||||
- **HarmonyOS SDK**: API Level 10 或更高
|
|
||||||
- **Node.js**: 16.x 或更高版本
|
|
||||||
- **HDC工具**: 用于设备调试和安装
|
|
||||||
|
|
||||||
### 1. 准备资源文件
|
|
||||||
|
|
||||||
在开始构建之前,需要准备以下资源:
|
|
||||||
|
|
||||||
#### Electron 应用代码
|
|
||||||
将您的 Electron 应用代码(编译后的产物)放入:
|
|
||||||
```
|
|
||||||
web_engine/src/main/resources/resfile/resources/app/
|
|
||||||
```
|
|
||||||
|
|
||||||
### 2. 构建 HAP 包
|
|
||||||
|
|
||||||
#### 使用 DevEco Studio
|
|
||||||
1. 用 DevEco Studio 打开项目
|
|
||||||
2. 选择 **Build** → **Build Hap(s)/APP(s)** → **Build Hap(s)**
|
|
||||||
3. 或点击右上角的运行按钮启动应用
|
|
||||||
|
|
||||||
构建完成后,未签名的 HAP 包将保存在:
|
|
||||||
```
|
|
||||||
electron/build/default/outputs/default/electron-default-unsigned.hap
|
|
||||||
```
|
|
||||||
|
|
||||||
### 3. 应用签名
|
|
||||||
|
|
||||||
为了在设备上正常运行,需要对 HAP 包进行签名:
|
|
||||||
|
|
||||||
> 建议使用自动签名验证
|
|
||||||
1. 申请华为开发者证书
|
|
||||||
2. 在 DevEco Studio 中配置签名信息
|
|
||||||
3. 重新构建生成已签名的 HAP 包
|
|
||||||
|
|
||||||
详细签名流程请参考:[应用/服务签名-DevEco Studio](https://developer.huawei.com/)
|
|
||||||
|
|
||||||
### 4. 安装和运行
|
|
||||||
|
|
||||||
#### 通过 DevEco Studio
|
|
||||||
直接点击运行按钮安装到设备
|
|
||||||
|
|
||||||
#### 通过命令行
|
|
||||||
```bash
|
|
||||||
hdc app install <已签名hap包路径>
|
|
||||||
# 示例: hdc app install electron-default-signed.hap
|
|
||||||
```
|
|
||||||
|
|
||||||
## 应用定制
|
|
||||||
|
|
||||||
### 修改应用名称
|
|
||||||
编辑文件:`electron/src/main/resources/zh_CN/element/string.json`
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"string": [
|
|
||||||
{
|
|
||||||
"name": "EntryAbility_label",
|
|
||||||
"value": "您的应用名称"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### 替换应用图标
|
|
||||||
将新图标文件放入:`AppScope/resources/base/media/`
|
|
||||||
|
|
||||||
### 配置启动窗口大小
|
|
||||||
编辑 `electron/src/main/module.json5`,在 abilities 中添加 metadata:
|
|
||||||
```json
|
|
||||||
"metadata": [
|
|
||||||
{
|
|
||||||
"name": "ohos.ability.window.height",
|
|
||||||
"value": "800"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "ohos.ability.window.width",
|
|
||||||
"value": "800"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "ohos.ability.window.left",
|
|
||||||
"value": "center"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "ohos.ability.window.top",
|
|
||||||
"value": "center"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
```
|
|
||||||
|
|
||||||
## 权限配置
|
|
||||||
|
|
||||||
应用权限在 `web_engine/src/main/module.json5` 文件的 `requestPermissions` 字段中配置。
|
|
||||||
|
|
||||||
### 基础权限(无需特殊申请)
|
|
||||||
- `ohos.permission.INTERNET` - 网络访问
|
|
||||||
- `ohos.permission.GET_NETWORK_INFO` - 获取网络信息
|
|
||||||
- `ohos.permission.RUNNING_LOCK` - 后台运行锁
|
|
||||||
- `ohos.permission.PREPARE_APP_TERMINATE` - 应用终止准备
|
|
||||||
|
|
||||||
### 需要申请的权限
|
|
||||||
- `ohos.permission.CAMERA` - 相机权限
|
|
||||||
- `ohos.permission.MICROPHONE` - 麦克风权限
|
|
||||||
- `ohos.permission.LOCATION` - 位置权限
|
|
||||||
- `ohos.permission.READ_WRITE_DOWNLOAD_DIRECTORY` - 下载目录访问
|
|
||||||
|
|
||||||
## HarmonyOS 特有功能
|
|
||||||
|
|
||||||
### 悬浮窗
|
|
||||||
```javascript
|
|
||||||
const { BrowserWindow } = require('electron');
|
|
||||||
|
|
||||||
let floatWindow = new BrowserWindow({
|
|
||||||
windowInfo: {
|
|
||||||
type: 'floatWindow' // mainWindow, subWindow, floatWindow
|
|
||||||
},
|
|
||||||
parent: mainWindow,
|
|
||||||
x: 100,
|
|
||||||
y: 100,
|
|
||||||
width: 800,
|
|
||||||
height: 600,
|
|
||||||
transparent: true, // 透明窗口
|
|
||||||
opacity: 0.5 // 透明度
|
|
||||||
});
|
|
||||||
```
|
|
||||||
|
|
||||||
### 系统权限请求
|
|
||||||
```javascript
|
|
||||||
const { systemPreferences } = require('electron');
|
|
||||||
|
|
||||||
// 请求相机权限
|
|
||||||
systemPreferences.requestSystemPermission('camera').then(granted => {
|
|
||||||
console.log('Camera permission:', granted);
|
|
||||||
});
|
|
||||||
|
|
||||||
// 请求目录权限
|
|
||||||
systemPreferences.requestDirectoryPermission(null).then(granted => {
|
|
||||||
console.log('Directory permission:', granted);
|
|
||||||
});
|
|
||||||
```
|
|
||||||
|
|
||||||
## 调试
|
|
||||||
|
|
||||||
### 渲染进程调试
|
|
||||||
```javascript
|
|
||||||
const { BrowserWindow } = require('electron');
|
|
||||||
const win = new BrowserWindow();
|
|
||||||
win.webContents.openDevTools();
|
|
||||||
```
|
|
||||||
|
|
||||||
### 主进程调试
|
|
||||||
1. 在 `web_engine/src/main/ets/components/WebWindow.ets` 中添加调试参数:
|
|
||||||
```typescript
|
|
||||||
let inspect = '--inspect=9229';
|
|
||||||
let vec_args = [..., inspect];
|
|
||||||
```
|
|
||||||
|
|
||||||
2. 配置端口转发:
|
|
||||||
```bash
|
|
||||||
hdc fport tcp:9229 tcp:9229
|
|
||||||
```
|
|
||||||
|
|
||||||
3. 在 Chrome 浏览器中访问:`chrome://inspect`
|
|
||||||
|
|
||||||
## 应用数据目录
|
|
||||||
|
|
||||||
- 用户数据默认存储在:`/data/storage/el2/base/files`
|
|
||||||
- 应用安装目录:`/data/storage/el1/bundle`
|
|
||||||
- 数据库目录:`/data/storage/el2/database`
|
|
||||||
|
|
||||||
## 常见问题
|
|
||||||
|
|
||||||
### 构建失败
|
|
||||||
1. 检查 SO 库文件是否完整
|
|
||||||
2. 确认 Electron 应用代码已正确放置
|
|
||||||
3. 验证权限配置是否正确
|
|
||||||
|
|
||||||
### 三方库兼容性
|
|
||||||
- **C++ addon**: 需要重新编译适配鸿蒙平台
|
|
||||||
- **平台检测**: 需要适配 `process.platform === 'ohos'`
|
|
||||||
- **二进制文件**: 可能需要替换为鸿蒙版本
|
|
||||||
|
|
||||||
### 权限问题
|
|
||||||
如果某些 ACL 权限无法获得,可以暂时注释掉相关权限:
|
|
||||||
```json
|
|
||||||
// "requestPermissions": [
|
|
||||||
// {
|
|
||||||
// "name": "ohos.permission.SYSTEM_FLOAT_WINDOW"
|
|
||||||
// }
|
|
||||||
// ]
|
|
||||||
```
|
|
||||||
|
|
||||||
## 贡献指南
|
|
||||||
|
|
||||||
1. Fork 本仓库
|
|
||||||
2. 创建功能分支:`git checkout -b feature/your-feature`
|
|
||||||
3. 提交更改:`git commit -am 'Add some feature'`
|
|
||||||
4. 推送到分支:`git push origin feature/your-feature`
|
|
||||||
5. 提交 Pull Request
|
|
||||||
|
|
||||||
## 联系我们
|
|
||||||
|
|
||||||
如遇到问题或需要支持,请提交 Issue 或联系维护团队。
|
|
||||||
227
README-en.md
Normal file
227
README-en.md
Normal file
@ -0,0 +1,227 @@
|
|||||||
|
# HarmonyOS Electron HAP
|
||||||
|
|
||||||
|
English | [简体中文](./README-CN.md)
|
||||||
|
|
||||||
|
A HarmonyOS Application Package (HAP) project based on the HarmonyOS platform that enables running Electron applications on HarmonyOS devices.
|
||||||
|
|
||||||
|
## Project Structure
|
||||||
|
|
||||||
|
```
|
||||||
|
ohos_electron_hap/
|
||||||
|
├── AppScope/ # Application scope configuration
|
||||||
|
├── chromium/ # Chromium module
|
||||||
|
├── electron/ # Electron main module
|
||||||
|
├── web_engine/ # Web engine component
|
||||||
|
├── hvigor/ # Build tool configuration
|
||||||
|
├── build-profile.json5 # Project build configuration
|
||||||
|
├── hvigorfile.ts # Build script
|
||||||
|
└── oh-package.json5 # Project dependencies configuration
|
||||||
|
```
|
||||||
|
|
||||||
|
## Quick Start
|
||||||
|
|
||||||
|
### Environment Requirements
|
||||||
|
|
||||||
|
- **DevEco Studio**: 4.0 or higher
|
||||||
|
- **HarmonyOS SDK**: API Level 10 or higher
|
||||||
|
- **Node.js**: 16.x or higher
|
||||||
|
- **HDC Tool**: For device debugging and installation
|
||||||
|
|
||||||
|
### 1. Prepare Resource Files
|
||||||
|
|
||||||
|
Before starting the build, you need to prepare the following resources:
|
||||||
|
|
||||||
|
#### Electron Application Code
|
||||||
|
Place your Electron application code (compiled artifacts) into:
|
||||||
|
```
|
||||||
|
web_engine/src/main/resources/resfile/resources/app/
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. Build HAP Package
|
||||||
|
|
||||||
|
#### Using DevEco Studio
|
||||||
|
1. Open the project with DevEco Studio
|
||||||
|
2. Select **Build** → **Build Hap(s)/APP(s)** → **Build Hap(s)**
|
||||||
|
3. Or click the run button in the top right corner to launch the application
|
||||||
|
|
||||||
|
After building, the unsigned HAP package will be saved at:
|
||||||
|
```
|
||||||
|
electron/build/default/outputs/default/electron-default-unsigned.hap
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3. Application Signing
|
||||||
|
|
||||||
|
To run normally on devices, the HAP package needs to be signed:
|
||||||
|
|
||||||
|
> Recommend using automatic signature verification
|
||||||
|
1. Apply for Huawei Developer Certificate
|
||||||
|
2. Configure signing information in DevEco Studio
|
||||||
|
3. Rebuild to generate signed HAP package
|
||||||
|
|
||||||
|
For detailed signing process, please refer to: [Application/Service Signing-DevEco Studio](https://developer.huawei.com/)
|
||||||
|
|
||||||
|
### 4. Installation and Running
|
||||||
|
|
||||||
|
#### Via DevEco Studio
|
||||||
|
Click the run button directly to install on device
|
||||||
|
|
||||||
|
#### Via Command Line
|
||||||
|
```bash
|
||||||
|
hdc app install <signed-hap-package-path>
|
||||||
|
# Example: hdc app install electron-default-signed.hap
|
||||||
|
```
|
||||||
|
|
||||||
|
## Application Customization
|
||||||
|
|
||||||
|
### Modify Application Name
|
||||||
|
Edit file: `electron/src/main/resources/zh_CN/element/string.json`
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"string": [
|
||||||
|
{
|
||||||
|
"name": "EntryAbility_label",
|
||||||
|
"value": "Your Application Name"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Replace Application Icon
|
||||||
|
Place new icon file into: `AppScope/resources/base/media/`
|
||||||
|
|
||||||
|
### Configure Startup Window Size
|
||||||
|
Edit `electron/src/main/module.json5`, add metadata in abilities:
|
||||||
|
```json
|
||||||
|
"metadata": [
|
||||||
|
{
|
||||||
|
"name": "ohos.ability.window.height",
|
||||||
|
"value": "800"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "ohos.ability.window.width",
|
||||||
|
"value": "800"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "ohos.ability.window.left",
|
||||||
|
"value": "center"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "ohos.ability.window.top",
|
||||||
|
"value": "center"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
## Permission Configuration
|
||||||
|
|
||||||
|
Application permissions are configured in the `requestPermissions` field of the `web_engine/src/main/module.json5` file.
|
||||||
|
|
||||||
|
### Basic Permissions (No Special Application Required)
|
||||||
|
- `ohos.permission.INTERNET` - Network access
|
||||||
|
- `ohos.permission.GET_NETWORK_INFO` - Get network information
|
||||||
|
- `ohos.permission.RUNNING_LOCK` - Background running lock
|
||||||
|
- `ohos.permission.PREPARE_APP_TERMINATE` - Application termination preparation
|
||||||
|
|
||||||
|
### Permissions Requiring Application
|
||||||
|
- `ohos.permission.CAMERA` - Camera permission
|
||||||
|
- `ohos.permission.MICROPHONE` - Microphone permission
|
||||||
|
- `ohos.permission.LOCATION` - Location permission
|
||||||
|
- `ohos.permission.READ_WRITE_DOWNLOAD_DIRECTORY` - Download directory access
|
||||||
|
|
||||||
|
## HarmonyOS Specific Features
|
||||||
|
|
||||||
|
### Floating Window
|
||||||
|
```javascript
|
||||||
|
const { BrowserWindow } = require('electron');
|
||||||
|
|
||||||
|
let floatWindow = new BrowserWindow({
|
||||||
|
windowInfo: {
|
||||||
|
type: 'floatWindow' // mainWindow, subWindow, floatWindow
|
||||||
|
},
|
||||||
|
parent: mainWindow,
|
||||||
|
x: 100,
|
||||||
|
y: 100,
|
||||||
|
width: 800,
|
||||||
|
height: 600,
|
||||||
|
transparent: true, // Transparent window
|
||||||
|
opacity: 0.5 // Opacity
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### System Permission Request
|
||||||
|
```javascript
|
||||||
|
const { systemPreferences } = require('electron');
|
||||||
|
|
||||||
|
// Request camera permission
|
||||||
|
systemPreferences.requestSystemPermission('camera').then(granted => {
|
||||||
|
console.log('Camera permission:', granted);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Request directory permission
|
||||||
|
systemPreferences.requestDirectoryPermission(null).then(granted => {
|
||||||
|
console.log('Directory permission:', granted);
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
## Debugging
|
||||||
|
|
||||||
|
### Renderer Process Debugging
|
||||||
|
```javascript
|
||||||
|
const { BrowserWindow } = require('electron');
|
||||||
|
const win = new BrowserWindow();
|
||||||
|
win.webContents.openDevTools();
|
||||||
|
```
|
||||||
|
|
||||||
|
### Main Process Debugging
|
||||||
|
1. Add debugging parameters in `web_engine/src/main/ets/components/WebWindow.ets`:
|
||||||
|
```typescript
|
||||||
|
let inspect = '--inspect=9229';
|
||||||
|
let vec_args = [..., inspect];
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Configure port forwarding:
|
||||||
|
```bash
|
||||||
|
hdc fport tcp:9229 tcp:9229
|
||||||
|
```
|
||||||
|
|
||||||
|
3. Access in Chrome browser: `chrome://inspect`
|
||||||
|
|
||||||
|
## Application Data Directory
|
||||||
|
|
||||||
|
- User data stored by default at: `/data/storage/el2/base/files`
|
||||||
|
- Application installation directory: `/data/storage/el1/bundle`
|
||||||
|
- Database directory: `/data/storage/el2/database`
|
||||||
|
|
||||||
|
## Common Issues
|
||||||
|
|
||||||
|
### Build Failure
|
||||||
|
1. Check if SO library files are complete
|
||||||
|
2. Confirm Electron application code is correctly placed
|
||||||
|
3. Verify permission configuration is correct
|
||||||
|
|
||||||
|
### Third-party Library Compatibility
|
||||||
|
- **C++ addon**: Need to recompile for HarmonyOS platform adaptation
|
||||||
|
- **Platform detection**: Need to adapt `process.platform === 'ohos'`
|
||||||
|
- **Binary files**: May need to replace with HarmonyOS versions
|
||||||
|
|
||||||
|
### Permission Issues
|
||||||
|
If certain ACL permissions cannot be obtained, you can temporarily comment out related permissions:
|
||||||
|
```json
|
||||||
|
// "requestPermissions": [
|
||||||
|
// {
|
||||||
|
// "name": "ohos.permission.SYSTEM_FLOAT_WINDOW"
|
||||||
|
// }
|
||||||
|
// ]
|
||||||
|
```
|
||||||
|
|
||||||
|
## Contributing
|
||||||
|
|
||||||
|
1. Fork this repository
|
||||||
|
2. Create a feature branch: `git checkout -b feature/your-feature`
|
||||||
|
3. Commit your changes: `git commit -am 'Add some feature'`
|
||||||
|
4. Push to the branch: `git push origin feature/your-feature`
|
||||||
|
5. Submit a Pull Request
|
||||||
|
|
||||||
|
## Contact Us
|
||||||
|
|
||||||
|
If you encounter issues or need support, please submit an Issue or contact the maintenance team.
|
||||||
192
README.md
192
README.md
@ -1,96 +1,96 @@
|
|||||||
# HarmonyOS Electron HAP
|
# HarmonyOS Electron HAP
|
||||||
|
|
||||||
English | [简体中文](./README-CN.md)
|
[English](./README.md) | 简体中文
|
||||||
|
|
||||||
A HarmonyOS Application Package (HAP) project based on the HarmonyOS platform that enables running Electron applications on HarmonyOS devices.
|
这是一个基于 HarmonyOS 平台的 Electron 应用程序包(HAP)项目,支持在鸿蒙设备上运行 Electron 应用。
|
||||||
|
|
||||||
## Project Structure
|
## 项目结构
|
||||||
|
|
||||||
```
|
```
|
||||||
ohos_electron_hap/
|
ohos_electron_hap/
|
||||||
├── AppScope/ # Application scope configuration
|
├── AppScope/ # 应用范围配置
|
||||||
├── chromium/ # Chromium module
|
├── chromium/ # Chromium 模块
|
||||||
├── electron/ # Electron main module
|
├── electron/ # Electron 主模块
|
||||||
├── web_engine/ # Web engine component
|
├── web_engine/ # Web 引擎组件
|
||||||
├── hvigor/ # Build tool configuration
|
├── hvigor/ # 构建工具配置
|
||||||
├── build-profile.json5 # Project build configuration
|
├── build-profile.json5 # 项目构建配置
|
||||||
├── hvigorfile.ts # Build script
|
├── hvigorfile.ts # 构建脚本
|
||||||
└── oh-package.json5 # Project dependencies configuration
|
└── oh-package.json5 # 项目依赖配置
|
||||||
```
|
```
|
||||||
|
|
||||||
## Quick Start
|
## 快速开始
|
||||||
|
|
||||||
### Environment Requirements
|
### 环境要求
|
||||||
|
|
||||||
- **DevEco Studio**: 4.0 or higher
|
- **DevEco Studio**: 4.0 或更高版本
|
||||||
- **HarmonyOS SDK**: API Level 10 or higher
|
- **HarmonyOS SDK**: API Level 10 或更高
|
||||||
- **Node.js**: 16.x or higher
|
- **Node.js**: 16.x 或更高版本
|
||||||
- **HDC Tool**: For device debugging and installation
|
- **HDC工具**: 用于设备调试和安装
|
||||||
|
|
||||||
### 1. Prepare Resource Files
|
### 1. 准备资源文件
|
||||||
|
|
||||||
Before starting the build, you need to prepare the following resources:
|
在开始构建之前,需要准备以下资源:
|
||||||
|
|
||||||
#### Electron Application Code
|
#### Electron 应用代码
|
||||||
Place your Electron application code (compiled artifacts) into:
|
将您的 Electron 应用代码(编译后的产物)放入:
|
||||||
```
|
```
|
||||||
web_engine/src/main/resources/resfile/resources/app/
|
web_engine/src/main/resources/resfile/resources/app/
|
||||||
```
|
```
|
||||||
|
|
||||||
### 2. Build HAP Package
|
### 2. 构建 HAP 包
|
||||||
|
|
||||||
#### Using DevEco Studio
|
#### 使用 DevEco Studio
|
||||||
1. Open the project with DevEco Studio
|
1. 用 DevEco Studio 打开项目
|
||||||
2. Select **Build** → **Build Hap(s)/APP(s)** → **Build Hap(s)**
|
2. 选择 **Build** → **Build Hap(s)/APP(s)** → **Build Hap(s)**
|
||||||
3. Or click the run button in the top right corner to launch the application
|
3. 或点击右上角的运行按钮启动应用
|
||||||
|
|
||||||
After building, the unsigned HAP package will be saved at:
|
构建完成后,未签名的 HAP 包将保存在:
|
||||||
```
|
```
|
||||||
electron/build/default/outputs/default/electron-default-unsigned.hap
|
electron/build/default/outputs/default/electron-default-unsigned.hap
|
||||||
```
|
```
|
||||||
|
|
||||||
### 3. Application Signing
|
### 3. 应用签名
|
||||||
|
|
||||||
To run normally on devices, the HAP package needs to be signed:
|
为了在设备上正常运行,需要对 HAP 包进行签名:
|
||||||
|
|
||||||
> Recommend using automatic signature verification
|
> 建议使用自动签名验证
|
||||||
1. Apply for Huawei Developer Certificate
|
1. 申请华为开发者证书
|
||||||
2. Configure signing information in DevEco Studio
|
2. 在 DevEco Studio 中配置签名信息
|
||||||
3. Rebuild to generate signed HAP package
|
3. 重新构建生成已签名的 HAP 包
|
||||||
|
|
||||||
For detailed signing process, please refer to: [Application/Service Signing-DevEco Studio](https://developer.huawei.com/)
|
详细签名流程请参考:[应用/服务签名-DevEco Studio](https://developer.huawei.com/)
|
||||||
|
|
||||||
### 4. Installation and Running
|
### 4. 安装和运行
|
||||||
|
|
||||||
#### Via DevEco Studio
|
#### 通过 DevEco Studio
|
||||||
Click the run button directly to install on device
|
直接点击运行按钮安装到设备
|
||||||
|
|
||||||
#### Via Command Line
|
#### 通过命令行
|
||||||
```bash
|
```bash
|
||||||
hdc app install <signed-hap-package-path>
|
hdc app install <已签名hap包路径>
|
||||||
# Example: hdc app install electron-default-signed.hap
|
# 示例: hdc app install electron-default-signed.hap
|
||||||
```
|
```
|
||||||
|
|
||||||
## Application Customization
|
## 应用定制
|
||||||
|
|
||||||
### Modify Application Name
|
### 修改应用名称
|
||||||
Edit file: `electron/src/main/resources/zh_CN/element/string.json`
|
编辑文件:`electron/src/main/resources/zh_CN/element/string.json`
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"string": [
|
"string": [
|
||||||
{
|
{
|
||||||
"name": "EntryAbility_label",
|
"name": "EntryAbility_label",
|
||||||
"value": "Your Application Name"
|
"value": "您的应用名称"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### Replace Application Icon
|
### 替换应用图标
|
||||||
Place new icon file into: `AppScope/resources/base/media/`
|
将新图标文件放入:`AppScope/resources/base/media/`
|
||||||
|
|
||||||
### Configure Startup Window Size
|
### 配置启动窗口大小
|
||||||
Edit `electron/src/main/module.json5`, add metadata in abilities:
|
编辑 `electron/src/main/module.json5`,在 abilities 中添加 metadata:
|
||||||
```json
|
```json
|
||||||
"metadata": [
|
"metadata": [
|
||||||
{
|
{
|
||||||
@ -112,25 +112,25 @@ Edit `electron/src/main/module.json5`, add metadata in abilities:
|
|||||||
]
|
]
|
||||||
```
|
```
|
||||||
|
|
||||||
## Permission Configuration
|
## 权限配置
|
||||||
|
|
||||||
Application permissions are configured in the `requestPermissions` field of the `web_engine/src/main/module.json5` file.
|
应用权限在 `web_engine/src/main/module.json5` 文件的 `requestPermissions` 字段中配置。
|
||||||
|
|
||||||
### Basic Permissions (No Special Application Required)
|
### 基础权限(无需特殊申请)
|
||||||
- `ohos.permission.INTERNET` - Network access
|
- `ohos.permission.INTERNET` - 网络访问
|
||||||
- `ohos.permission.GET_NETWORK_INFO` - Get network information
|
- `ohos.permission.GET_NETWORK_INFO` - 获取网络信息
|
||||||
- `ohos.permission.RUNNING_LOCK` - Background running lock
|
- `ohos.permission.RUNNING_LOCK` - 后台运行锁
|
||||||
- `ohos.permission.PREPARE_APP_TERMINATE` - Application termination preparation
|
- `ohos.permission.PREPARE_APP_TERMINATE` - 应用终止准备
|
||||||
|
|
||||||
### Permissions Requiring Application
|
### 需要申请的权限
|
||||||
- `ohos.permission.CAMERA` - Camera permission
|
- `ohos.permission.CAMERA` - 相机权限
|
||||||
- `ohos.permission.MICROPHONE` - Microphone permission
|
- `ohos.permission.MICROPHONE` - 麦克风权限
|
||||||
- `ohos.permission.LOCATION` - Location permission
|
- `ohos.permission.LOCATION` - 位置权限
|
||||||
- `ohos.permission.READ_WRITE_DOWNLOAD_DIRECTORY` - Download directory access
|
- `ohos.permission.READ_WRITE_DOWNLOAD_DIRECTORY` - 下载目录访问
|
||||||
|
|
||||||
## HarmonyOS Specific Features
|
## HarmonyOS 特有功能
|
||||||
|
|
||||||
### Floating Window
|
### 悬浮窗
|
||||||
```javascript
|
```javascript
|
||||||
const { BrowserWindow } = require('electron');
|
const { BrowserWindow } = require('electron');
|
||||||
|
|
||||||
@ -143,69 +143,69 @@ let floatWindow = new BrowserWindow({
|
|||||||
y: 100,
|
y: 100,
|
||||||
width: 800,
|
width: 800,
|
||||||
height: 600,
|
height: 600,
|
||||||
transparent: true, // Transparent window
|
transparent: true, // 透明窗口
|
||||||
opacity: 0.5 // Opacity
|
opacity: 0.5 // 透明度
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
### System Permission Request
|
### 系统权限请求
|
||||||
```javascript
|
```javascript
|
||||||
const { systemPreferences } = require('electron');
|
const { systemPreferences } = require('electron');
|
||||||
|
|
||||||
// Request camera permission
|
// 请求相机权限
|
||||||
systemPreferences.requestSystemPermission('camera').then(granted => {
|
systemPreferences.requestSystemPermission('camera').then(granted => {
|
||||||
console.log('Camera permission:', granted);
|
console.log('Camera permission:', granted);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Request directory permission
|
// 请求目录权限
|
||||||
systemPreferences.requestDirectoryPermission(null).then(granted => {
|
systemPreferences.requestDirectoryPermission(null).then(granted => {
|
||||||
console.log('Directory permission:', granted);
|
console.log('Directory permission:', granted);
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
## Debugging
|
## 调试
|
||||||
|
|
||||||
### Renderer Process Debugging
|
### 渲染进程调试
|
||||||
```javascript
|
```javascript
|
||||||
const { BrowserWindow } = require('electron');
|
const { BrowserWindow } = require('electron');
|
||||||
const win = new BrowserWindow();
|
const win = new BrowserWindow();
|
||||||
win.webContents.openDevTools();
|
win.webContents.openDevTools();
|
||||||
```
|
```
|
||||||
|
|
||||||
### Main Process Debugging
|
### 主进程调试
|
||||||
1. Add debugging parameters in `web_engine/src/main/ets/components/WebWindow.ets`:
|
1. 在 `web_engine/src/main/ets/components/WebWindow.ets` 中添加调试参数:
|
||||||
```typescript
|
```typescript
|
||||||
let inspect = '--inspect=9229';
|
let inspect = '--inspect=9229';
|
||||||
let vec_args = [..., inspect];
|
let vec_args = [..., inspect];
|
||||||
```
|
```
|
||||||
|
|
||||||
2. Configure port forwarding:
|
2. 配置端口转发:
|
||||||
```bash
|
```bash
|
||||||
hdc fport tcp:9229 tcp:9229
|
hdc fport tcp:9229 tcp:9229
|
||||||
```
|
```
|
||||||
|
|
||||||
3. Access in Chrome browser: `chrome://inspect`
|
3. 在 Chrome 浏览器中访问:`chrome://inspect`
|
||||||
|
|
||||||
## Application Data Directory
|
## 应用数据目录
|
||||||
|
|
||||||
- User data stored by default at: `/data/storage/el2/base/files`
|
- 用户数据默认存储在:`/data/storage/el2/base/files`
|
||||||
- Application installation directory: `/data/storage/el1/bundle`
|
- 应用安装目录:`/data/storage/el1/bundle`
|
||||||
- Database directory: `/data/storage/el2/database`
|
- 数据库目录:`/data/storage/el2/database`
|
||||||
|
|
||||||
## Common Issues
|
## 常见问题
|
||||||
|
|
||||||
### Build Failure
|
### 构建失败
|
||||||
1. Check if SO library files are complete
|
1. 检查 SO 库文件是否完整
|
||||||
2. Confirm Electron application code is correctly placed
|
2. 确认 Electron 应用代码已正确放置
|
||||||
3. Verify permission configuration is correct
|
3. 验证权限配置是否正确
|
||||||
|
|
||||||
### Third-party Library Compatibility
|
### 三方库兼容性
|
||||||
- **C++ addon**: Need to recompile for HarmonyOS platform adaptation
|
- **C++ addon**: 需要重新编译适配鸿蒙平台
|
||||||
- **Platform detection**: Need to adapt `process.platform === 'ohos'`
|
- **平台检测**: 需要适配 `process.platform === 'ohos'`
|
||||||
- **Binary files**: May need to replace with HarmonyOS versions
|
- **二进制文件**: 可能需要替换为鸿蒙版本
|
||||||
|
|
||||||
### Permission Issues
|
### 权限问题
|
||||||
If certain ACL permissions cannot be obtained, you can temporarily comment out related permissions:
|
如果某些 ACL 权限无法获得,可以暂时注释掉相关权限:
|
||||||
```json
|
```json
|
||||||
// "requestPermissions": [
|
// "requestPermissions": [
|
||||||
// {
|
// {
|
||||||
@ -214,14 +214,14 @@ If certain ACL permissions cannot be obtained, you can temporarily comment out r
|
|||||||
// ]
|
// ]
|
||||||
```
|
```
|
||||||
|
|
||||||
## Contributing
|
## 贡献指南
|
||||||
|
|
||||||
1. Fork this repository
|
1. Fork 本仓库
|
||||||
2. Create a feature branch: `git checkout -b feature/your-feature`
|
2. 创建功能分支:`git checkout -b feature/your-feature`
|
||||||
3. Commit your changes: `git commit -am 'Add some feature'`
|
3. 提交更改:`git commit -am 'Add some feature'`
|
||||||
4. Push to the branch: `git push origin feature/your-feature`
|
4. 推送到分支:`git push origin feature/your-feature`
|
||||||
5. Submit a Pull Request
|
5. 提交 Pull Request
|
||||||
|
|
||||||
## Contact Us
|
## 联系我们
|
||||||
|
|
||||||
If you encounter issues or need support, please submit an Issue or contact the maintenance team.
|
如遇到问题或需要支持,请提交 Issue 或联系维护团队。
|
||||||
|
|||||||
@ -1,4 +1,8 @@
|
|||||||
const { createClient, AuthType } = require("webdav");
|
let _webdav;
|
||||||
|
async function _loadWebdav() {
|
||||||
|
if (!_webdav) _webdav = await import("webdav");
|
||||||
|
return _webdav;
|
||||||
|
}
|
||||||
const https = require("https");
|
const https = require("https");
|
||||||
const {
|
const {
|
||||||
S3Client,
|
S3Client,
|
||||||
@ -57,8 +61,9 @@ const buildBasicAuthHeader = (username, password) =>
|
|||||||
"Basic " +
|
"Basic " +
|
||||||
Buffer.from(`${username || ""}:${password || ""}`, "utf8").toString("base64");
|
Buffer.from(`${username || ""}:${password || ""}`, "utf8").toString("base64");
|
||||||
|
|
||||||
const buildWebdavClient = (config) => {
|
const buildWebdavClient = async (config) => {
|
||||||
if (!config) throw new Error("Missing WebDAV config");
|
if (!config) throw new Error("Missing WebDAV config");
|
||||||
|
const { createClient, AuthType } = await _loadWebdav();
|
||||||
const endpoint = normalizeEndpoint(config.endpoint);
|
const endpoint = normalizeEndpoint(config.endpoint);
|
||||||
const extraOpts = {};
|
const extraOpts = {};
|
||||||
if (config.allowInsecure) {
|
if (config.allowInsecure) {
|
||||||
@ -145,7 +150,7 @@ const wrapS3Error = (operation, error, config) => {
|
|||||||
|
|
||||||
const handleWebdavInitialize = async (config) => {
|
const handleWebdavInitialize = async (config) => {
|
||||||
try {
|
try {
|
||||||
const client = buildWebdavClient(config);
|
const client = await buildWebdavClient(config);
|
||||||
const path = getWebdavPath();
|
const path = getWebdavPath();
|
||||||
await client.exists(path);
|
await client.exists(path);
|
||||||
return { resourceId: path };
|
return { resourceId: path };
|
||||||
@ -156,7 +161,7 @@ const handleWebdavInitialize = async (config) => {
|
|||||||
|
|
||||||
const handleWebdavUpload = async (config, syncedFile) => {
|
const handleWebdavUpload = async (config, syncedFile) => {
|
||||||
try {
|
try {
|
||||||
const client = buildWebdavClient(config);
|
const client = await buildWebdavClient(config);
|
||||||
const path = getWebdavPath();
|
const path = getWebdavPath();
|
||||||
await client.putFileContents(path, JSON.stringify(syncedFile), { overwrite: true });
|
await client.putFileContents(path, JSON.stringify(syncedFile), { overwrite: true });
|
||||||
return { resourceId: path };
|
return { resourceId: path };
|
||||||
@ -167,7 +172,7 @@ const handleWebdavUpload = async (config, syncedFile) => {
|
|||||||
|
|
||||||
const handleWebdavDownload = async (config) => {
|
const handleWebdavDownload = async (config) => {
|
||||||
try {
|
try {
|
||||||
const client = buildWebdavClient(config);
|
const client = await buildWebdavClient(config);
|
||||||
const path = getWebdavPath();
|
const path = getWebdavPath();
|
||||||
const exists = await client.exists(path);
|
const exists = await client.exists(path);
|
||||||
if (!exists) return { syncedFile: null };
|
if (!exists) return { syncedFile: null };
|
||||||
@ -181,7 +186,7 @@ const handleWebdavDownload = async (config) => {
|
|||||||
|
|
||||||
const handleWebdavDelete = async (config) => {
|
const handleWebdavDelete = async (config) => {
|
||||||
try {
|
try {
|
||||||
const client = buildWebdavClient(config);
|
const client = await buildWebdavClient(config);
|
||||||
const path = getWebdavPath();
|
const path = getWebdavPath();
|
||||||
const exists = await client.exists(path);
|
const exists = await client.exists(path);
|
||||||
if (!exists) return { ok: true };
|
if (!exists) return { ok: true };
|
||||||
|
|||||||
@ -13,6 +13,19 @@
|
|||||||
* - windowManager.cjs: Electron window management
|
* - windowManager.cjs: Electron window management
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// HarmonyOS: the full main.cjs startup (80+ bridge requires, GPU switches,
|
||||||
|
// protocol registration, etc.) causes SIGSEGV in V8. Use minimal init.
|
||||||
|
if (process.platform === 'ohos' || process.platform === 'openharmony') {
|
||||||
|
const { app, BrowserWindow } = require("electron");
|
||||||
|
const path = require("path");
|
||||||
|
app.whenReady().then(() => {
|
||||||
|
const distIndex = path.join(__dirname, "..", "dist", "index.html");
|
||||||
|
const win = new BrowserWindow({ width: 1280, height: 800, show: true });
|
||||||
|
win.loadURL("file://" + distIndex);
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Handle environment setup
|
// Handle environment setup
|
||||||
if (process.env.ELECTRON_RUN_AS_NODE) {
|
if (process.env.ELECTRON_RUN_AS_NODE) {
|
||||||
delete process.env.ELECTRON_RUN_AS_NODE;
|
delete process.env.ELECTRON_RUN_AS_NODE;
|
||||||
@ -956,7 +969,7 @@ async function createWindow() {
|
|||||||
// HarmonyOS: windowManager internally calls loadFile() which is not
|
// HarmonyOS: windowManager internally calls loadFile() which is not
|
||||||
// supported by the OpenHarmony Electron runtime. Bypass it entirely
|
// supported by the OpenHarmony Electron runtime. Bypass it entirely
|
||||||
// and create the BrowserWindow ourselves with loadURL('file://…').
|
// and create the BrowserWindow ourselves with loadURL('file://…').
|
||||||
if (process.platform === 'openharmony') {
|
if (process.platform === 'ohos' || process.platform === 'openharmony') {
|
||||||
const distIndex = path.join(electronDir, '..', 'dist', 'index.html');
|
const distIndex = path.join(electronDir, '..', 'dist', 'index.html');
|
||||||
try { fs.writeFileSync('/tmp/ohos_debug.log', 'PLATFORM=' + process.platform + '\nDIST=' + distIndex + '\nEXISTS=' + fs.existsSync(distIndex) + '\n'); } catch {}
|
try { fs.writeFileSync('/tmp/ohos_debug.log', 'PLATFORM=' + process.platform + '\nDIST=' + distIndex + '\nEXISTS=' + fs.existsSync(distIndex) + '\n'); } catch {}
|
||||||
const ohosWin = new BrowserWindow({
|
const ohosWin = new BrowserWindow({
|
||||||
|
|||||||
16000
web_engine/src/main/resources/resfile/resources/app/package-lock.json
generated
Normal file
16000
web_engine/src/main/resources/resfile/resources/app/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user