-
-
Save p120ph37/98cf0fb13790feed702f3e90cbddfbf6 to your computer and use it in GitHub Desktop.
Electron Relaunch Test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<body> | |
<h1>Relaunch Test</h1> | |
<h5>Note: app.relaunch does not work in Electron Fiddle at all. You must launch this via "npm start" instead</h5> | |
<div style="border: 1px solid black; width: 480px; height: 160px; white-space: nowrap; overflow: scroll;"> | |
<code> | |
<pre>process.argv = <span id="main-argv"></span></pre> | |
</code> | |
</div> | |
<button id="relaunch">Relaunch...</button> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const {app, BrowserWindow, ipcMain} = require('electron') | |
const path = require('path') | |
app.whenReady().then(() => { | |
const mainWindow = new BrowserWindow({ | |
width: 800, | |
height: 600, | |
webPreferences: { | |
preload: path.join(__dirname, 'preload.js') | |
} | |
}) | |
ipcMain.handle('getMainArgv', () => process.argv) | |
ipcMain.on('relaunch', () => { | |
app.relaunch({ | |
execPath: process.argv[0], | |
args: process.argv.slice(1).concat(['--relaunch']) | |
}) | |
app.exit(0) | |
}) | |
mainWindow.loadFile('index.html') | |
}) | |
app.on('window-all-closed', () => app.quit()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "elfin-passion-shoe-ix5xe", | |
"productName": "elfin-passion-shoe-ix5xe", | |
"description": "My Electron application description", | |
"keywords": [], | |
"main": "./main.js", | |
"version": "1.0.0", | |
"author": "anm", | |
"scripts": { | |
"start": "electron ." | |
}, | |
"dependencies": {}, | |
"devDependencies": { | |
"electron": "17.0.0-alpha.4" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const {ipcRenderer} = require('electron') | |
window.addEventListener('DOMContentLoaded', () => { | |
ipcRenderer.invoke('getMainArgv').then(mainArgv => { | |
document.getElementById('main-argv').innerText = JSON.stringify(mainArgv, null, 2) | |
}) | |
document.getElementById('relaunch').addEventListener('click', () => ipcRenderer.send('relaunch')) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment