Skip to content

Commit 51bf7b7

Browse files
committed
Füge die Hauptdateien für den Minecraft Launcher hinzu und implementiere die Startfunktionalität
1 parent c95165f commit 51bf7b7

File tree

4 files changed

+106
-0
lines changed

4 files changed

+106
-0
lines changed

index.html

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Minecraft Launcher</title>
6+
<style>
7+
body {
8+
font-family: Arial, sans-serif;
9+
margin: 0;
10+
padding: 0;
11+
display: flex;
12+
flex-direction: column;
13+
align-items: center;
14+
justify-content: center;
15+
height: 100vh;
16+
background-color: #282c34;
17+
color: white;
18+
}
19+
#launch-btn {
20+
padding: 10px 20px;
21+
font-size: 18px;
22+
color: white;
23+
background-color: #61dafb;
24+
border: none;
25+
border-radius: 5px;
26+
cursor: pointer;
27+
}
28+
#launch-btn:hover {
29+
background-color: #21a1f1;
30+
}
31+
</style>
32+
</head>
33+
<body>
34+
<h1>Minecraft Launcher</h1>
35+
<button id="launch-btn">Launch Minecraft</button>
36+
<script type="module" src="renderer.js"></script>
37+
</body>
38+
</html>

main.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { app, BrowserWindow } from 'electron';
2+
import path from 'path';
3+
import { fileURLToPath } from 'url';
4+
5+
const __filename = fileURLToPath(import.meta.url);
6+
const __dirname = path.dirname(__filename);
7+
8+
let mainWindow;
9+
10+
const createWindow = () => {
11+
mainWindow = new BrowserWindow({
12+
width: 800,
13+
height: 600,
14+
webPreferences: {
15+
preload: path.join(__dirname, 'preload.js'), // Optional for secure communication
16+
nodeIntegration: true, // Enable Node.js APIs
17+
},
18+
});
19+
mainWindow.loadFile('index.html');
20+
};
21+
22+
app.on('ready', createWindow);
23+
24+
app.on('window-all-closed', () => {
25+
if (process.platform !== 'darwin') {
26+
app.quit();
27+
}
28+
});
29+
30+
app.on('activate', () => {
31+
if (BrowserWindow.getAllWindows().length === 0) {
32+
createWindow();
33+
}
34+
});

preload.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { contextBridge } from 'electron';
2+
import { exec } from 'child_process';
3+
4+
contextBridge.exposeInMainWorld('api', {
5+
launchMinecraft: () => {
6+
exec('node index.js', (error, stdout, stderr) => {
7+
if (error) {
8+
console.error(`Error: ${error.message}`);
9+
return 'Failed to launch Minecraft!';
10+
}
11+
if (stderr) {
12+
console.error(`Stderr: ${stderr}`);
13+
}
14+
console.log(`Stdout: ${stdout}`);
15+
return 'Minecraft launched successfully!';
16+
});
17+
},
18+
});

renderer.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { exec } from 'child_process';
2+
3+
document.getElementById('launch-btn').addEventListener('click', () => {
4+
exec('node index.js', (error, stdout, stderr) => {
5+
if (error) {
6+
console.error(`Error: ${error.message}`);
7+
alert('Failed to launch Minecraft!');
8+
return;
9+
}
10+
if (stderr) {
11+
console.error(`Stderr: ${stderr}`);
12+
}
13+
console.log(`Stdout: ${stdout}`);
14+
alert('Minecraft launched successfully!');
15+
});
16+
});

0 commit comments

Comments
 (0)