electron-screenshots 0.4.0 → 0.4.3-alpha.0
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/README.md +21 -6
- package/lib/preload.d.ts +6 -1
- package/lib/screenshots.d.ts +18 -4
- package/lib/screenshots.js +18 -18
- package/package.json +6 -4
package/README.md
CHANGED
|
@@ -80,14 +80,29 @@ module.exports = {
|
|
|
80
80
|
|
|
81
81
|
## Methods
|
|
82
82
|
|
|
83
|
-
- `
|
|
84
|
-
- `Lang`类型产考`react-screenshots`中的`Lang`类型
|
|
83
|
+
- `Debugger`类型产考`debug`中的`Debugger`类型
|
|
85
84
|
|
|
86
85
|
```ts
|
|
87
86
|
export type LoggerFn = (...args: unknown[]) => void
|
|
88
87
|
export type Logger = Debugger | LoggerFn
|
|
88
|
+
|
|
89
|
+
export interface Lang {
|
|
90
|
+
magnifier_position_label?: string
|
|
91
|
+
operation_ok_title?: string
|
|
92
|
+
operation_cancel_title?: string
|
|
93
|
+
operation_save_title?: string
|
|
94
|
+
operation_redo_title?: string
|
|
95
|
+
operation_undo_title?: string
|
|
96
|
+
operation_mosaic_title?: string
|
|
97
|
+
operation_text_title?: string
|
|
98
|
+
operation_brush_title?: string
|
|
99
|
+
operation_arrow_title?: string
|
|
100
|
+
operation_ellipse_title?: string
|
|
101
|
+
operation_rectangle_title?: string
|
|
102
|
+
}
|
|
103
|
+
|
|
89
104
|
export interface ScreenshotsOpts {
|
|
90
|
-
lang?:
|
|
105
|
+
lang?: Lang
|
|
91
106
|
// 调用日志,默认值为 debug('electron-screenshots')
|
|
92
107
|
// debug https://www.npmjs.com/package/debug
|
|
93
108
|
logger?: Logger
|
|
@@ -99,7 +114,7 @@ export interface ScreenshotsOpts {
|
|
|
99
114
|
| `constructor(opts: ScreenshotsOpts)` | 调用截图方法截图 | - |
|
|
100
115
|
| `startCapture()` | 调用截图方法截图 | - |
|
|
101
116
|
| `endCapture() ` | 手动结束截图 | - |
|
|
102
|
-
| `setLang(lang:
|
|
117
|
+
| `setLang(lang: Lang)` | 修改语言 | - |
|
|
103
118
|
|
|
104
119
|
## Events
|
|
105
120
|
|
|
@@ -167,12 +182,12 @@ const screenshots = new Screenshots({
|
|
|
167
182
|
}
|
|
168
183
|
})
|
|
169
184
|
|
|
170
|
-
screenshots.on('save', (e, buffer,
|
|
185
|
+
screenshots.on('save', (e, buffer, data) => {
|
|
171
186
|
// 阻止插件自带的保存功能
|
|
172
187
|
// 用户自己控制保存功能
|
|
173
188
|
e.preventDefault()
|
|
174
189
|
// 用户可在这里自己定义保存功能
|
|
175
|
-
console.log('capture', buffer,
|
|
190
|
+
console.log('capture', buffer, data)
|
|
176
191
|
})
|
|
177
192
|
|
|
178
193
|
screenshots.startCapture()
|
package/lib/preload.d.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { Display } from './getBoundAndDisplay';
|
|
2
|
-
|
|
2
|
+
export interface Bounds {
|
|
3
|
+
x: number;
|
|
4
|
+
y: number;
|
|
5
|
+
width: number;
|
|
6
|
+
height: number;
|
|
7
|
+
}
|
|
3
8
|
export interface ScreenshotsData {
|
|
4
9
|
bounds: Bounds;
|
|
5
10
|
display: Display;
|
package/lib/screenshots.d.ts
CHANGED
|
@@ -1,15 +1,29 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { Debugger } from 'debug';
|
|
3
|
-
import {
|
|
3
|
+
import { BrowserView, BrowserWindow } from 'electron';
|
|
4
4
|
import Events from 'events';
|
|
5
|
-
import { Bounds
|
|
5
|
+
import { Bounds } from './preload';
|
|
6
6
|
export declare type LoggerFn = (...args: unknown[]) => void;
|
|
7
7
|
export declare 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
|
+
}
|
|
8
22
|
export interface ScreenshotsOpts {
|
|
9
|
-
lang?:
|
|
23
|
+
lang?: Lang;
|
|
10
24
|
logger?: Logger;
|
|
11
25
|
}
|
|
12
|
-
export { Bounds
|
|
26
|
+
export { Bounds };
|
|
13
27
|
export default class Screenshots extends Events {
|
|
14
28
|
$win: BrowserWindow | null;
|
|
15
29
|
$view: BrowserView;
|
package/lib/screenshots.js
CHANGED
|
@@ -75,11 +75,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
75
75
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
76
76
|
var debug_1 = __importDefault(require("debug"));
|
|
77
77
|
var electron_1 = require("electron");
|
|
78
|
-
var promises_1 = __importDefault(require("fs/promises"));
|
|
79
|
-
var event_1 = __importDefault(require("./event"));
|
|
80
78
|
var events_1 = __importDefault(require("events"));
|
|
81
|
-
var
|
|
79
|
+
var fs_extra_1 = __importDefault(require("fs-extra"));
|
|
80
|
+
var event_1 = __importDefault(require("./event"));
|
|
82
81
|
var getBoundAndDisplay_1 = __importDefault(require("./getBoundAndDisplay"));
|
|
82
|
+
var padStart_1 = __importDefault(require("./padStart"));
|
|
83
83
|
var Screenshots = /** @class */ (function (_super) {
|
|
84
84
|
__extends(Screenshots, _super);
|
|
85
85
|
function Screenshots(opts) {
|
|
@@ -125,8 +125,6 @@ var Screenshots = /** @class */ (function (_super) {
|
|
|
125
125
|
_this.capture(boundAndDisplay).then(function () {
|
|
126
126
|
if (!_this.$win)
|
|
127
127
|
return;
|
|
128
|
-
// linux截图存在黑屏,这里设置为false就不会出现这个问题
|
|
129
|
-
_this.$win.setFullScreen(true);
|
|
130
128
|
_this.$win.show();
|
|
131
129
|
_this.$win.focus();
|
|
132
130
|
});
|
|
@@ -171,20 +169,19 @@ var Screenshots = /** @class */ (function (_super) {
|
|
|
171
169
|
transparent: true,
|
|
172
170
|
resizable: false,
|
|
173
171
|
movable: false,
|
|
174
|
-
focusable:
|
|
175
|
-
|
|
176
|
-
//
|
|
177
|
-
// 参考48-49行
|
|
178
|
-
fullscreen: false,
|
|
179
|
-
// 设为true mac全屏窗口没有桌面滚动效果
|
|
172
|
+
focusable: false,
|
|
173
|
+
fullscreen: true,
|
|
174
|
+
// 设为true 防止mac新开一个桌面,影响效果
|
|
180
175
|
simpleFullscreen: true,
|
|
181
176
|
backgroundColor: '#00000000',
|
|
182
177
|
titleBarStyle: 'hidden',
|
|
183
178
|
alwaysOnTop: true,
|
|
184
179
|
enableLargerThanScreen: true,
|
|
185
180
|
skipTaskbar: true,
|
|
181
|
+
hasShadow: false,
|
|
186
182
|
minimizable: false,
|
|
187
183
|
maximizable: false,
|
|
184
|
+
roundedCorners: false,
|
|
188
185
|
webPreferences: {
|
|
189
186
|
nodeIntegration: false,
|
|
190
187
|
contextIsolation: false,
|
|
@@ -192,6 +189,9 @@ var Screenshots = /** @class */ (function (_super) {
|
|
|
192
189
|
}
|
|
193
190
|
});
|
|
194
191
|
this.$win.setBrowserView(this.$view);
|
|
192
|
+
this.$win.setMenu(null);
|
|
193
|
+
this.$win.setMenuBarVisibility(false);
|
|
194
|
+
this.$win.removeMenu();
|
|
195
195
|
this.$view.setBounds(bound);
|
|
196
196
|
};
|
|
197
197
|
Screenshots.prototype.capture = function (_a) {
|
|
@@ -262,10 +262,10 @@ var Screenshots = /** @class */ (function (_super) {
|
|
|
262
262
|
/**
|
|
263
263
|
* OK事件
|
|
264
264
|
*/
|
|
265
|
-
electron_1.ipcMain.on('SCREENSHOTS:ok', function (e, buffer,
|
|
266
|
-
_this.logger('SCREENSHOTS:ok', buffer,
|
|
265
|
+
electron_1.ipcMain.on('SCREENSHOTS:ok', function (e, buffer, data) {
|
|
266
|
+
_this.logger('SCREENSHOTS:ok', buffer, data);
|
|
267
267
|
var event = new event_1.default();
|
|
268
|
-
_this.emit('ok', event, buffer,
|
|
268
|
+
_this.emit('ok', event, buffer, data);
|
|
269
269
|
if (event.defaultPrevented) {
|
|
270
270
|
return;
|
|
271
271
|
}
|
|
@@ -287,14 +287,14 @@ var Screenshots = /** @class */ (function (_super) {
|
|
|
287
287
|
/**
|
|
288
288
|
* SAVE事件
|
|
289
289
|
*/
|
|
290
|
-
electron_1.ipcMain.on('SCREENSHOTS:save', function (e, buffer,
|
|
290
|
+
electron_1.ipcMain.on('SCREENSHOTS:save', function (e, buffer, data) { return __awaiter(_this, void 0, void 0, function () {
|
|
291
291
|
var event, time, year, month, date, hours, minutes, seconds, milliseconds, _a, canceled, filePath;
|
|
292
292
|
return __generator(this, function (_b) {
|
|
293
293
|
switch (_b.label) {
|
|
294
294
|
case 0:
|
|
295
|
-
this.logger('SCREENSHOTS:save', buffer,
|
|
295
|
+
this.logger('SCREENSHOTS:save', buffer, data);
|
|
296
296
|
event = new event_1.default();
|
|
297
|
-
this.emit('save', event, buffer,
|
|
297
|
+
this.emit('save', event, buffer, data);
|
|
298
298
|
if (event.defaultPrevented || !this.$win) {
|
|
299
299
|
return [2 /*return*/];
|
|
300
300
|
}
|
|
@@ -320,7 +320,7 @@ var Screenshots = /** @class */ (function (_super) {
|
|
|
320
320
|
if (canceled || !filePath) {
|
|
321
321
|
return [2 /*return*/];
|
|
322
322
|
}
|
|
323
|
-
return [4 /*yield*/,
|
|
323
|
+
return [4 /*yield*/, fs_extra_1.default.writeFile(filePath, buffer)];
|
|
324
324
|
case 2:
|
|
325
325
|
_b.sent();
|
|
326
326
|
this.endCapture();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "electron-screenshots",
|
|
3
|
-
"version": "0.4.0",
|
|
3
|
+
"version": "0.4.3-alpha.0",
|
|
4
4
|
"description": "electron 截图插件",
|
|
5
5
|
"types": "lib/screenshots.d.ts",
|
|
6
6
|
"main": "lib/screenshots.js",
|
|
@@ -36,14 +36,16 @@
|
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"debug": "^4.3.3",
|
|
39
|
-
"
|
|
40
|
-
"
|
|
39
|
+
"fs-extra": "^10.1.0",
|
|
40
|
+
"node-screenshots": "^0.0.3",
|
|
41
|
+
"react-screenshots": "^0.4.3-alpha.0"
|
|
41
42
|
},
|
|
42
43
|
"peerDependencies": {
|
|
43
44
|
"electron": ">=11"
|
|
44
45
|
},
|
|
45
46
|
"devDependencies": {
|
|
46
47
|
"@types/debug": "^4.1.7",
|
|
48
|
+
"@types/fs-extra": "^9.0.13",
|
|
47
49
|
"@typescript-eslint/eslint-plugin": "^5.10.0",
|
|
48
50
|
"@typescript-eslint/parser": "^5.10.0",
|
|
49
51
|
"cross-env": "^7.0.3",
|
|
@@ -57,5 +59,5 @@
|
|
|
57
59
|
"rimraf": "^3.0.2",
|
|
58
60
|
"typescript": "^4.5.5"
|
|
59
61
|
},
|
|
60
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "65896243723db7e6877fd32cea3187b2fa24a21a"
|
|
61
63
|
}
|