mirror of
https://github.com/araxiaonline/araxiapatch-ts.git
synced 2026-06-13 03:02:23 -04:00
init
This commit is contained in:
92
app.ts
Normal file
92
app.ts
Normal file
@@ -0,0 +1,92 @@
|
||||
import { app, BrowserWindow } from 'electron';
|
||||
import { download } from 'electron-dl';
|
||||
|
||||
// Files to download
|
||||
const files: string[] = [
|
||||
'info.txt',
|
||||
'patch-4.mpq',
|
||||
'patch-5.mpq',
|
||||
'patch-7.mpq',
|
||||
'patch-9.mpq',
|
||||
'patch-B.mpq',
|
||||
'patch-C.mpq',
|
||||
'patch-D.mpq',
|
||||
'patch-F.mpq',
|
||||
'patch-G.mpq',
|
||||
'patch-J.mpq',
|
||||
'patch-L.mpq',
|
||||
'patch-S.mpq',
|
||||
'patch-T.mpq',
|
||||
'patch-U.mpq',
|
||||
];
|
||||
|
||||
const patchSource = 'https://storage.googleapis.com/araxia-client-patches/';
|
||||
const appName = 'Araxia Client Patch Downloader';
|
||||
|
||||
let mainWindow: BrowserWindow | null;
|
||||
|
||||
function createWindow() {
|
||||
// Create the browser window
|
||||
mainWindow = new BrowserWindow({
|
||||
width: 800,
|
||||
height: 600,
|
||||
webPreferences: {
|
||||
nodeIntegration: true,
|
||||
},
|
||||
});
|
||||
|
||||
// Load the index.html file
|
||||
mainWindow.loadFile('index.html');
|
||||
|
||||
// Open the DevTools.
|
||||
// mainWindow.webContents.openDevTools();
|
||||
|
||||
// Emitted when the window is closed
|
||||
mainWindow.on('closed', function () {
|
||||
mainWindow = null;
|
||||
});
|
||||
|
||||
// Handle the close button click
|
||||
mainWindow.on('close', function (e) {
|
||||
// Prevent the window from closing immediately
|
||||
e.preventDefault();
|
||||
app.quit();
|
||||
});
|
||||
}
|
||||
|
||||
// Create the main window when the app is ready
|
||||
app.on('ready', createWindow);
|
||||
|
||||
// Quit the app when all windows are closed (except on macOS)
|
||||
app.on('window-all-closed', function () {
|
||||
if (process.platform !== 'darwin') {
|
||||
app.quit();
|
||||
}
|
||||
});
|
||||
|
||||
// Create a new window when the app is activated (on macOS)
|
||||
app.on('activate', function () {
|
||||
if (mainWindow === null) {
|
||||
createWindow();
|
||||
}
|
||||
});
|
||||
|
||||
// Handle file downloads
|
||||
app.on('ready', function () {
|
||||
// Specify the directory where files will be downloaded
|
||||
const directory = app.getPath('userData');
|
||||
|
||||
// Download each file in parallel
|
||||
files.forEach((file, index) => {
|
||||
download(mainWindow, patchSource + file, { directory, filename: file })
|
||||
.then(() => {
|
||||
// File downloaded successfully
|
||||
console.log(`File ${file} downloaded.`);
|
||||
mainWindow?.webContents.send('update-progress', { index, progress: 100 });
|
||||
})
|
||||
.catch((error) => {
|
||||
// Error occurred during download
|
||||
console.error(`Error downloading file ${file}: ${error}`);
|
||||
});
|
||||
});
|
||||
});
|
||||
18
index.html
Normal file
18
index.html
Normal file
@@ -0,0 +1,18 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Araxia Client Patch Downloader</title>
|
||||
<link rel="stylesheet" href="styles.css">
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1>Araxia Client Patch Downloader</h1>
|
||||
<div class="progress-bars">
|
||||
<!-- Progress bars will be dynamically added here -->
|
||||
</div>
|
||||
</div>
|
||||
<script src="renderer.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
38
renderer.js
Normal file
38
renderer.js
Normal file
@@ -0,0 +1,38 @@
|
||||
const { ipcRenderer } = require('electron');
|
||||
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
// Listen for progress update messages from the main process
|
||||
ipcRenderer.on('update-progress', (event, data) => {
|
||||
updateProgressBar(data.index, data.progress);
|
||||
});
|
||||
});
|
||||
|
||||
// Function to update the progress bar for a specific file
|
||||
function updateProgressBar(index, progress) {
|
||||
const progressBar = document.getElementById(`progress-bar-${index}`);
|
||||
if (progressBar) {
|
||||
const progressBarInner = progressBar.querySelector('.progress');
|
||||
progressBarInner.style.width = `${progress}%`;
|
||||
|
||||
// Update the progress label
|
||||
const progressLabel = progressBar.querySelector('.progress-label');
|
||||
progressLabel.textContent = `File ${index} (${progress}%)`;
|
||||
|
||||
// Update the download speed if available
|
||||
const progressSpeed = progressBar.querySelector('.progress-speed');
|
||||
if (progressSpeed) {
|
||||
progressSpeed.textContent = `Speed: ${getFormattedSpeed()}`
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Function to format the download speed
|
||||
function getFormattedSpeed(speed) {
|
||||
if (speed < 1024) {
|
||||
return `${speed.toFixed(2)} B/s`;
|
||||
} else if (speed < 1024 * 1024) {
|
||||
return `${(speed / 1024).toFixed(2)} KB/s`;
|
||||
} else {
|
||||
return `${(speed / 1024 / 1024).toFixed(2)} MB/s`;
|
||||
}
|
||||
}
|
||||
67
style.css
Normal file
67
style.css
Normal file
@@ -0,0 +1,67 @@
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
background-color: #f0f0f0;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 800px;
|
||||
margin: 0 auto;
|
||||
padding: 20px;
|
||||
text-align: center;
|
||||
background-color: #fff;
|
||||
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.2);
|
||||
border-radius: 5px;
|
||||
position: relative;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 24px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.progress-bars {
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.progress-bar {
|
||||
margin-bottom: 10px;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.progress-label {
|
||||
flex: 1;
|
||||
margin-right: 10px;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.progress-bar-inner {
|
||||
flex: 4;
|
||||
}
|
||||
|
||||
.progressBar {
|
||||
width: 100%;
|
||||
height: 20px;
|
||||
border-radius: 5px;
|
||||
background-color: #f0f0f0;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.progressBar .progress {
|
||||
height: 100%;
|
||||
background-color: #007bff;
|
||||
transition: width 0.3s ease-in-out;
|
||||
}
|
||||
|
||||
.progress-speed {
|
||||
flex: 1;
|
||||
font-size: 12px;
|
||||
text-align: right;
|
||||
color: #888;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user