惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

AI
AI
Engineering at Meta
Engineering at Meta
T
The Blog of Author Tim Ferriss
Latest news
Latest news
Microsoft Azure Blog
Microsoft Azure Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Simon Willison's Weblog
Simon Willison's Weblog
M
MIT News - Artificial intelligence
V
Visual Studio Blog
N
Netflix TechBlog - Medium
P
Palo Alto Networks Blog
C
Cybersecurity and Infrastructure Security Agency CISA
阮一峰的网络日志
阮一峰的网络日志
P
Proofpoint News Feed
G
Google Developers Blog
MongoDB | Blog
MongoDB | Blog
V
Vulnerabilities – Threatpost
AWS News Blog
AWS News Blog
美团技术团队
博客园 - 聂微东
The GitHub Blog
The GitHub Blog
Stack Overflow Blog
Stack Overflow Blog
The Hacker News
The Hacker News
C
CXSECURITY Database RSS Feed - CXSecurity.com
L
Lohrmann on Cybersecurity
B
Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
爱范儿
爱范儿
Hacker News - Newest:
Hacker News - Newest: "LLM"
Hugging Face - Blog
Hugging Face - Blog
O
OpenAI News
W
WeLiveSecurity
Cisco Talos Blog
Cisco Talos Blog
Google Online Security Blog
Google Online Security Blog
T
Tenable Blog
Attack and Defense Labs
Attack and Defense Labs
C
Cisco Blogs
G
GRAHAM CLULEY
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Y
Y Combinator Blog
Microsoft Security Blog
Microsoft Security Blog
Help Net Security
Help Net Security
The Last Watchdog
The Last Watchdog
S
Security @ Cisco Blogs
C
CERT Recently Published Vulnerability Notes
博客园 - 【当耐特】
T
Troy Hunt's Blog
Cloudbric
Cloudbric
IT之家
IT之家

虹墨空间站

浏览器直接访问正常,过了负载均衡就崩了?只因响应头里多了个空格 Claude Code 怎样快速消耗 token 去掉高德地图开屏广告 解决 Claude Code 安装或更新后 claude.exe 无法运行、claude native binary not installed Windows 11 26H1 显示所有托盘图标 OpenClaw 安装与配置 盘点手里的电子产品传家宝 基于 7z 的 NAS 到网盘备份解决方案,支持增量、分卷、加密、压缩 卸载百度网盘智能看图 CDN 方式引入 Monaco Editor 在线工具 - 富文本转 Markdown 2025 年了,安卓平板上什么第三方九键输入法最好用? bat 脚本打印输出彩色文字 Android 强制锁定屏幕旋转方向
鸿蒙 PC 编译运行 Electron 应用
iMaeGoo · 2025-08-25 · via 虹墨空间站

华为推出的 MateBook Pro 首次搭载了鸿蒙 PC 操作系统,使其能够直接运行鸿蒙手机应用和鸿蒙平板应用,但仅仅这样只能称得上是『大号平板』。

Electron 框架是优秀的跨平台客户端框架,通过改造,鸿蒙 PC 上也能运行 Electron 应用,具体如何操作呢?

编译 Electron

可以自己编译,也可以用华为预编译好的版本。

自己编译

参考文档:https://gitcode.com/openharmony-sig/electron

编译环境必须使用 Ubuntu 22.04,可以用虚拟机。

编译耗时很长,我用 8 核虚拟机 跑了大概 8 个小时左右,如无特殊需求建议用华为预编译好的版本。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65

sudo apt install -y git-lfs ccache curl python3 python-is-python3 python3-pip
python --version
pip --version


mkdir -p ~/bin
curl https://gitee.com/oschina/repo/raw/fork_flow/repo-py3 > ~/bin/repo
chmod a+x ~/bin/repo
echo 'export PATH=~/bin/:$PATH' >> ~/.bashrc
source ~/.bashrc
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple requests


curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt install -y nodejs
node -v
npm -v


git clone -b master https://gitcode.com/openharmony-sig/electron.git


cd electron
git lfs pull


git config --global user.name "iMaeGoo"
git config --global user.email "mail1st@qq.com"
repo init -u https://gitcode.com/openharmony-tpc/manifest.git -b pc_chromium_132 -m pc_chromium_132_20251106.xml --no-repo-verify
repo sync -c
repo forall -c 'git lfs pull'


pushd src
find -name "*.git*" -exec rm -rf "{}" \;
popd
chmod +x override_files.sh
./override_files.sh


sudo ./src/build/install-build-deps.sh --no-chromeos-fonts


./electron_build.sh


source_path=./Electron实际目录/src/out/musl_64
destination_path=./electron
if [ -d ${destination_path} ];then
rm -rf ${destination_path}
fi
mkdir ${destination_path}
cp ${source_path}/libelectron.so ${destination_path}
cp ${source_path}/libffmpeg.so ${destination_path}
cp ${source_path}/libadapter.so ${destination_path}
cp ${source_path}/electron ${destination_path}
cp ${source_path}/icudtl.dat ${destination_path}
cp ${source_path}/v8_context_snapshot.bin ${destination_path}
cp ${source_path}/chrome_100_percent.pak ${destination_path}
cp ${source_path}/chrome_200_percent.pak ${destination_path}
cp ${source_path}/resources.pak ${destination_path}
mkdir ${destination_path}/locales
cp ${source_path}/locales/zh-CN.pak ${destination_path}/locales
cp ${source_path}/locales/en-US.pak ${destination_path}/locales

使用预编译版本

没有调用 addon 和 ArkTS 的需求时可以直接使用以下二进制 release 包进行开发。

  1. 获取最新日期的二进制 release 包,华为账号登录仓库,下载默认 Electron 34 的 release 包。

  2. 解压

搭建环境

安装 DevEco Studio,目前是 5.1.0,最新版即可

https://developer.huawei.com/consumer/cn/download/

配置环境变量,这样以后能方便地使用 hdc 等命令

假设安装路径是 D:\dev\DevEcoStudio,就在 PATH 中增加 D:\dev\DevEcoStudio\sdk\default\openharmony\toolchains

运行项目

打开 DevEco,打开前面编译/下载好的项目 ohos_hap

首次运行需要证书,按提示登录华为账号即可生成证书

跑起来的效果,按 Ctrl + Alt + I 可以打开调试

Electron 的入口点在 src/main/resources/resfile/resources/app/main.js,修改后重新运行即可看到效果

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
const { app, BrowserWindow, Tray, nativeImage } = require('electron');
const path = require('path');

let mainWindow, tray;

function createWindow() {
tray = new Tray(nativeImage.createFromPath(path.join(__dirname, 'electron_white.png')));
mainWindow = new BrowserWindow({
width: 800,
height: 600,
});
mainWindow.setWindowButtonVisibility(true);
mainWindow.loadURL('https://caiyunapp.com/map/');
}
app.whenReady().then(createWindow);