2023-08-28 11:23:10 +00:00
|
|
|
const { app, BrowserWindow } = require('electron/main')
|
2023-07-17 08:30:53 +00:00
|
|
|
const fs = require('node:fs')
|
|
|
|
const path = require('node:path')
|
2020-11-30 07:48:39 +00:00
|
|
|
|
|
|
|
app.disableHardwareAcceleration()
|
|
|
|
|
2023-04-24 14:35:14 +00:00
|
|
|
function createWindow () {
|
|
|
|
const win = new BrowserWindow({
|
|
|
|
width: 800,
|
|
|
|
height: 600,
|
|
|
|
webPreferences: {
|
|
|
|
offscreen: true
|
|
|
|
}
|
|
|
|
})
|
2020-11-30 07:48:39 +00: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-24 02:33:45 +00:00
|
|
|
console.log(`The screenshot has been successfully saved to ${path.join(process.cwd(), 'ex.png')}`)
|
2023-04-24 14:35:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
app.whenReady().then(() => {
|
|
|
|
createWindow()
|
|
|
|
|
|
|
|
app.on('activate', () => {
|
|
|
|
if (BrowserWindow.getAllWindows().length === 0) {
|
|
|
|
createWindow()
|
|
|
|
}
|
|
|
|
})
|
2020-11-30 07:48:39 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
app.on('window-all-closed', () => {
|
|
|
|
if (process.platform !== 'darwin') {
|
|
|
|
app.quit()
|
|
|
|
}
|
|
|
|
})
|