-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
121 lines (110 loc) · 3.61 KB
/
main.js
File metadata and controls
121 lines (110 loc) · 3.61 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
const { app, BrowserWindow, Menu, shell } = require('electron');
const path = require('path');
// Garder une référence globale de l'objet window
let mainWindow;
function createWindow() {
// Créer la fenêtre du navigateur
mainWindow = new BrowserWindow({
width: 1400,
height: 900,
minWidth: 1000,
minHeight: 700,
icon: path.join(__dirname, 'icon.png'),
webPreferences: {
nodeIntegration: false,
contextIsolation: true,
preload: path.join(__dirname, 'preload.js')
},
backgroundColor: '#0a0a1a',
show: false, // Ne pas afficher avant que ce soit prêt
titleBarStyle: 'default',
autoHideMenuBar: true // Cache la barre de menu par défaut
});
// Charger le fichier index.html
mainWindow.loadFile(path.join(__dirname, 'idlegame', 'index.html'));
// Afficher quand c'est prêt (évite le flash blanc)
mainWindow.once('ready-to-show', () => {
mainWindow.show();
});
// Ouvrir les liens externes dans le navigateur par défaut
mainWindow.webContents.setWindowOpenHandler(({ url }) => {
shell.openExternal(url);
return { action: 'deny' };
});
// Menu personnalisé (minimal)
const menu = Menu.buildFromTemplate([
{
label: 'Jeu',
submenu: [
{
label: 'Plein écran',
accelerator: 'F11',
click: () => {
mainWindow.setFullScreen(!mainWindow.isFullScreen());
}
},
{ type: 'separator' },
{
label: 'Outils de développement',
accelerator: 'F12',
click: () => {
mainWindow.webContents.toggleDevTools();
}
},
{ type: 'separator' },
{
label: 'Quitter',
accelerator: 'Alt+F4',
click: () => {
app.quit();
}
}
]
},
{
label: 'Aide',
submenu: [
{
label: 'À propos',
click: () => {
const { dialog } = require('electron');
dialog.showMessageBox(mainWindow, {
type: 'info',
title: 'Cosmic Miner',
message: 'Cosmic Miner v1.0.0',
detail: 'Un jeu idle spatial\n\nDéveloppé par Lulunoel2016\n\nMerci de jouer !'
});
}
}
]
}
]);
Menu.setApplicationMenu(menu);
// Émis quand la fenêtre est fermée
mainWindow.on('closed', () => {
mainWindow = null;
});
}
// Quand Electron a fini l'initialisation
app.whenReady().then(createWindow);
// Quitter quand toutes les fenêtres sont fermées
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
if (mainWindow === null) {
createWindow();
}
});
// Sécurité : empêcher la navigation vers des URLs externes
app.on('web-contents-created', (event, contents) => {
contents.on('will-navigate', (event, navigationUrl) => {
const parsedUrl = new URL(navigationUrl);
if (parsedUrl.protocol !== 'file:') {
event.preventDefault();
shell.openExternal(navigationUrl);
}
});
});