File tree Expand file tree Collapse file tree 4 files changed +21
-1
lines changed
Expand file tree Collapse file tree 4 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,10 @@ <h1>Hello World!</h1>
1313 Chromium < span id ="chrome-version "> </ span > ,
1414 and Electron < span id ="electron-version "> </ span > .
1515
16+ < div >
17+ < button id ="btn " type ="button "> Restart</ button >
18+ </ div >
19+
1620 <!-- You can also require other files to run in this process -->
1721 < script src ="./renderer.js "> </ script >
1822 </ body >
Original file line number Diff line number Diff line change 11// Modules to control application life and create native browser window
2- const { app, BrowserWindow } = require ( 'electron' )
2+ const { app, BrowserWindow, ipcMain } = require ( 'electron' )
33const path = require ( 'node:path' )
44
5+ function handleRestart ( ) {
6+ app . relaunch ( )
7+ app . quit ( )
8+ }
9+
510function createWindow ( ) {
611 // Create the browser window.
712 const mainWindow = new BrowserWindow ( {
@@ -23,6 +28,7 @@ function createWindow () {
2328// initialization and is ready to create browser windows.
2429// Some APIs can only be used after this event occurs.
2530app . whenReady ( ) . then ( ( ) => {
31+ ipcMain . on ( 'restart' , handleRestart )
2632 createWindow ( )
2733
2834 app . on ( 'activate' , function ( ) {
Original file line number Diff line number Diff line change 1+ const { contextBridge, ipcRenderer } = require ( 'electron/renderer' )
12/**
23 * The preload script runs before `index.html` is loaded
34 * in the renderer. It has access to web APIs as well as
@@ -16,3 +17,7 @@ window.addEventListener('DOMContentLoaded', () => {
1617 replaceText ( `${ type } -version` , process . versions [ type ] )
1718 }
1819} )
20+
21+ contextBridge . exposeInMainWorld ( 'electronAPI' , {
22+ restart : ( ) => ipcRenderer . send ( 'restart' )
23+ } )
Original file line number Diff line number Diff line change 55 * `contextIsolation` is turned on. Use the contextBridge API in `preload.js`
66 * to expose Node.js functionality from the main process.
77 */
8+
9+ const button = document . getElementById ( 'btn' )
10+ button . addEventListener ( 'click' , ( ) => {
11+ window . electronAPI . restart ( )
12+ } )
You can’t perform that action at this time.
0 commit comments