electron-screenshots 0.5.26 → 0.5.28
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 +18 -1
- package/lib/index.d.ts +0 -1
- package/lib/index.js +54 -34
- package/lib/padStart.js +1 -1
- package/package.json +62 -63
- package/LICENSE +0 -21
package/README.md
CHANGED
|
@@ -18,6 +18,7 @@ import { app, globalShortcut } from "electron";
|
|
|
18
18
|
import Screenshots from "./screenshots";
|
|
19
19
|
|
|
20
20
|
app.whenReady().then(() => {
|
|
21
|
+
app.setAppUserModelId('com.electron.screenshots')
|
|
21
22
|
const screenshots = new Screenshots();
|
|
22
23
|
globalShortcut.register("ctrl+shift+a", () => {
|
|
23
24
|
screenshots.startCapture();
|
|
@@ -44,7 +45,7 @@ app.whenReady().then(() => {
|
|
|
44
45
|
// 保存后的回调事件
|
|
45
46
|
screenshots.on("afterSave", (e, buffer, bounds, isSaved) => {
|
|
46
47
|
console.log("capture", buffer, bounds);
|
|
47
|
-
console.log("isSaved", isSaved) // 是否保存成功
|
|
48
|
+
console.log("isSaved", isSaved); // 是否保存成功
|
|
48
49
|
});
|
|
49
50
|
debug({ showDevTools: true, devToolsMode: "undocked" });
|
|
50
51
|
});
|
|
@@ -83,6 +84,22 @@ module.exports = {
|
|
|
83
84
|
};
|
|
84
85
|
```
|
|
85
86
|
|
|
87
|
+
- vite 配置示例:
|
|
88
|
+
|
|
89
|
+
```js
|
|
90
|
+
// vite.config.js
|
|
91
|
+
import { defineConfig } from "vite";
|
|
92
|
+
import viteExternals from "vite-plugin-externals";
|
|
93
|
+
|
|
94
|
+
export default defineConfig({
|
|
95
|
+
plugins: [
|
|
96
|
+
viteExternals({
|
|
97
|
+
"electron-screenshots": 'require("electron-screenshots")', // 模块名称: 全局变量
|
|
98
|
+
}),
|
|
99
|
+
],
|
|
100
|
+
});
|
|
101
|
+
```
|
|
102
|
+
|
|
86
103
|
- esc 取消截图,可用以下代码实现按 esc 取消截图
|
|
87
104
|
|
|
88
105
|
```js
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -30,13 +30,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
30
30
|
}) : function(o, v) {
|
|
31
31
|
o["default"] = v;
|
|
32
32
|
});
|
|
33
|
-
var __importStar = (this && this.__importStar) || function (
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
};
|
|
33
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
34
|
+
var ownKeys = function(o) {
|
|
35
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
36
|
+
var ar = [];
|
|
37
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
38
|
+
return ar;
|
|
39
|
+
};
|
|
40
|
+
return ownKeys(o);
|
|
41
|
+
};
|
|
42
|
+
return function (mod) {
|
|
43
|
+
if (mod && mod.__esModule) return mod;
|
|
44
|
+
var result = {};
|
|
45
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
46
|
+
__setModuleDefault(result, mod);
|
|
47
|
+
return result;
|
|
48
|
+
};
|
|
49
|
+
})();
|
|
40
50
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
41
51
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
42
52
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -47,8 +57,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
47
57
|
});
|
|
48
58
|
};
|
|
49
59
|
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
50
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
51
|
-
return g =
|
|
60
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
61
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
52
62
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
53
63
|
function step(op) {
|
|
54
64
|
if (f) throw new TypeError("Generator is already executing.");
|
|
@@ -213,10 +223,10 @@ var Screenshots = /** @class */ (function (_super) {
|
|
|
213
223
|
* 初始化窗口
|
|
214
224
|
*/
|
|
215
225
|
Screenshots.prototype.createWindow = function (display) {
|
|
216
|
-
var _a, _b;
|
|
217
226
|
return __awaiter(this, void 0, void 0, function () {
|
|
218
227
|
var windowTypes;
|
|
219
228
|
var _this = this;
|
|
229
|
+
var _a, _b;
|
|
220
230
|
return __generator(this, function (_c) {
|
|
221
231
|
switch (_c.label) {
|
|
222
232
|
case 0:
|
|
@@ -310,41 +320,51 @@ var Screenshots = /** @class */ (function (_super) {
|
|
|
310
320
|
};
|
|
311
321
|
Screenshots.prototype.capture = function (display) {
|
|
312
322
|
return __awaiter(this, void 0, void 0, function () {
|
|
313
|
-
var
|
|
323
|
+
var Monitor, point, monitor, image, buffer, err_1, sources, source;
|
|
314
324
|
return __generator(this, function (_a) {
|
|
315
325
|
switch (_a.label) {
|
|
316
326
|
case 0:
|
|
317
327
|
this.logger('SCREENSHOTS:capture');
|
|
318
328
|
_a.label = 1;
|
|
319
329
|
case 1:
|
|
320
|
-
_a.trys.push([1,
|
|
330
|
+
_a.trys.push([1, 5, , 7]);
|
|
321
331
|
return [4 /*yield*/, Promise.resolve().then(function () { return __importStar(require('node-screenshots')); })];
|
|
322
332
|
case 2:
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
y: capturer.y,
|
|
331
|
-
width: capturer.width,
|
|
332
|
-
height: capturer.height,
|
|
333
|
-
rotation: capturer.rotation,
|
|
334
|
-
scaleFactor: capturer.scaleFactor,
|
|
335
|
-
isPrimary: capturer.isPrimary,
|
|
336
|
-
}
|
|
337
|
-
: null);
|
|
338
|
-
if (!capturer) {
|
|
339
|
-
throw new Error("NodeScreenshots.fromDisplay(".concat(display.id, ") get null"));
|
|
333
|
+
Monitor = (_a.sent()).Monitor;
|
|
334
|
+
point = {
|
|
335
|
+
x: display.x + display.width / 2,
|
|
336
|
+
y: display.y + display.height / 2,
|
|
337
|
+
};
|
|
338
|
+
if (process.platform === 'win32') {
|
|
339
|
+
point = electron_1.screen.screenToDipPoint(point);
|
|
340
340
|
}
|
|
341
|
-
|
|
341
|
+
monitor = Monitor.fromPoint(point.x, point.y);
|
|
342
|
+
this.logger('SCREENSHOTS:capture Monitor.fromPoint arguments %o', display);
|
|
343
|
+
this.logger('SCREENSHOTS:capture Monitor.fromPoint return %o', {
|
|
344
|
+
id: monitor === null || monitor === void 0 ? void 0 : monitor.id,
|
|
345
|
+
name: monitor === null || monitor === void 0 ? void 0 : monitor.name,
|
|
346
|
+
x: monitor === null || monitor === void 0 ? void 0 : monitor.x,
|
|
347
|
+
y: monitor === null || monitor === void 0 ? void 0 : monitor.y,
|
|
348
|
+
width: monitor === null || monitor === void 0 ? void 0 : monitor.width,
|
|
349
|
+
height: monitor === null || monitor === void 0 ? void 0 : monitor.height,
|
|
350
|
+
rotation: monitor === null || monitor === void 0 ? void 0 : monitor.rotation,
|
|
351
|
+
scaleFactor: monitor === null || monitor === void 0 ? void 0 : monitor.scaleFactor,
|
|
352
|
+
frequency: monitor === null || monitor === void 0 ? void 0 : monitor.frequency,
|
|
353
|
+
isPrimary: monitor === null || monitor === void 0 ? void 0 : monitor.isPrimary,
|
|
354
|
+
});
|
|
355
|
+
if (!monitor) {
|
|
356
|
+
throw new Error("Monitor.fromDisplay(".concat(display.id, ") get null"));
|
|
357
|
+
}
|
|
358
|
+
return [4 /*yield*/, monitor.captureImage()];
|
|
342
359
|
case 3:
|
|
343
360
|
image = _a.sent();
|
|
344
|
-
return [
|
|
361
|
+
return [4 /*yield*/, image.toPng(true)];
|
|
345
362
|
case 4:
|
|
363
|
+
buffer = _a.sent();
|
|
364
|
+
return [2 /*return*/, "data:image/png;base64,".concat(buffer.toString('base64'))];
|
|
365
|
+
case 5:
|
|
346
366
|
err_1 = _a.sent();
|
|
347
|
-
this.logger('SCREENSHOTS:capture
|
|
367
|
+
this.logger('SCREENSHOTS:capture Monitor capture() error %o', err_1);
|
|
348
368
|
return [4 /*yield*/, electron_1.desktopCapturer.getSources({
|
|
349
369
|
types: ['screen'],
|
|
350
370
|
thumbnailSize: {
|
|
@@ -352,7 +372,7 @@ var Screenshots = /** @class */ (function (_super) {
|
|
|
352
372
|
height: display.height * display.scaleFactor,
|
|
353
373
|
},
|
|
354
374
|
})];
|
|
355
|
-
case
|
|
375
|
+
case 6:
|
|
356
376
|
sources = _a.sent();
|
|
357
377
|
source = void 0;
|
|
358
378
|
// Linux系统上,screen.getDisplayNearestPoint 返回的 Display 对象的 id
|
|
@@ -370,7 +390,7 @@ var Screenshots = /** @class */ (function (_super) {
|
|
|
370
390
|
throw new Error("Can't find screen source");
|
|
371
391
|
}
|
|
372
392
|
return [2 /*return*/, source.thumbnail.toDataURL()];
|
|
373
|
-
case
|
|
393
|
+
case 7: return [2 /*return*/];
|
|
374
394
|
}
|
|
375
395
|
});
|
|
376
396
|
});
|
package/lib/padStart.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = padStart;
|
|
3
4
|
/**
|
|
4
5
|
* 如果string字符串长度小于 length 则在左侧填充字符
|
|
5
6
|
* 如果超出length长度则截断超出的部分。
|
|
@@ -16,4 +17,3 @@ function padStart(string, length, chars) {
|
|
|
16
17
|
}
|
|
17
18
|
return str;
|
|
18
19
|
}
|
|
19
|
-
exports.default = padStart;
|
package/package.json
CHANGED
|
@@ -1,63 +1,62 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "electron-screenshots",
|
|
3
|
-
"version": "0.5.
|
|
4
|
-
"description": "electron 截图插件",
|
|
5
|
-
"types": "lib/index.d.ts",
|
|
6
|
-
"main": "lib/index.cjs.js",
|
|
7
|
-
"module": "lib/index.js",
|
|
8
|
-
"files": [
|
|
9
|
-
"lib/**"
|
|
10
|
-
],
|
|
11
|
-
"scripts": {
|
|
12
|
-
"prepublishOnly": "npm run build",
|
|
13
|
-
"start": "cross-env DEBUG=electron-screenshots electron lib/demo.js",
|
|
14
|
-
"dev": "tsc --sourceMap --watch",
|
|
15
|
-
"build": "npm run lint && npm run clean && tsc",
|
|
16
|
-
"lint": "eslint . --ext .js,.ts --fix",
|
|
17
|
-
"clean": "rimraf lib"
|
|
18
|
-
},
|
|
19
|
-
"repository": {
|
|
20
|
-
"type": "git",
|
|
21
|
-
"url": "git+https://github.com/nashaofu/screenshots.git"
|
|
22
|
-
},
|
|
23
|
-
"keywords": [
|
|
24
|
-
"electron",
|
|
25
|
-
"shortcut",
|
|
26
|
-
"screenshot",
|
|
27
|
-
"cropper"
|
|
28
|
-
],
|
|
29
|
-
"author": "nashaofu",
|
|
30
|
-
"license": "MIT",
|
|
31
|
-
"bugs": {
|
|
32
|
-
"url": "https://github.com/nashaofu/screenshots/issues"
|
|
33
|
-
},
|
|
34
|
-
"homepage": "https://github.com/nashaofu/screenshots/tree/master/packages/electron-screenshots#readme",
|
|
35
|
-
"publishConfig": {
|
|
36
|
-
"registry": "https://registry.npmjs.org/"
|
|
37
|
-
},
|
|
38
|
-
"dependencies": {
|
|
39
|
-
"debug": "^4.3.4",
|
|
40
|
-
"fs-extra": "^11.1.1",
|
|
41
|
-
"node-screenshots": "^0.1
|
|
42
|
-
"react-screenshots": "^0.5.22"
|
|
43
|
-
},
|
|
44
|
-
"peerDependencies": {
|
|
45
|
-
"electron": ">=14"
|
|
46
|
-
},
|
|
47
|
-
"devDependencies": {
|
|
48
|
-
"@types/debug": "^4.1.7",
|
|
49
|
-
"@types/fs-extra": "^11.0.1",
|
|
50
|
-
"@types/node": "^18.15.11",
|
|
51
|
-
"@typescript-eslint/eslint-plugin": "^5.57.0",
|
|
52
|
-
"@typescript-eslint/parser": "^5.57.0",
|
|
53
|
-
"cross-env": "^7.0.3",
|
|
54
|
-
"electron": "^23.2.0",
|
|
55
|
-
"eslint": "^8.37.0",
|
|
56
|
-
"eslint-config-airbnb-base": "^15.0.0",
|
|
57
|
-
"eslint-config-airbnb-typescript": "^17.0.0",
|
|
58
|
-
"eslint-plugin-import": "^2.27.5",
|
|
59
|
-
"rimraf": "^4.4.1",
|
|
60
|
-
"typescript": "^5.0.2"
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "electron-screenshots",
|
|
3
|
+
"version": "0.5.28",
|
|
4
|
+
"description": "electron 截图插件",
|
|
5
|
+
"types": "lib/index.d.ts",
|
|
6
|
+
"main": "lib/index.cjs.js",
|
|
7
|
+
"module": "lib/index.js",
|
|
8
|
+
"files": [
|
|
9
|
+
"lib/**"
|
|
10
|
+
],
|
|
11
|
+
"scripts": {
|
|
12
|
+
"prepublishOnly": "npm run build",
|
|
13
|
+
"start": "cross-env DEBUG=electron-screenshots electron lib/demo.js",
|
|
14
|
+
"dev": "tsc --sourceMap --watch",
|
|
15
|
+
"build": "npm run lint && npm run clean && tsc",
|
|
16
|
+
"lint": "eslint . --ext .js,.ts --fix",
|
|
17
|
+
"clean": "rimraf lib"
|
|
18
|
+
},
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/nashaofu/screenshots.git"
|
|
22
|
+
},
|
|
23
|
+
"keywords": [
|
|
24
|
+
"electron",
|
|
25
|
+
"shortcut",
|
|
26
|
+
"screenshot",
|
|
27
|
+
"cropper"
|
|
28
|
+
],
|
|
29
|
+
"author": "nashaofu",
|
|
30
|
+
"license": "MIT",
|
|
31
|
+
"bugs": {
|
|
32
|
+
"url": "https://github.com/nashaofu/screenshots/issues"
|
|
33
|
+
},
|
|
34
|
+
"homepage": "https://github.com/nashaofu/screenshots/tree/master/packages/electron-screenshots#readme",
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"registry": "https://registry.npmjs.org/"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"debug": "^4.3.4",
|
|
40
|
+
"fs-extra": "^11.1.1",
|
|
41
|
+
"node-screenshots": "^0.2.1",
|
|
42
|
+
"react-screenshots": "^0.5.22"
|
|
43
|
+
},
|
|
44
|
+
"peerDependencies": {
|
|
45
|
+
"electron": ">=14"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@types/debug": "^4.1.7",
|
|
49
|
+
"@types/fs-extra": "^11.0.1",
|
|
50
|
+
"@types/node": "^18.15.11",
|
|
51
|
+
"@typescript-eslint/eslint-plugin": "^5.57.0",
|
|
52
|
+
"@typescript-eslint/parser": "^5.57.0",
|
|
53
|
+
"cross-env": "^7.0.3",
|
|
54
|
+
"electron": "^23.2.0",
|
|
55
|
+
"eslint": "^8.37.0",
|
|
56
|
+
"eslint-config-airbnb-base": "^15.0.0",
|
|
57
|
+
"eslint-config-airbnb-typescript": "^17.0.0",
|
|
58
|
+
"eslint-plugin-import": "^2.27.5",
|
|
59
|
+
"rimraf": "^4.4.1",
|
|
60
|
+
"typescript": "^5.0.2"
|
|
61
|
+
}
|
|
62
|
+
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
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.
|