Skip to content

Commit 51ab988

Browse files
committed
update electron version to 13.1.1
1 parent 2d51248 commit 51ab988

File tree

15 files changed

+144
-59
lines changed

15 files changed

+144
-59
lines changed

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,4 @@ npm-debug.log
66
dist
77
build
88
crash
9-
error
10-
.vscode
9+
error

.prettierrc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"tabWidth": 2,
3+
"useTabs": false,
4+
"semi": false,
5+
"singleQuote": false,
6+
"TrailingCooma": "all",
7+
"bracketSpacing": true,
8+
"jsxBracketSameLine": false,
9+
"arrowParens": "avoid"
10+
}

README.md

Lines changed: 87 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,63 @@
22

33
官网:https://electronjs.org/
44

5+
- [electron-learn](#electron-learn)
6+
- [1. 本次项目功能点](#1-本次项目功能点)
7+
- [目前支持的功能点](#目前支持的功能点)
8+
- [使用方式](#使用方式)
9+
- [2. electron相关软件安装](#2-electron相关软件安装)
10+
- [nvm 安装](#nvm-安装)
11+
- [Node.js/NPM 安装](#nodejsnpm-安装)
12+
- [node 安装加速机器](#node-安装加速机器)
13+
- [Electron 安装](#electron-安装)
14+
- [Electron 加速技巧](#electron-加速技巧)
15+
- [常见问题](#常见问题)
16+
- [3. electron 原理](#3-electron-原理)
17+
- [2.1. 使用 Electron 的 API](#21-使用-electron-的-api)
18+
- [3.2. 使用 Node.js 的 API](#32-使用-nodejs-的-api)
19+
- [4. electron 常用 api](#4-electron-常用-api)
20+
- [4.1. app](#41-app)
21+
- [4.2. BrowserWindow](#42-browserwindow)
22+
- [4.3. ipcMain 和 ipcRenderer](#43-ipcmain-和-ipcrenderer)
23+
- [4.4. Menu/MenuItem(菜单/菜单项)](#44-menumenuitem菜单菜单项)
24+
- [4.5. Tray(托盘)](#45-tray托盘)
25+
- [4.6. clipboard](#46-clipboard)
26+
- [4.7. screen](#47-screen)
27+
- [4.8. globalShortcut](#48-globalshortcut)
28+
- [4.9. desktopCapturer](#49-desktopcapturer)
29+
- [4.10. shell](#410-shell)
30+
- [4.11. powerMonitor 电源监视器](#411-powermonitor-电源监视器)
31+
- [4.12. nativeTheme 读取并响应Chromium本地色彩主题中的变化](#412-nativetheme-读取并响应chromium本地色彩主题中的变化)
32+
- [5. 开机自启动](#5-开机自启动)
33+
- [5.1. node-auto-launch](#51-node-auto-launch)
34+
- [5.2. app.getLoginItemSettings([options])](#52-appgetloginitemsettingsoptions)
35+
- [6. 监控—crashReporter](#6-监控crashreporter)
36+
- [7. 打包](#7-打包)
37+
- [7.1. electron-builder](#71-electron-builder)
38+
- [命令行参数(CLI)](#命令行参数cli)
39+
- [8. 集成c++](#8-集成c)
40+
- [9. 测试和调试](#9-测试和调试)
41+
- [9.1. 调试debug](#91-调试debug)
42+
- [9.2. 自动化测试](#92-自动化测试)
43+
- [10. 更新](#10-更新)
44+
- [11. Electron客户端的安全:从xss到rce](#11-electron客户端的安全从xss到rce)
45+
- [12. 浏览器启动客户端](#12-浏览器启动客户端)
46+
- [12.1. windows平台](#121-windows平台)
47+
- [12.2. mac 平台](#122-mac-平台)
48+
- [12.2.1. info.plist](#1221-infoplist)
49+
- [12.3. 接收参数](#123-接收参数)
50+
- [12.3.1. Windows](#1231-windows)
51+
- [12.3.2. MacOS](#1232-macos)
52+
- [13. 性能优化](#13-性能优化)
53+
- [13.1. 减少包体积大小](#131-减少包体积大小)
54+
- [Electron 开发过程中可能会遇到的几个问题和场景。](#electron-开发过程中可能会遇到的几个问题和场景)
55+
- [NPM 下载的问题](#npm-下载的问题)
56+
- [热重载](#热重载)
57+
- [参考资料](#参考资料)
58+
559
## 1. 本次项目功能点
660

7-
模仿微信,做了一个单机版的聊天,因为只有mac,没有Windows机器,以下仅根据mac来开发。
61+
模仿微信,做了一个单机版的聊天,因为只有mac,没有Windows机器,以下仅根据mac来开发。
862

963
![效果图](images/xiaoguo.gif)
1064

@@ -46,29 +100,6 @@ cd updater-server
46100
node index.js
47101
```
48102

49-
### 参考资料
50-
51-
1. electron 优化 https://juejin.im/post/5e0010866fb9a015fd69c645
52-
53-
Electron的主进程阻塞导致UI卡顿的问题 https://zhuanlan.zhihu.com/p/37050595
54-
55-
2. 打包:mac 文件签名:https://www.cnblogs.com/lovesong/p/11782449.html
56-
https://www.cnblogs.com/qirui/p/8327812.html
57-
58-
3. 集成c++
59-
https://www.jianshu.com/p/93ffa05f028f
60-
https://blog.csdn.net/wang839305939/article/details/83780789
61-
https://www.jianshu.com/p/5a4c7ce2be54
62-
https://www.dazhuanlan.com/2019/09/23/5d88a0bc8ec13/
63-
https://stackoverflow.com/questions/32986826/calling-node-native-addons-c-in-electron
64-
65-
4. 奔溃报告上传 https://juejin.im/post/5c5ee47be51d457f95354c82
66-
https://www.electronjs.org/docs/api/crash-reporter
67-
68-
5. debugger https://cloud.tencent.com/developer/section/1116142
69-
70-
6. 测试和调试 https://www.bookstack.cn/read/electron-v6.0-zh/dda8a7a000404b49.md
71-
72103

73104
## 2. electron相关软件安装
74105

@@ -117,6 +148,15 @@ npx electron -v (npm > 5.2)
117148
ELECTRON_MIRROR=https://cdn.npm.taobao.org/dist/electron/ npm install electron --save- dev
118149
```
119150

151+
### 常见问题
152+
153+
> Electron failed to install correctly, please delete node_modules/electron and try installing again
154+
155+
1. 首先 npm instal或者yarn install
156+
2. 执行 npm install electron-fix -g
157+
3. 接着 electron-fix start
158+
4. 最后再 npm start
159+
120160
## 3. electron 原理
121161

122162
Node.js 和 Chromiums 整合
@@ -614,15 +654,13 @@ shell.openExternal('https://github.com')
614654

615655
```
616656

617-
##### 方法
618-
619657
shell.showItemInFolder(fullPath)
620658
fullPath String
621659
在文件管理器中显示给定的文件。如果可以, 选中该文件。
622660

623-
shell.openItem(fullPath)
661+
shell.openItem(fullPath)
624662
fullPath String
625-
返回 Boolean - 文件是否成功打开,以桌面的默认方式打开给定的文件。
663+
返回 Boolean - 文件是否成功打开,以桌面的默认方式打开给定的文件。
626664

627665
shell.beep()
628666
播放哔哔的声音.
@@ -1469,5 +1507,25 @@ init()
14691507

14701508

14711509

1510+
### 参考资料
1511+
1512+
1. electron 优化 https://juejin.im/post/5e0010866fb9a015fd69c645
1513+
1514+
Electron的主进程阻塞导致UI卡顿的问题 https://zhuanlan.zhihu.com/p/37050595
1515+
1516+
2. 打包:mac 文件签名:https://www.cnblogs.com/lovesong/p/11782449.html
1517+
https://www.cnblogs.com/qirui/p/8327812.html
1518+
1519+
3. 集成c++
1520+
https://www.jianshu.com/p/93ffa05f028f
1521+
https://blog.csdn.net/wang839305939/article/details/83780789
1522+
https://www.jianshu.com/p/5a4c7ce2be54
1523+
https://www.dazhuanlan.com/2019/09/23/5d88a0bc8ec13/
1524+
https://stackoverflow.com/questions/32986826/calling-node-native-addons-c-in-electron
1525+
1526+
4. 奔溃报告上传 https://juejin.im/post/5c5ee47be51d457f95354c82
1527+
https://www.electronjs.org/docs/api/crash-reporter
1528+
1529+
5. debugger https://cloud.tencent.com/developer/section/1116142
14721530

1473-
### 热更新
1531+
6. 测试和调试 https://www.bookstack.cn/read/electron-v6.0-zh/dda8a7a000404b49.md

package-lock.json

Lines changed: 7 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"start:main": "electron .",
1111
"pack:mac": "electron-builder --mac",
1212
"build:render": "webpack --env prod",
13-
"build": "npm run build:render && npm run pack:mac"
13+
"build": "npm run build:render && npm run pack:mac",
14+
"fix": "electron-fix start"
1415
},
1516
"author": "Ivy",
1617
"license": "ISC",
@@ -28,7 +29,7 @@
2829
"clean-webpack-plugin": "^3.0.0",
2930
"concurrently": "^5.2.0",
3031
"css-loader": "^3.5.3",
31-
"electron": "^12.0.9",
32+
"electron": "^13.1.1",
3233
"electron-builder": "^22.10.5",
3334
"electron-fix": "^1.1.3",
3435
"extract-text-webpack-plugin": "^4.0.0-beta.0",

src/lib/capture/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
left: 0;
3030
width: 100%;
3131
height: 100%;
32-
background: rgba(0, 0, 0, 0.3);
32+
/* background: rgba(0, 0, 0, 0.3); */
3333
}
3434

3535
.rect {

src/lib/capture/js/draw.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ class Draw {
6060
//创建新的canvas上下文作为存储,方便取出里面的rgba信息
6161
this.$bgCanvas = document.createElement('canvas');
6262
this.$bgCtx = this.$bgCanvas.getContext('2d');
63+
// 拿到原图后,再加截屏遮罩
64+
const mask = document.querySelector('#mask');
65+
mask.style.backgroundColor = 'rgba(0, 0, 0, 0.3)';
6366

6467
//新建一个图片,用来放进canvas存图片数据
6568
const imgCanvas = await new Promise((resolve) => {

src/lib/capture/main.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { BrowserWindow, globalShortcut, ipcMain } = require('electron');
1+
const { BrowserWindow, globalShortcut, ipcMain, app } = require('electron');
22

33
const path = require('path');
44
let capWin;
@@ -32,8 +32,10 @@ function createCaptureWindow() {
3232
transparent: true,
3333
frame: false,
3434
movable: false,
35+
skipTaskbar: true,
36+
autoHideMenuBar: true,
3537
resizable: false,
36-
enableLargerThanScreen: true,
38+
enableLargerThanScreen: true, // mac
3739
hasShadow: false,
3840
webPreferences: {
3941
nodeIntegration: true,
@@ -42,15 +44,15 @@ function createCaptureWindow() {
4244
},
4345
});
4446

47+
app.dock.hide();
4548
capWin.setAlwaysOnTop(true, 'screen-saver');
4649
capWin.setVisibleOnAllWorkspaces(true);
4750
capWin.setSimpleFullScreen(true);
48-
// capWin.setFullScreenable(false)
49-
51+
// capWin.setFullScreenable(false) // mac
5052
capWin.loadFile(path.join(__dirname, './index.html'));
5153

5254
// 打开开发者工具
53-
// capWin.webContents.openDevTools()
55+
// capWin.webContents.openDevTools();
5456

5557
capWin.on('closed', () => {
5658
capWin = null;

src/renderer/components/Message/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ import React from 'react';
22
import Text from './Text';
33
import Tip from './Tip';
44
import Image from './Image.jsx';
5+
import { USER_NAME } from '../../constants';
56
import './index.scss';
67

78
const AvatarRender = (msg) => {
89
return (
910
<img
1011
className="chat-avatar"
11-
src={require(`../../../resources/images/users/${msg.fromId === 'ivy' ? 'user' : msg.fromId}.png`)}
12+
src={require(`../../../resources/images/users/${msg.fromId === USER_NAME ? 'user' : msg.fromId}.png`)}
1213
/>
1314
);
1415
};
@@ -31,7 +32,7 @@ const MsgRender = (msg) => {
3132
}
3233

3334
return (
34-
<div key={msg.id} className={`msg-item clearfix ${msg.type !== 2 ? (msg.fromId === 'ivy' ? 'right' : 'left') : ''}`}>
35+
<div key={msg.id} className={`msg-item clearfix ${msg.type !== 2 ? (msg.fromId === USER_NAME ? 'right' : 'left') : ''}`}>
3536
{msg.type !== 2 ? AvatarRender(msg) : null}
3637
{content}
3738
</div>

0 commit comments

Comments
 (0)