mirror of
https://github.com/araxiaonline/araxiapatch-ts.git
synced 2026-06-13 03:02:23 -04:00
81 lines
2.0 KiB
TypeScript
81 lines
2.0 KiB
TypeScript
import { app, BrowserWindow } from 'electron';
|
|
import { download } from 'electron-dl';
|
|
|
|
// Files to download
|
|
const files: string[] = [
|
|
"info.txt",
|
|
"AraxiaPatchv1.tar.gz",
|
|
"HDPatchv1.tar.gz",
|
|
];
|
|
|
|
const patchSource = 'https://storage.googleapis.com/araxia-client-patches/Updatev1/';
|
|
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}`);
|
|
});
|
|
});
|
|
});
|