Update quick-start.md

This commit is contained in:
tiagotol 2016-09-27 14:29:35 -03:00 committed by GitHub
parent 6728efe87e
commit 08808664b6

View file

@ -78,44 +78,55 @@ O `main.js` deve criar as janelas e os manipuladores de eventos do sistema, um t
exemplo: exemplo:
```javascript ```javascript
var app = require('app'); // Módulo para controlar o ciclo de vida do app. const {app, BrowserWindow} = require('electron')
var BrowserWindow = require('browser-window'); // Módulo para criar uma janela nativa do browser.
// Mantenha uma referência global para o objeto window, se você não o fizer, // Keep a global reference of the window object, if you don't, the window will
// a janela será fechada automaticamente quando o objeto JavaScript for // be closed automatically when the JavaScript object is garbage collected.
// coletado pelo garbage collector. let win
var mainWindow = null;
// Sair quando todas as janelas estiverem fechadas. function createWindow () {
app.on('window-all-closed', function() { // Create the browser window.
// No macOS é comum para as aplicações na barra de menu win = new BrowserWindow({width: 800, height: 600})
// continuarem ativas até que o usuário saia explicitamente
// com Cmd + Q // and load the index.html of the app.
if (process.platform != 'darwin') { win.loadURL(`file://${__dirname}/index.html`)
app.quit();
// Open the DevTools.
win.webContents.openDevTools()
// Emitted when the window is closed.
win.on('closed', () => {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
win = null
})
} }
});
// Esse método irá ser chamado quando o Electron finalizar // This method will be called when Electron has finished
// a inicialização e estiver pronto para criar janelas do browser. // initialization and is ready to create browser windows.
app.on('ready', function() { // Some APIs can only be used after this event occurs.
// Criar a janela do navegador. app.on('ready', createWindow)
mainWindow = new BrowserWindow({width: 800, height: 600});
// e carrega o index.html do app. // Quit when all windows are closed.
mainWindow.loadURL('file://' + __dirname + '/index.html'); app.on('window-all-closed', () => {
// On macOS it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') {
app.quit()
}
})
// Abre os DevTools. app.on('activate', () => {
mainWindow.openDevTools(); // On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (win === null) {
createWindow()
}
})
// Emitido quando a janela é fechada. // In this file you can include the rest of your app's specific main process
mainWindow.on('closed', function() { // code. You can also put them in separate files and require them here.
// Desfaz a referência para o objeto window, normalmente você deverá
// guardar as janelas em um array se seu app suportar várias janelas,
// essa é a hora que você deverá deletar o elemento correspondente.
mainWindow = null;
});
});
``` ```
Finalmente o `index.html` é a página web que você quer mostrar: Finalmente o `index.html` é a página web que você quer mostrar: