2020-11-30 07:48:39 +00:00
|
|
|
const { app, BrowserWindow } = require('electron')
|
|
|
|
const fs = require('fs')
|
2021-05-24 02:33:45 +00:00
|
|
|
const path = require('path')
|
2020-11-30 07:48:39 +00:00
|
|
|
|
|
|
|
app.disableHardwareAcceleration()
|
|
|
|
|
|
|
|
let win
|
|
|
|
|
|
|
|
app.whenReady().then(() => {
|
|
|
|
win = new BrowserWindow({ webPreferences: { offscreen: true } })
|
|
|
|
win.loadURL('https://github.com')
|
|
|
|
win.webContents.on('paint', (event, dirty, image) => {
|
|
|
|
fs.writeFileSync('ex.png', image.toPNG())
|
|
|
|
})
|
|
|
|
win.webContents.setFrameRate(60)
|
2021-05-24 02:33:45 +00:00
|
|
|
console.log(`The screenshot has been successfully saved to ${path.join(process.cwd(), 'ex.png')}`)
|
2020-11-30 07:48:39 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
app.on('window-all-closed', () => {
|
|
|
|
if (process.platform !== 'darwin') {
|
|
|
|
app.quit()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
app.on('activate', () => {
|
|
|
|
if (BrowserWindow.getAllWindows().length === 0) {
|
|
|
|
createWindow()
|
|
|
|
}
|
|
|
|
})
|