electron-screenshots 0.5.22 → 0.5.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +231 -225
- package/lib/demo.d.ts +1 -0
- package/lib/demo.js +62 -0
- package/lib/index.cjs.d.ts +0 -0
- package/lib/index.cjs.js +2 -0
- package/lib/index.d.ts +57 -1
- package/lib/index.js +450 -51
- package/package.json +6 -5
- package/lib/screenshots.d.ts +0 -57
- package/lib/screenshots.js +0 -458
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2019 nashaofu
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 nashaofu
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,225 +1,231 @@
|
|
|
1
|
-
# electron-screenshots
|
|
2
|
-
|
|
3
|
-
> electron 截图插件
|
|
4
|
-
|
|
5
|
-
## Prerequisites
|
|
6
|
-
|
|
7
|
-
- electron >= 11
|
|
8
|
-
|
|
9
|
-
## Install
|
|
10
|
-
|
|
11
|
-
[](https://nodei.co/npm/electron-screenshots/)
|
|
12
|
-
|
|
13
|
-
## Usage
|
|
14
|
-
|
|
15
|
-
```ts
|
|
16
|
-
import debug from "electron-debug";
|
|
17
|
-
import { app, globalShortcut } from "electron";
|
|
18
|
-
import Screenshots from "./screenshots";
|
|
19
|
-
|
|
20
|
-
app.whenReady().then(() => {
|
|
21
|
-
const screenshots = new Screenshots();
|
|
22
|
-
globalShortcut.register("ctrl+shift+a", () => {
|
|
23
|
-
screenshots.startCapture();
|
|
24
|
-
screenshots.$view.webContents.openDevTools();
|
|
25
|
-
});
|
|
26
|
-
// 点击确定按钮回调事件
|
|
27
|
-
screenshots.on("ok", (e, buffer, bounds) => {
|
|
28
|
-
console.log("capture", buffer, bounds);
|
|
29
|
-
});
|
|
30
|
-
// 点击取消按钮回调事件
|
|
31
|
-
screenshots.on("cancel", () => {
|
|
32
|
-
console.log("capture", "cancel1");
|
|
33
|
-
});
|
|
34
|
-
screenshots.on("cancel", (e) => {
|
|
35
|
-
// 执行了preventDefault
|
|
36
|
-
// 点击取消不会关闭截图窗口
|
|
37
|
-
e.preventDefault();
|
|
38
|
-
console.log("capture", "cancel2");
|
|
39
|
-
});
|
|
40
|
-
// 点击保存按钮回调事件
|
|
41
|
-
screenshots.on("save", (e, buffer, bounds) => {
|
|
42
|
-
console.log("capture", buffer, bounds);
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
//
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
|
184
|
-
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
1
|
+
# electron-screenshots
|
|
2
|
+
|
|
3
|
+
> electron 截图插件
|
|
4
|
+
|
|
5
|
+
## Prerequisites
|
|
6
|
+
|
|
7
|
+
- electron >= 11
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
[](https://nodei.co/npm/electron-screenshots/)
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import debug from "electron-debug";
|
|
17
|
+
import { app, globalShortcut } from "electron";
|
|
18
|
+
import Screenshots from "./screenshots";
|
|
19
|
+
|
|
20
|
+
app.whenReady().then(() => {
|
|
21
|
+
const screenshots = new Screenshots();
|
|
22
|
+
globalShortcut.register("ctrl+shift+a", () => {
|
|
23
|
+
screenshots.startCapture();
|
|
24
|
+
screenshots.$view.webContents.openDevTools();
|
|
25
|
+
});
|
|
26
|
+
// 点击确定按钮回调事件
|
|
27
|
+
screenshots.on("ok", (e, buffer, bounds) => {
|
|
28
|
+
console.log("capture", buffer, bounds);
|
|
29
|
+
});
|
|
30
|
+
// 点击取消按钮回调事件
|
|
31
|
+
screenshots.on("cancel", () => {
|
|
32
|
+
console.log("capture", "cancel1");
|
|
33
|
+
});
|
|
34
|
+
screenshots.on("cancel", (e) => {
|
|
35
|
+
// 执行了preventDefault
|
|
36
|
+
// 点击取消不会关闭截图窗口
|
|
37
|
+
e.preventDefault();
|
|
38
|
+
console.log("capture", "cancel2");
|
|
39
|
+
});
|
|
40
|
+
// 点击保存按钮回调事件
|
|
41
|
+
screenshots.on("save", (e, buffer, bounds) => {
|
|
42
|
+
console.log("capture", buffer, bounds);
|
|
43
|
+
});
|
|
44
|
+
// 保存后的回调事件
|
|
45
|
+
screenshots.on("afterSave", (e, buffer, bounds, isSaved) => {
|
|
46
|
+
console.log("capture", buffer, bounds);
|
|
47
|
+
console.log("isSaved", isSaved) // 是否保存成功
|
|
48
|
+
});
|
|
49
|
+
debug({ showDevTools: true, devToolsMode: "undocked" });
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
app.on("window-all-closed", () => {
|
|
53
|
+
if (process.platform !== "darwin") {
|
|
54
|
+
app.quit();
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### 注意
|
|
60
|
+
|
|
61
|
+
- 如果使用了 webpack 打包主进程,请在主进程 webpack 配置中修改如下配置,否则可能会出现不能调用截图窗口的情况
|
|
62
|
+
|
|
63
|
+
```js
|
|
64
|
+
{
|
|
65
|
+
externals: {
|
|
66
|
+
'electron-screenshots': 'require("electron-screenshots")'
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
- `vue-cli-plugin-electron-builder`配置示例[vue-cli-plugin-electron-builder-issue](https://github.com/nashaofu/vue-cli-plugin-electron-builder-issue/blob/0f774a90b09e10b02f86fcb6b50645058fe1a4e8/vue.config.js#L1-L8)
|
|
72
|
+
|
|
73
|
+
```js
|
|
74
|
+
// vue.config.js
|
|
75
|
+
module.exports = {
|
|
76
|
+
publicPath: ".",
|
|
77
|
+
pluginOptions: {
|
|
78
|
+
electronBuilder: {
|
|
79
|
+
// 不打包,使用 require 加载
|
|
80
|
+
externals: ["electron-screenshots"],
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
- esc 取消截图,可用以下代码实现按 esc 取消截图
|
|
87
|
+
|
|
88
|
+
```js
|
|
89
|
+
globalShortcut.register("esc", () => {
|
|
90
|
+
if (screenshots.$win?.isFocused()) {
|
|
91
|
+
screenshots.endCapture();
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
- 加速截图界面展示,不销毁`BrowserWindow`,减少创建窗口的开销,可用以下代码实现。**需注意,启用该功能,会导致`window-all-closed`事件不触发,因此需要手动关闭截图窗口**
|
|
97
|
+
|
|
98
|
+
```js
|
|
99
|
+
// 是否复用截图窗口,加快截图窗口显示,默认值为 false
|
|
100
|
+
// 如果设置为 true 则会在第一次调用截图窗口时创建,后续调用时直接使用
|
|
101
|
+
// 且由于窗口不会 close,所以不会触发 app 的 `window-all-closed` 事件
|
|
102
|
+
const screenshots = new Screenshots({
|
|
103
|
+
singleWindow: true,
|
|
104
|
+
});
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## Methods
|
|
108
|
+
|
|
109
|
+
- `Debugger`类型产考[debug](https://github.com/debug-js/debug)中的`Debugger`类型
|
|
110
|
+
|
|
111
|
+
```ts
|
|
112
|
+
export type LoggerFn = (...args: unknown[]) => void;
|
|
113
|
+
export type Logger = Debugger | LoggerFn;
|
|
114
|
+
|
|
115
|
+
export interface Lang {
|
|
116
|
+
magnifier_position_label?: string;
|
|
117
|
+
operation_ok_title?: string;
|
|
118
|
+
operation_cancel_title?: string;
|
|
119
|
+
operation_save_title?: string;
|
|
120
|
+
operation_redo_title?: string;
|
|
121
|
+
operation_undo_title?: string;
|
|
122
|
+
operation_mosaic_title?: string;
|
|
123
|
+
operation_text_title?: string;
|
|
124
|
+
operation_brush_title?: string;
|
|
125
|
+
operation_arrow_title?: string;
|
|
126
|
+
operation_ellipse_title?: string;
|
|
127
|
+
operation_rectangle_title?: string;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export interface ScreenshotsOpts {
|
|
131
|
+
lang?: Lang;
|
|
132
|
+
// 调用日志,默认值为 debug('electron-screenshots')
|
|
133
|
+
// debug https://www.npmjs.com/package/debug
|
|
134
|
+
logger?: Logger;
|
|
135
|
+
// 是否复用截图窗口,加快截图窗口显示,默认值为 false
|
|
136
|
+
// 如果设置为 true 则会在第一次调用截图窗口时创建,后续调用时直接使用
|
|
137
|
+
// 且由于窗口不会 close,所以不会触发 app 的 `window-all-closed` 事件
|
|
138
|
+
singleWindow?: boolean;
|
|
139
|
+
}
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
| 名称 | 说明 | 返回值 |
|
|
143
|
+
| ------------------------------------------------- | ---------------- | ------ |
|
|
144
|
+
| `constructor(opts: ScreenshotsOpts): Screenshots` | 调用截图方法截图 | - |
|
|
145
|
+
| `startCapture(): Promise<void>` | 调用截图方法截图 | - |
|
|
146
|
+
| `endCapture(): Promise<void>` | 手动结束截图 | - |
|
|
147
|
+
| `setLang(lang: Lang): Promise<void>` | 修改语言 | - |
|
|
148
|
+
|
|
149
|
+
## Events
|
|
150
|
+
|
|
151
|
+
- 数据类型
|
|
152
|
+
|
|
153
|
+
```ts
|
|
154
|
+
interface Bounds {
|
|
155
|
+
x: number;
|
|
156
|
+
y: number;
|
|
157
|
+
width: number;
|
|
158
|
+
height: number;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export interface Display {
|
|
162
|
+
id: number;
|
|
163
|
+
x: number;
|
|
164
|
+
y: number;
|
|
165
|
+
width: number;
|
|
166
|
+
height: number;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export interface ScreenshotsData {
|
|
170
|
+
bounds: Bounds;
|
|
171
|
+
display: Display;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
class Event {
|
|
175
|
+
public defaultPrevented = false;
|
|
176
|
+
|
|
177
|
+
public preventDefault(): void {
|
|
178
|
+
this.defaultPrevented = true;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
| 名称 | 说明 | 回调参数 |
|
|
184
|
+
| ------------- | ----------------------------------------------------------- | --------------------------------------------------------------------------------- |
|
|
185
|
+
| ok | 截图确认事件 | `(event: Event, buffer: Buffer, data: ScreenshotsData) => void` |
|
|
186
|
+
| cancel | 截图取消事件 | `(event: Event) => void` |
|
|
187
|
+
| save | 截图保存事件 | `(event: Event, buffer: Buffer, data: ScreenshotsData) => void` |
|
|
188
|
+
| afterSave | 截图保存(取消保存)后的事件 | `(event: Event, buffer: Buffer, data: ScreenshotsData, isSaved: boolean) => void` |
|
|
189
|
+
| windowCreated | 截图窗口被创建后触发 | `($win: BrowserWindow) => void` |
|
|
190
|
+
| windowClosed | 截图窗口被关闭后触发,对`BrowserWindow` `closed` 事件的转发 | `($win: BrowserWindow) => void` |
|
|
191
|
+
|
|
192
|
+
### 说明
|
|
193
|
+
|
|
194
|
+
- event: 事件对象
|
|
195
|
+
- buffer: png 图片 buffer
|
|
196
|
+
- bounds: 截图区域信息
|
|
197
|
+
- display: 截图的屏幕
|
|
198
|
+
- `event`对象可调用`preventDefault`方法来阻止默认事件,例如阻止默认保存事件
|
|
199
|
+
|
|
200
|
+
```ts
|
|
201
|
+
const screenshots = new Screenshots({
|
|
202
|
+
lang: {
|
|
203
|
+
magnifier_position_label: "Position",
|
|
204
|
+
operation_ok_title: "Ok",
|
|
205
|
+
operation_cancel_title: "Cancel",
|
|
206
|
+
operation_save_title: "Save",
|
|
207
|
+
operation_redo_title: "Redo",
|
|
208
|
+
operation_undo_title: "Undo",
|
|
209
|
+
operation_mosaic_title: "Mosaic",
|
|
210
|
+
operation_text_title: "Text",
|
|
211
|
+
operation_brush_title: "Brush",
|
|
212
|
+
operation_arrow_title: "Arrow",
|
|
213
|
+
operation_ellipse_title: "Ellipse",
|
|
214
|
+
operation_rectangle_title: "Rectangle",
|
|
215
|
+
},
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
screenshots.on("save", (e, buffer, data) => {
|
|
219
|
+
// 阻止插件自带的保存功能
|
|
220
|
+
// 用户自己控制保存功能
|
|
221
|
+
e.preventDefault();
|
|
222
|
+
// 用户可在这里自己定义保存功能
|
|
223
|
+
console.log("capture", buffer, data);
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
screenshots.startCapture();
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
## Screenshot
|
|
230
|
+
|
|
231
|
+

|
package/lib/demo.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/lib/demo.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
/* eslint-disable no-console */
|
|
7
|
+
var electron_1 = require("electron");
|
|
8
|
+
var _1 = __importDefault(require("."));
|
|
9
|
+
electron_1.app.whenReady().then(function () {
|
|
10
|
+
var screenshots = new _1.default({
|
|
11
|
+
lang: {
|
|
12
|
+
operation_rectangle_title: '矩形2323',
|
|
13
|
+
},
|
|
14
|
+
singleWindow: true,
|
|
15
|
+
});
|
|
16
|
+
screenshots.$view.webContents.openDevTools();
|
|
17
|
+
electron_1.globalShortcut.register('ctrl+shift+a', function () {
|
|
18
|
+
screenshots.startCapture();
|
|
19
|
+
});
|
|
20
|
+
screenshots.on('windowCreated', function ($win) {
|
|
21
|
+
$win.on('focus', function () {
|
|
22
|
+
electron_1.globalShortcut.register('esc', function () {
|
|
23
|
+
if ($win === null || $win === void 0 ? void 0 : $win.isFocused()) {
|
|
24
|
+
screenshots.endCapture();
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
$win.on('blur', function () {
|
|
29
|
+
electron_1.globalShortcut.unregister('esc');
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
// 防止不能关闭截图界面
|
|
33
|
+
electron_1.globalShortcut.register('ctrl+shift+q', function () {
|
|
34
|
+
electron_1.app.quit();
|
|
35
|
+
});
|
|
36
|
+
// 点击确定按钮回调事件
|
|
37
|
+
screenshots.on('ok', function (e, buffer, bounds) {
|
|
38
|
+
console.log('capture', buffer, bounds);
|
|
39
|
+
});
|
|
40
|
+
// 点击取消按钮回调事件
|
|
41
|
+
screenshots.on('cancel', function () {
|
|
42
|
+
console.log('capture', 'cancel1');
|
|
43
|
+
screenshots.setLang({
|
|
44
|
+
operation_ellipse_title: 'ellipse',
|
|
45
|
+
operation_rectangle_title: 'rectangle',
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
// 点击保存按钮回调事件
|
|
49
|
+
screenshots.on('save', function (e, buffer, bounds) {
|
|
50
|
+
console.log('capture', buffer, bounds);
|
|
51
|
+
});
|
|
52
|
+
var mainWin = new electron_1.BrowserWindow({
|
|
53
|
+
show: true,
|
|
54
|
+
});
|
|
55
|
+
mainWin.removeMenu();
|
|
56
|
+
mainWin.loadURL('https://github.com/nashaofu');
|
|
57
|
+
});
|
|
58
|
+
electron_1.app.on('window-all-closed', function () {
|
|
59
|
+
if (process.platform !== 'darwin') {
|
|
60
|
+
electron_1.app.quit();
|
|
61
|
+
}
|
|
62
|
+
});
|
|
File without changes
|
package/lib/index.cjs.js
ADDED
package/lib/index.d.ts
CHANGED
|
@@ -1 +1,57 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Debugger } from 'debug';
|
|
3
|
+
import { BrowserView, BrowserWindow } from 'electron';
|
|
4
|
+
import Events from 'events';
|
|
5
|
+
import { Bounds } from './preload';
|
|
6
|
+
export type LoggerFn = (...args: unknown[]) => void;
|
|
7
|
+
export type Logger = Debugger | LoggerFn;
|
|
8
|
+
export interface Lang {
|
|
9
|
+
magnifier_position_label?: string;
|
|
10
|
+
operation_ok_title?: string;
|
|
11
|
+
operation_cancel_title?: string;
|
|
12
|
+
operation_save_title?: string;
|
|
13
|
+
operation_redo_title?: string;
|
|
14
|
+
operation_undo_title?: string;
|
|
15
|
+
operation_mosaic_title?: string;
|
|
16
|
+
operation_text_title?: string;
|
|
17
|
+
operation_brush_title?: string;
|
|
18
|
+
operation_arrow_title?: string;
|
|
19
|
+
operation_ellipse_title?: string;
|
|
20
|
+
operation_rectangle_title?: string;
|
|
21
|
+
}
|
|
22
|
+
export interface ScreenshotsOpts {
|
|
23
|
+
lang?: Lang;
|
|
24
|
+
logger?: Logger;
|
|
25
|
+
singleWindow?: boolean;
|
|
26
|
+
}
|
|
27
|
+
export { Bounds };
|
|
28
|
+
export default class Screenshots extends Events {
|
|
29
|
+
$win: BrowserWindow | null;
|
|
30
|
+
$view: BrowserView;
|
|
31
|
+
private logger;
|
|
32
|
+
private singleWindow;
|
|
33
|
+
private isReady;
|
|
34
|
+
constructor(opts?: ScreenshotsOpts);
|
|
35
|
+
/**
|
|
36
|
+
* 开始截图
|
|
37
|
+
*/
|
|
38
|
+
startCapture(): Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* 结束截图
|
|
41
|
+
*/
|
|
42
|
+
endCapture(): Promise<void>;
|
|
43
|
+
/**
|
|
44
|
+
* 设置语言
|
|
45
|
+
*/
|
|
46
|
+
setLang(lang: Partial<Lang>): Promise<void>;
|
|
47
|
+
private reset;
|
|
48
|
+
/**
|
|
49
|
+
* 初始化窗口
|
|
50
|
+
*/
|
|
51
|
+
private createWindow;
|
|
52
|
+
private capture;
|
|
53
|
+
/**
|
|
54
|
+
* 绑定ipc时间处理
|
|
55
|
+
*/
|
|
56
|
+
private listenIpc;
|
|
57
|
+
}
|