-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscreen.js
More file actions
57 lines (47 loc) · 1.39 KB
/
Copy pathscreen.js
File metadata and controls
57 lines (47 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/**
* @description
* Accept 2 argument:
* 1 - path to application directory where save image
* 2 - path to html page
*/
const fs = require('node:fs');
const path = require('node:path');
const { app, BrowserWindow } = require('electron');
const pathToAppDirectory = process.argv[process.argv.length - 2];
if(!pathToAppDirectory) {
console.log("[ERROR] Need add absolute path to note application directory as first argument!");
app.quit();
}
const pathToPage = process.argv[process.argv.length - 1];
if(!pathToPage) {
console.log("[ERROR] Need add absolute path to html page as second argument!");
app.quit();
}
async function takeScreen(win) {
const screenshot = await win.webContents.capturePage();
const scrrenshotBuffer = screenshot.toPNG();
const pathSaveImageTo = path.join(pathToAppDirectory, 'image_of_page.png');
fs.writeFile(pathSaveImageTo, scrrenshotBuffer, () => {});
app.quit();
}
const startApp = async () => {
const win = new BrowserWindow({
center: true,
autoHideMenuBar: true,
fullscreen: true,
fullscreenable: true,
frame: false,
show: false,
webPreferences: {
preload: path.join(__dirname, 'screen_preload.js')
},
});
await win.loadFile(pathToPage);
setTimeout(() => takeScreen(win), 2000);
}
app.whenReady().then(() => {
startApp()
})
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') app.quit()
})