mirror of
https://git.sanhost.net/sanasol/hytale-f2p
synced 2026-02-26 09:21:48 -03:00
105 lines
2.9 KiB
JavaScript
105 lines
2.9 KiB
JavaScript
const { app, BrowserWindow, ipcMain } = require('electron');
|
|
const path = require('path');
|
|
const { launchGame, saveUsername, loadUsername } = require('./backend/launcher');
|
|
|
|
let mainWindow;
|
|
|
|
function createWindow() {
|
|
mainWindow = new BrowserWindow({
|
|
width: 1280,
|
|
height: 720,
|
|
frame: false,
|
|
resizable: false,
|
|
backgroundColor: '#090909',
|
|
webPreferences: {
|
|
preload: path.join(__dirname, 'preload.js'),
|
|
nodeIntegration: false,
|
|
contextIsolation: true,
|
|
devTools: false,
|
|
webSecurity: true
|
|
}
|
|
});
|
|
|
|
mainWindow.loadFile('index.html');
|
|
|
|
mainWindow.webContents.on('devtools-opened', () => {
|
|
mainWindow.webContents.closeDevTools();
|
|
});
|
|
|
|
mainWindow.webContents.on('before-input-event', (event, input) => {
|
|
if (input.control && input.shift && input.key.toLowerCase() === 'i') {
|
|
event.preventDefault();
|
|
}
|
|
if (input.control && input.shift && input.key.toLowerCase() === 'j') {
|
|
event.preventDefault();
|
|
}
|
|
if (input.control && input.shift && input.key.toLowerCase() === 'c') {
|
|
event.preventDefault();
|
|
}
|
|
if (input.key === 'F12') {
|
|
event.preventDefault();
|
|
}
|
|
if (input.key === 'F5') {
|
|
event.preventDefault();
|
|
}
|
|
});
|
|
|
|
mainWindow.webContents.on('context-menu', (e) => {
|
|
e.preventDefault();
|
|
});
|
|
|
|
mainWindow.webContents.setIgnoreMenuShortcuts(true);
|
|
}
|
|
|
|
app.whenReady().then(() => {
|
|
createWindow();
|
|
});
|
|
|
|
app.on('window-all-closed', () => {
|
|
if (process.platform !== 'darwin') {
|
|
app.quit();
|
|
}
|
|
});
|
|
|
|
ipcMain.handle('launch-game', async (event, playerName) => {
|
|
try {
|
|
const progressCallback = (message, percent, speed, downloaded, total) => {
|
|
if (mainWindow && !mainWindow.isDestroyed()) {
|
|
const data = {
|
|
message: message || null,
|
|
percent: percent !== null && percent !== undefined ? Math.min(100, Math.max(0, percent)) : null,
|
|
speed: speed !== null && speed !== undefined ? speed : null,
|
|
downloaded: downloaded !== null && downloaded !== undefined ? downloaded : null,
|
|
total: total !== null && total !== undefined ? total : null
|
|
};
|
|
mainWindow.webContents.send('progress-update', data);
|
|
}
|
|
};
|
|
|
|
await launchGame(playerName, progressCallback);
|
|
|
|
return { success: true };
|
|
} catch (error) {
|
|
console.error('Launch error:', error);
|
|
const errorMessage = error.message || error.toString();
|
|
return { success: false, error: errorMessage };
|
|
}
|
|
});
|
|
|
|
ipcMain.handle('window-close', () => {
|
|
if (mainWindow) mainWindow.close();
|
|
});
|
|
|
|
ipcMain.handle('window-minimize', () => {
|
|
if (mainWindow) mainWindow.minimize();
|
|
});
|
|
|
|
ipcMain.handle('save-username', (event, username) => {
|
|
saveUsername(username);
|
|
return { success: true };
|
|
});
|
|
|
|
ipcMain.handle('load-username', () => {
|
|
return loadUsername();
|
|
});
|