2023-04-05 13:42:20 +00:00
|
|
|
const { app, BrowserWindow, Menu, ipcMain } = require('electron')
|
2023-07-17 08:30:53 +00:00
|
|
|
const path = require('node:path')
|
2022-02-09 16:00:05 +00:00
|
|
|
|
|
|
|
function createWindow () {
|
|
|
|
const mainWindow = new BrowserWindow({
|
|
|
|
webPreferences: {
|
|
|
|
preload: path.join(__dirname, 'preload.js')
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
const menu = Menu.buildFromTemplate([
|
|
|
|
{
|
|
|
|
label: app.name,
|
|
|
|
submenu: [
|
2023-04-05 13:42:20 +00:00
|
|
|
{
|
|
|
|
click: () => mainWindow.webContents.send('update-counter', 1),
|
|
|
|
label: 'Increment'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
click: () => mainWindow.webContents.send('update-counter', -1),
|
|
|
|
label: 'Decrement'
|
|
|
|
}
|
2022-02-09 16:00:05 +00:00
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
])
|
|
|
|
|
|
|
|
Menu.setApplicationMenu(menu)
|
|
|
|
mainWindow.loadFile('index.html')
|
|
|
|
|
|
|
|
// Open the DevTools.
|
|
|
|
mainWindow.webContents.openDevTools()
|
|
|
|
}
|
|
|
|
|
|
|
|
app.whenReady().then(() => {
|
|
|
|
ipcMain.on('counter-value', (_event, value) => {
|
|
|
|
console.log(value) // will print value to Node console
|
|
|
|
})
|
|
|
|
createWindow()
|
2023-02-01 11:59:16 +00:00
|
|
|
|
2022-02-09 16:00:05 +00:00
|
|
|
app.on('activate', function () {
|
|
|
|
if (BrowserWindow.getAllWindows().length === 0) createWindow()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
app.on('window-all-closed', function () {
|
|
|
|
if (process.platform !== 'darwin') app.quit()
|
|
|
|
})
|