Skip to content
This repository was archived by the owner on Feb 5, 2026. It is now read-only.

Commit c3907e2

Browse files
authored
Create context-menu.js
1 parent 07601c1 commit c3907e2

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

src/context-menu.js

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
const { Menu, clipboard, shell, BrowserWindow, ipcMain } = require('electron');
2+
const fs = require('fs');
3+
const path = require('path');
4+
5+
function setupContextMenu(mainWindow, view) {
6+
view.webContents.on('context-menu', async (_, params) => {
7+
const template = [
8+
...(params.linkURL ? [{
9+
label: 'Aller sur le lien',
10+
click: () => shell.openExternal(params.linkURL)
11+
}] : []),
12+
{
13+
label: 'Copier',
14+
role: 'copy',
15+
enabled: params.selectionText.trim().length > 0
16+
},
17+
{
18+
label: 'Coller',
19+
role: 'paste'
20+
},
21+
{
22+
label: 'Voir le code source',
23+
click: async () => {
24+
const html = await view.webContents.executeJavaScript('document.documentElement.outerHTML');
25+
const filePath = path.join(__dirname, 'renderer', 'view-source.html');
26+
fs.writeFileSync(filePath, `<pre>${html.replace(/</g, '&lt;')}</pre>`);
27+
mainWindow.webContents.send('open-source-view');
28+
}
29+
}
30+
];
31+
32+
const menu = Menu.buildFromTemplate(template);
33+
menu.popup();
34+
});
35+
}
36+
37+
function setupCreditsShortcut(mainWindow) {
38+
const { globalShortcut } = require('electron');
39+
40+
globalShortcut.register('Control+M', () => {
41+
const creditsWindow = new BrowserWindow({
42+
width: 400,
43+
height: 300,
44+
title: 'Crédits',
45+
resizable: false,
46+
minimizable: false,
47+
maximizable: false,
48+
modal: true,
49+
parent: mainWindow,
50+
webPreferences: {
51+
nodeIntegration: false
52+
}
53+
});
54+
55+
creditsWindow.loadURL(`data:text/html,
56+
<html>
57+
<head><title>Crédits</title></head>
58+
<body style="font-family:sans-serif;padding:20px;">
59+
<h2>Mxlw Browser</h2>
60+
<p>Développé par <b>Maxlware</b>.</p>
61+
<p>Design : Frugiser / Aero / Bento</p>
62+
<p>License : Mozilla Public License 2.0</p>
63+
</body>
64+
</html>`);
65+
});
66+
}
67+
68+
module.exports = {
69+
setupContextMenu,
70+
setupCreditsShortcut
71+
};

0 commit comments

Comments
 (0)