mirror of
https://git.sanhost.net/sanasol/hytale-f2p.git
synced 2026-02-26 06:41:47 -03:00
Update main.js
This commit is contained in:
80
main.js
80
main.js
@@ -1,6 +1,6 @@
|
|||||||
const { app, BrowserWindow, ipcMain } = require('electron');
|
const { app, BrowserWindow, ipcMain, dialog } = require('electron');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const { launchGame, saveUsername, loadUsername, saveJavaPath, loadJavaPath } = require('./backend/launcher');
|
const { launchGame, saveUsername, loadUsername, saveJavaPath, loadJavaPath, saveInstallPath, loadInstallPath, isGameInstalled, uninstallGame } = require('./backend/launcher');
|
||||||
|
|
||||||
let mainWindow;
|
let mainWindow;
|
||||||
|
|
||||||
@@ -10,6 +10,7 @@ function createWindow() {
|
|||||||
height: 720,
|
height: 720,
|
||||||
frame: false,
|
frame: false,
|
||||||
resizable: false,
|
resizable: false,
|
||||||
|
alwaysOnTop: true,
|
||||||
backgroundColor: '#090909',
|
backgroundColor: '#090909',
|
||||||
webPreferences: {
|
webPreferences: {
|
||||||
preload: path.join(__dirname, 'preload.js'),
|
preload: path.join(__dirname, 'preload.js'),
|
||||||
@@ -61,8 +62,8 @@ app.on('window-all-closed', () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.handle('launch-game', async (event, playerName, javaPath) => {
|
ipcMain.handle('launch-game', async (event, playerName, javaPath, installPath) => {
|
||||||
try {
|
try {
|
||||||
const progressCallback = (message, percent, speed, downloaded, total) => {
|
const progressCallback = (message, percent, speed, downloaded, total) => {
|
||||||
if (mainWindow && !mainWindow.isDestroyed()) {
|
if (mainWindow && !mainWindow.isDestroyed()) {
|
||||||
const data = {
|
const data = {
|
||||||
@@ -76,7 +77,7 @@ ipcMain.handle('launch-game', async (event, playerName, javaPath) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
await launchGame(playerName, progressCallback, javaPath);
|
await launchGame(playerName, progressCallback, javaPath, installPath);
|
||||||
|
|
||||||
return { success: true };
|
return { success: true };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -94,20 +95,55 @@ ipcMain.handle('window-minimize', () => {
|
|||||||
if (mainWindow) mainWindow.minimize();
|
if (mainWindow) mainWindow.minimize();
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.handle('save-username', (event, username) => {
|
ipcMain.handle('save-username', (event, username) => {
|
||||||
saveUsername(username);
|
saveUsername(username);
|
||||||
return { success: true };
|
return { success: true };
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.handle('load-username', () => {
|
ipcMain.handle('load-username', () => {
|
||||||
return loadUsername();
|
return loadUsername();
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.handle('save-java-path', (event, javaPath) => {
|
ipcMain.handle('save-java-path', (event, javaPath) => {
|
||||||
saveJavaPath(javaPath);
|
saveJavaPath(javaPath);
|
||||||
return { success: true };
|
return { success: true };
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.handle('load-java-path', () => {
|
ipcMain.handle('load-java-path', () => {
|
||||||
return loadJavaPath();
|
return loadJavaPath();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
ipcMain.handle('save-install-path', (event, installPath) => {
|
||||||
|
saveInstallPath(installPath);
|
||||||
|
return { success: true };
|
||||||
|
});
|
||||||
|
|
||||||
|
ipcMain.handle('load-install-path', () => {
|
||||||
|
return loadInstallPath();
|
||||||
|
});
|
||||||
|
|
||||||
|
ipcMain.handle('select-install-path', async () => {
|
||||||
|
const result = await dialog.showOpenDialog(mainWindow, {
|
||||||
|
properties: ['openDirectory'],
|
||||||
|
title: 'Select Installation Folder'
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!result.canceled && result.filePaths.length > 0) {
|
||||||
|
return result.filePaths[0];
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
|
||||||
|
ipcMain.handle('is-game-installed', () => {
|
||||||
|
return isGameInstalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
ipcMain.handle('uninstall-game', async () => {
|
||||||
|
try {
|
||||||
|
await uninstallGame();
|
||||||
|
return { success: true };
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Uninstall error:', error);
|
||||||
|
return { success: false, error: error.message };
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user