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:
|
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
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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
|
app.on('activate', () => {
|
||||||
// a inicialização e estiver pronto para criar janelas do browser.
|
// On macOS it's common to re-create a window in the app when the
|
||||||
app.on('ready', function() {
|
// dock icon is clicked and there are no other windows open.
|
||||||
// Criar a janela do navegador.
|
if (win === null) {
|
||||||
mainWindow = new BrowserWindow({width: 800, height: 600});
|
createWindow()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
// e carrega o index.html do app.
|
// In this file you can include the rest of your app's specific main process
|
||||||
mainWindow.loadURL('file://' + __dirname + '/index.html');
|
// code. You can also put them in separate files and require them here.
|
||||||
|
|
||||||
// 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;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Finalmente o `index.html` é a página web que você quer mostrar:
|
Finalmente o `index.html` é a página web que você quer mostrar:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue