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