electron-screenshots 0.5.14 → 0.5.16

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 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,223 +1,223 @@
1
- # electron-screenshots
2
-
3
- > electron 截图插件
4
-
5
- ## Prerequisites
6
-
7
- - electron >= 11
8
-
9
- ## Install
10
-
11
- [![NPM](https://nodei.co/npm/electron-screenshots.png?downloads=true&downloadRank=true&stars=true)](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
- debug({ showDevTools: true, devToolsMode: 'undocked' })
45
- })
46
-
47
- app.on('window-all-closed', () => {
48
- if (process.platform !== 'darwin') {
49
- app.quit()
50
- }
51
- })
52
- ```
53
-
54
- ### 注意
55
-
56
- - 如果使用了 webpack 打包主进程,请在主进程 webpack 配置中修改如下配置,否则可能会出现不能调用截图窗口的情况
57
-
58
- ```js
59
- {
60
- externals: {
61
- 'electron-screenshots': 'require("electron-screenshots")'
62
- }
63
- }
64
- ```
65
-
66
- - `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)
67
-
68
- ```js
69
- // vue.config.js
70
- module.exports = {
71
- publicPath: '.',
72
- pluginOptions: {
73
- electronBuilder: {
74
- // 不打包,使用 require 加载
75
- externals: ['electron-screenshots']
76
- }
77
- }
78
- }
79
- ```
80
-
81
- - esc 取消截图,可用以下代码实现按 esc 取消截图
82
-
83
- ```js
84
- globalShortcut.register('esc', () => {
85
- if (screenshots.$win?.isFocused()) {
86
- screenshots.endCapture()
87
- }
88
- })
89
- ```
90
-
91
- - 加速截图界面展示,不销毁`BrowserWindow`,减少创建窗口的开销,可用以下代码实现。**需注意,启用该功能,会导致`window-all-closed`事件不触发,因此需要手动关闭截图窗口**
92
-
93
- ```js
94
- // 是否复用截图窗口,加快截图窗口显示,默认值为 false
95
- // 如果设置为 true 则会在第一次调用截图窗口时创建,后续调用时直接使用
96
- // 且由于窗口不会 close,所以不会触发 app 的 `window-all-closed` 事件
97
- const screenshots = new Screenshots({
98
- singleWindow: true
99
- })
100
- ```
101
-
102
- ## Methods
103
-
104
- - `Debugger`类型产考`debug`中的`Debugger`类型
105
-
106
- ```ts
107
- export type LoggerFn = (...args: unknown[]) => void
108
- export type Logger = Debugger | LoggerFn
109
-
110
- export interface Lang {
111
- magnifier_position_label?: string
112
- operation_ok_title?: string
113
- operation_cancel_title?: string
114
- operation_save_title?: string
115
- operation_redo_title?: string
116
- operation_undo_title?: string
117
- operation_mosaic_title?: string
118
- operation_text_title?: string
119
- operation_brush_title?: string
120
- operation_arrow_title?: string
121
- operation_ellipse_title?: string
122
- operation_rectangle_title?: string
123
- }
124
-
125
- export interface ScreenshotsOpts {
126
- lang?: Lang
127
- // 调用日志,默认值为 debug('electron-screenshots')
128
- // debug https://www.npmjs.com/package/debug
129
- logger?: Logger
130
- // 是否复用截图窗口,加快截图窗口显示,默认值为 false
131
- // 如果设置为 true 则会在第一次调用截图窗口时创建,后续调用时直接使用
132
- // 且由于窗口不会 close,所以不会触发 app 的 `window-all-closed` 事件
133
- singleWindow?: boolean
134
- }
135
- ```
136
-
137
- | 名称 | 说明 | 返回值 |
138
- | ------------------------------------------------- | ---------------- | ------ |
139
- | `constructor(opts: ScreenshotsOpts): Screenshots` | 调用截图方法截图 | - |
140
- | `startCapture(): Promise<void>` | 调用截图方法截图 | - |
141
- | `endCapture(): Promise<void>` | 手动结束截图 | - |
142
- | `setLang(lang: Lang): Promise<void>` | 修改语言 | - |
143
-
144
- ## Events
145
-
146
- - 数据类型
147
-
148
- ```ts
149
- interface Bounds {
150
- x: number
151
- y: number
152
- width: number
153
- height: number
154
- }
155
-
156
- export interface Display {
157
- id: number
158
- x: number
159
- y: number
160
- width: number
161
- height: number
162
- }
163
-
164
- export interface ScreenshotsData {
165
- bounds: Bounds
166
- display: Display
167
- }
168
-
169
- class Event {
170
- public defaultPrevented = false
171
-
172
- public preventDefault(): void {
173
- this.defaultPrevented = true
174
- }
175
- }
176
- ```
177
-
178
- | 名称 | 说明 | 回调参数 |
179
- | ------ | ------------ | --------------------------------------------------------------- |
180
- | ok | 截图确认事件 | `(event: Event, buffer: Buffer, data: ScreenshotsData) => void` |
181
- | cancel | 截图取消事件 | `(event: Event) => void` |
182
- | save | 截图保存事件 | `(event: Event, buffer: Buffer, data: ScreenshotsData) => void` |
183
-
184
- ### 说明
185
-
186
- - event: 事件对象
187
- - buffer: png 图片 buffer
188
- - bounds: 截图区域信息
189
- - display: 截图的屏幕
190
- - `event`对象可调用`preventDefault`方法来阻止默认事件,例如阻止默认保存事件
191
-
192
- ```ts
193
- const screenshots = new Screenshots({
194
- lang: {
195
- magnifier_position_label: 'Position',
196
- operation_ok_title: 'Ok',
197
- operation_cancel_title: 'Cancel',
198
- operation_save_title: 'Save',
199
- operation_redo_title: 'Redo',
200
- operation_undo_title: 'Undo',
201
- operation_mosaic_title: 'Mosaic',
202
- operation_text_title: 'Text',
203
- operation_brush_title: 'Brush',
204
- operation_arrow_title: 'Arrow',
205
- operation_ellipse_title: 'Ellipse',
206
- operation_rectangle_title: 'Rectangle'
207
- }
208
- })
209
-
210
- screenshots.on('save', (e, buffer, data) => {
211
- // 阻止插件自带的保存功能
212
- // 用户自己控制保存功能
213
- e.preventDefault()
214
- // 用户可在这里自己定义保存功能
215
- console.log('capture', buffer, data)
216
- })
217
-
218
- screenshots.startCapture()
219
- ```
220
-
221
- ## Screenshot
222
-
223
- ![screenshot](../../screenshot.jpg)
1
+ # electron-screenshots
2
+
3
+ > electron 截图插件
4
+
5
+ ## Prerequisites
6
+
7
+ - electron >= 11
8
+
9
+ ## Install
10
+
11
+ [![NPM](https://nodei.co/npm/electron-screenshots.png?downloads=true&downloadRank=true&stars=true)](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
+ debug({ showDevTools: true, devToolsMode: 'undocked' })
45
+ })
46
+
47
+ app.on('window-all-closed', () => {
48
+ if (process.platform !== 'darwin') {
49
+ app.quit()
50
+ }
51
+ })
52
+ ```
53
+
54
+ ### 注意
55
+
56
+ - 如果使用了 webpack 打包主进程,请在主进程 webpack 配置中修改如下配置,否则可能会出现不能调用截图窗口的情况
57
+
58
+ ```js
59
+ {
60
+ externals: {
61
+ 'electron-screenshots': 'require("electron-screenshots")'
62
+ }
63
+ }
64
+ ```
65
+
66
+ - `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)
67
+
68
+ ```js
69
+ // vue.config.js
70
+ module.exports = {
71
+ publicPath: '.',
72
+ pluginOptions: {
73
+ electronBuilder: {
74
+ // 不打包,使用 require 加载
75
+ externals: ['electron-screenshots']
76
+ }
77
+ }
78
+ }
79
+ ```
80
+
81
+ - esc 取消截图,可用以下代码实现按 esc 取消截图
82
+
83
+ ```js
84
+ globalShortcut.register('esc', () => {
85
+ if (screenshots.$win?.isFocused()) {
86
+ screenshots.endCapture()
87
+ }
88
+ })
89
+ ```
90
+
91
+ - 加速截图界面展示,不销毁`BrowserWindow`,减少创建窗口的开销,可用以下代码实现。**需注意,启用该功能,会导致`window-all-closed`事件不触发,因此需要手动关闭截图窗口**
92
+
93
+ ```js
94
+ // 是否复用截图窗口,加快截图窗口显示,默认值为 false
95
+ // 如果设置为 true 则会在第一次调用截图窗口时创建,后续调用时直接使用
96
+ // 且由于窗口不会 close,所以不会触发 app 的 `window-all-closed` 事件
97
+ const screenshots = new Screenshots({
98
+ singleWindow: true
99
+ })
100
+ ```
101
+
102
+ ## Methods
103
+
104
+ - `Debugger`类型产考`debug`中的`Debugger`类型
105
+
106
+ ```ts
107
+ export type LoggerFn = (...args: unknown[]) => void
108
+ export type Logger = Debugger | LoggerFn
109
+
110
+ export interface Lang {
111
+ magnifier_position_label?: string
112
+ operation_ok_title?: string
113
+ operation_cancel_title?: string
114
+ operation_save_title?: string
115
+ operation_redo_title?: string
116
+ operation_undo_title?: string
117
+ operation_mosaic_title?: string
118
+ operation_text_title?: string
119
+ operation_brush_title?: string
120
+ operation_arrow_title?: string
121
+ operation_ellipse_title?: string
122
+ operation_rectangle_title?: string
123
+ }
124
+
125
+ export interface ScreenshotsOpts {
126
+ lang?: Lang
127
+ // 调用日志,默认值为 debug('electron-screenshots')
128
+ // debug https://www.npmjs.com/package/debug
129
+ logger?: Logger
130
+ // 是否复用截图窗口,加快截图窗口显示,默认值为 false
131
+ // 如果设置为 true 则会在第一次调用截图窗口时创建,后续调用时直接使用
132
+ // 且由于窗口不会 close,所以不会触发 app 的 `window-all-closed` 事件
133
+ singleWindow?: boolean
134
+ }
135
+ ```
136
+
137
+ | 名称 | 说明 | 返回值 |
138
+ | ------------------------------------------------- | ---------------- | ------ |
139
+ | `constructor(opts: ScreenshotsOpts): Screenshots` | 调用截图方法截图 | - |
140
+ | `startCapture(): Promise<void>` | 调用截图方法截图 | - |
141
+ | `endCapture(): Promise<void>` | 手动结束截图 | - |
142
+ | `setLang(lang: Lang): Promise<void>` | 修改语言 | - |
143
+
144
+ ## Events
145
+
146
+ - 数据类型
147
+
148
+ ```ts
149
+ interface Bounds {
150
+ x: number
151
+ y: number
152
+ width: number
153
+ height: number
154
+ }
155
+
156
+ export interface Display {
157
+ id: number
158
+ x: number
159
+ y: number
160
+ width: number
161
+ height: number
162
+ }
163
+
164
+ export interface ScreenshotsData {
165
+ bounds: Bounds
166
+ display: Display
167
+ }
168
+
169
+ class Event {
170
+ public defaultPrevented = false
171
+
172
+ public preventDefault(): void {
173
+ this.defaultPrevented = true
174
+ }
175
+ }
176
+ ```
177
+
178
+ | 名称 | 说明 | 回调参数 |
179
+ | ------ | ------------ | --------------------------------------------------------------- |
180
+ | ok | 截图确认事件 | `(event: Event, buffer: Buffer, data: ScreenshotsData) => void` |
181
+ | cancel | 截图取消事件 | `(event: Event) => void` |
182
+ | save | 截图保存事件 | `(event: Event, buffer: Buffer, data: ScreenshotsData) => void` |
183
+
184
+ ### 说明
185
+
186
+ - event: 事件对象
187
+ - buffer: png 图片 buffer
188
+ - bounds: 截图区域信息
189
+ - display: 截图的屏幕
190
+ - `event`对象可调用`preventDefault`方法来阻止默认事件,例如阻止默认保存事件
191
+
192
+ ```ts
193
+ const screenshots = new Screenshots({
194
+ lang: {
195
+ magnifier_position_label: 'Position',
196
+ operation_ok_title: 'Ok',
197
+ operation_cancel_title: 'Cancel',
198
+ operation_save_title: 'Save',
199
+ operation_redo_title: 'Redo',
200
+ operation_undo_title: 'Undo',
201
+ operation_mosaic_title: 'Mosaic',
202
+ operation_text_title: 'Text',
203
+ operation_brush_title: 'Brush',
204
+ operation_arrow_title: 'Arrow',
205
+ operation_ellipse_title: 'Ellipse',
206
+ operation_rectangle_title: 'Rectangle'
207
+ }
208
+ })
209
+
210
+ screenshots.on('save', (e, buffer, data) => {
211
+ // 阻止插件自带的保存功能
212
+ // 用户自己控制保存功能
213
+ e.preventDefault()
214
+ // 用户可在这里自己定义保存功能
215
+ console.log('capture', buffer, data)
216
+ })
217
+
218
+ screenshots.startCapture()
219
+ ```
220
+
221
+ ## Screenshot
222
+
223
+ ![screenshot](../../screenshot.jpg)
package/lib/event.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export default class Event {
2
- defaultPrevented: boolean;
3
- preventDefault(): void;
4
- }
1
+ export default class Event {
2
+ defaultPrevented: boolean;
3
+ preventDefault(): void;
4
+ }
package/lib/event.js CHANGED
@@ -1,12 +1,12 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var Event = /** @class */ (function () {
4
- function Event() {
5
- this.defaultPrevented = false;
6
- }
7
- Event.prototype.preventDefault = function () {
8
- this.defaultPrevented = true;
9
- };
10
- return Event;
11
- }());
12
- exports.default = Event;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var Event = /** @class */ (function () {
4
+ function Event() {
5
+ this.defaultPrevented = false;
6
+ }
7
+ Event.prototype.preventDefault = function () {
8
+ this.defaultPrevented = true;
9
+ };
10
+ return Event;
11
+ }());
12
+ exports.default = Event;
@@ -1,6 +1,6 @@
1
- import { Rectangle } from 'electron';
2
- export interface Display extends Rectangle {
3
- id: number;
4
- }
5
- declare const _default: () => Display;
6
- export default _default;
1
+ import { Rectangle } from 'electron';
2
+ export interface Display extends Rectangle {
3
+ id: number;
4
+ }
5
+ declare const _default: () => Display;
6
+ export default _default;
package/lib/getDisplay.js CHANGED
@@ -1,15 +1,15 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var electron_1 = require("electron");
4
- exports.default = (function () {
5
- var point = electron_1.screen.getCursorScreenPoint();
6
- var _a = electron_1.screen.getDisplayNearestPoint(point), id = _a.id, bounds = _a.bounds;
7
- // https://github.com/nashaofu/screenshots/issues/98
8
- return {
9
- id: id,
10
- x: Math.floor(bounds.x),
11
- y: Math.floor(bounds.y),
12
- width: Math.floor(bounds.width),
13
- height: Math.floor(bounds.height)
14
- };
15
- });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var electron_1 = require("electron");
4
+ exports.default = (function () {
5
+ var point = electron_1.screen.getCursorScreenPoint();
6
+ var _a = electron_1.screen.getDisplayNearestPoint(point), id = _a.id, bounds = _a.bounds;
7
+ // https://github.com/nashaofu/screenshots/issues/98
8
+ return {
9
+ id: id,
10
+ x: Math.floor(bounds.x),
11
+ y: Math.floor(bounds.y),
12
+ width: Math.floor(bounds.width),
13
+ height: Math.floor(bounds.height)
14
+ };
15
+ });
package/lib/index.d.ts CHANGED
@@ -1 +1 @@
1
- export {};
1
+ export {};