-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
74 lines (64 loc) · 2.44 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
const { app, BrowserWindow, dialog } = require('electron')
app.showExitPrompt = true
// Gardez une reference globale de l'objet window, si vous ne le faites pas, la fenetre sera
// fermee automatiquement quand l'objet JavaScript sera garbage collected.
let win
function createWindow () {
// Créer le browser window.
win = new BrowserWindow({
width: 1024,
height: 768,
webPreferences: {
nodeIntegration: false
},
icon: __dirname + '/128.png'
})
// and load the index.html of the app.
win.loadURL('http://127.0.0.1:5050/')
// Ouvre les DevTools.
//win.webContents.openDevTools()
win.on('close', (e) => {
if (app.showExitPrompt) {
let ret = !!dialog.showMessageBox(win, {
type: 'question',
buttons: ['Yes', 'No'],
title: 'Confirm',
message: 'Unsaved data will be lost. Are you sure you want to quit?'
}).then(answer => {
if (answer.response === 0) {
app.showExitPrompt = false
// Pas certains que cela soit la bonne façon de faire... -- JPM
win.destroy()
}
})
e.preventDefault() // Prevents the window from closing
}
})
// Émit lorsque la fenêtre est fermée.
win.on('closed', () => {
// Dé-référence l'objet window , normalement, vous stockeriez les fenêtres
// dans un tableau si votre application supporte le multi-fenêtre. C'est le moment
// où vous devez supprimer l'élément correspondant.
win = null
})
}
// Cette méthode sera appelée quant Electron aura fini
// de s'initialiser et sera prêt à créer des fenêtres de navigation.
// Certaines APIs peuvent être utilisées uniquement quand cet événement est émit.
app.on('ready', createWindow)
// Quitte l'application quand toutes les fenêtres sont fermées.
app.on('window-all-closed', () => {
// Sur macOS, il est commun pour une application et leur barre de menu
// de rester active tant que l'utilisateur ne quitte pas explicitement avec Cmd + Q
if (process.platform !== 'darwin') {
app.quit()
}
})
app.on('activate', () => {
// Sur macOS, il est commun de re-créer une fenêtre de l'application quand
// l'icône du dock est cliquée et qu'il n'y a pas d'autres fenêtres d'ouvertes.
if (win === null) {
createWindow()
}
})
// Dans ce fichier, vous pouvez inclure le reste de votre code spécifique au processus principal. Vous pouvez également le mettre dans des fichiers séparés et les inclure ici.