File tree Expand file tree Collapse file tree 4 files changed +106
-0
lines changed
Expand file tree Collapse file tree 4 files changed +106
-0
lines changed Original file line number Diff line number Diff line change 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 >
Original file line number Diff line number Diff line change 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+ } ) ;
Original file line number Diff line number Diff line change 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+ } ) ;
Original file line number Diff line number Diff line change 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+ } ) ;
You can’t perform that action at this time.
0 commit comments