Created
January 13, 2019 21:41
-
-
Save Downes/bf72fe0ad76e85e544e143607be00a5e to your computer and use it in GitHub Desktop.
Electron sample boostrap..js file
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
// console.log('testing') | |
const{app,BrowserWindow, Menu} = require('electron') | |
const ipc = require('electron').ipcMain | |
// main process | |
const path = require('path') | |
const url = require('url') | |
require('electron-reload')(__dirname) | |
let win | |
ipc.on('reply', (event,message) => { | |
console.log(event,message) | |
win.webContents.send('Message from bootstrap.js', 'Message from window 2: ${message}') | |
}) | |
function createWindow() { | |
win = new BrowserWindow({width:800,height:600}) | |
win.loadURL(url.format({ | |
pathname:path.join(__dirname, 'src/main.html'), | |
protocol: 'file', | |
slashes:true | |
})) | |
win.on('closed',() => { | |
win = null | |
}) | |
win.openDevTools() | |
var menu = Menu.buildFromTemplate([ | |
{ | |
label:'Electron',submenu:[ | |
{label:'Preferences'}, | |
{type:'separator'}, | |
{label:'log',click() { console.log('log item clicked')} } | |
] | |
} | |
]) | |
Menu.setApplicationMenu(menu) | |
} | |
app.on('ready', createWindow) | |
app.on('wondow-all-closed', ()=>{ | |
app.quit() | |
/* if(process.platform !== 'darwin') { | |
app.quit() | |
} */ | |
}) | |
app.on('activate', () => { | |
if (win == null){ | |
createWindow() | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment