electron/docs/fiddles/ipc/pattern-1/main.js
Jemil Suleimanov 013133867b
docs: unify documentation example and fiddle for IPC pattern-1 (#46517)
* docs: unify documentation examples and fiddle

* docs: remove changes in ipc documentation
2025-04-10 12:08:10 +02:00

31 lines
742 B
JavaScript

const { app, BrowserWindow, ipcMain } = require('electron/main')
const path = require('node:path')
function handleSetTitle (event, title) {
const webContents = event.sender
const win = BrowserWindow.fromWebContents(webContents)
win.setTitle(title)
}
function createWindow () {
const mainWindow = new BrowserWindow({
webPreferences: {
preload: path.join(__dirname, 'preload.js')
}
})
mainWindow.loadFile('index.html')
}
app.whenReady().then(() => {
ipcMain.on('set-title', handleSetTitle)
createWindow()
app.on('activate', function () {
if (BrowserWindow.getAllWindows().length === 0) createWindow()
})
})
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') app.quit()
})