Update quick-start.md
This commit is contained in:
parent
6728efe87e
commit
08808664b6
1 changed files with 44 additions and 33 deletions
|
@ -78,44 +78,55 @@ O `main.js` deve criar as janelas e os manipuladores de eventos do sistema, um t
|
|||
exemplo:
|
||||
|
||||
```javascript
|
||||
var app = require('app'); // Módulo para controlar o ciclo de vida do app.
|
||||
var BrowserWindow = require('browser-window'); // Módulo para criar uma janela nativa do browser.
|
||||
const {app, BrowserWindow} = require('electron')
|
||||
|
||||
// Mantenha uma referência global para o objeto window, se você não o fizer,
|
||||
// a janela será fechada automaticamente quando o objeto JavaScript for
|
||||
// coletado pelo garbage collector.
|
||||
var mainWindow = null;
|
||||
// Keep a global reference of the window object, if you don't, the window will
|
||||
// be closed automatically when the JavaScript object is garbage collected.
|
||||
let win
|
||||
|
||||
// Sair quando todas as janelas estiverem fechadas.
|
||||
app.on('window-all-closed', function() {
|
||||
// No macOS é comum para as aplicações na barra de menu
|
||||
// continuarem ativas até que o usuário saia explicitamente
|
||||
// com Cmd + Q
|
||||
if (process.platform != 'darwin') {
|
||||
app.quit();
|
||||
function createWindow () {
|
||||
// Create the browser window.
|
||||
win = new BrowserWindow({width: 800, height: 600})
|
||||
|
||||
// and load the index.html of the app.
|
||||
win.loadURL(`file://${__dirname}/index.html`)
|
||||
|
||||
// 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
|
||||
})
|
||||
}
|
||||
|
||||
// This method will be called when Electron has finished
|
||||
// initialization and is ready to create browser windows.
|
||||
// Some APIs can only be used after this event occurs.
|
||||
app.on('ready', createWindow)
|
||||
|
||||
// Quit when all windows are closed.
|
||||
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()
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
// Esse método irá ser chamado quando o Electron finalizar
|
||||
// a inicialização e estiver pronto para criar janelas do browser.
|
||||
app.on('ready', function() {
|
||||
// Criar a janela do navegador.
|
||||
mainWindow = new BrowserWindow({width: 800, height: 600});
|
||||
app.on('activate', () => {
|
||||
// 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()
|
||||
}
|
||||
})
|
||||
|
||||
// e carrega o index.html do app.
|
||||
mainWindow.loadURL('file://' + __dirname + '/index.html');
|
||||
|
||||
// Abre os DevTools.
|
||||
mainWindow.openDevTools();
|
||||
|
||||
// Emitido quando a janela é fechada.
|
||||
mainWindow.on('closed', function() {
|
||||
// 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;
|
||||
});
|
||||
});
|
||||
// In this file you can include the rest of your app's specific main process
|
||||
// code. You can also put them in separate files and require them here.
|
||||
```
|
||||
|
||||
Finalmente o `index.html` é a página web que você quer mostrar:
|
||||
|
|
Loading…
Add table
Reference in a new issue