EZPPLauncher/preload/preload.js

108 lines
3.7 KiB
JavaScript
Raw Permalink Normal View History

2022-10-16 13:54:29 +00:00
const { ipcRenderer } = require('electron');
const { Titlebar, Color } = require('custom-electron-titlebar');
2022-10-16 21:16:05 +00:00
const appInfo = require('../appInfo');
2022-10-16 13:54:29 +00:00
let titlebar;
window.addEventListener('DOMContentLoaded', () => {
titlebar = new Titlebar({
backgroundColor: Color.fromHex("#303030"),
itemBackgroundColor: Color.fromHex("#121212"),
menu: null,
maximizable: false
});
2022-10-16 21:16:05 +00:00
titlebar.updateTitle(`${appInfo.appName} ${appInfo.appVersion}`);
2022-10-16 13:54:29 +00:00
const $ = require('jquery');
2022-10-16 19:31:05 +00:00
const Swal = require('sweetalert2');
2022-10-16 13:54:29 +00:00
2022-10-16 20:44:56 +00:00
let currentState;
$("#launch-btn").on('click', async () => {
switch (currentState) {
case "up-to-date":
2022-10-16 21:10:07 +00:00
$("#launch-btn").attr('disabled', true);
$('#launch-btn').html('Launching...');
const result = await ipcRenderer.invoke("launch");
if (!result) {
Swal.fire({
title: 'Uh oh!',
text: "Something went wrong while launching!",
icon: 'error',
confirmButtonText: 'Okay'
});
$("#launch-btn").attr('disabled', false);
$('#launch-btn').html('Launch');
} else {
$("#launch-btn").attr('disabled', true);
$('#launch-btn').html('Running...');
}
2022-10-16 20:44:56 +00:00
break;
case "update-available":
$("#launch-btn").attr('disabled', true);
$('#launch-btn').html('Updating...');
ipcRenderer.send("do-update");
break;
}
});
2022-10-16 13:54:29 +00:00
$("#folder-btn").on('click', async () => {
2022-10-16 14:47:43 +00:00
const success = await ipcRenderer.invoke('set-osu-dir');
if (success == undefined)
return;
2022-10-16 16:42:04 +00:00
if (success) {
2022-10-16 19:31:05 +00:00
Swal.fire({
title: 'Success!',
2022-10-16 20:21:02 +00:00
text: 'osu! folder set.',
2022-10-16 19:31:05 +00:00
icon: 'success',
confirmButtonText: 'Cool'
})
2022-10-16 20:44:56 +00:00
ipcRenderer.send("do-update-check");
2022-10-16 16:42:04 +00:00
} else {
2022-10-16 19:31:05 +00:00
Swal.fire({
title: 'Uh oh!',
2022-10-16 20:21:02 +00:00
text: 'The selected folder is not a osu! directory.',
2022-10-16 19:31:05 +00:00
icon: 'error',
2022-10-16 20:21:02 +00:00
confirmButtonText: 'Oops.. my bad!'
2022-10-16 19:31:05 +00:00
})
2022-10-16 16:42:04 +00:00
}
2022-10-16 13:54:29 +00:00
});
2022-10-16 19:13:30 +00:00
ipcRenderer.on('status_update', (event, status) => {
2022-10-16 20:44:56 +00:00
currentState = status.type;
2022-10-16 19:13:30 +00:00
switch (status.type) {
case "up-to-date":
$("#launch-btn").attr('disabled', false);
$('#launch-btn').html('Launch');
break;
case "update-available":
$("#launch-btn").attr('disabled', false);
$('#launch-btn').html('Update');
break;
2022-10-16 20:21:02 +00:00
case "missing-folder":
2022-10-16 20:44:56 +00:00
$('#launch-btn').html('Please set your osu! folder');
break;
case "error":
Swal.fire({
title: 'Uh oh!',
text: status.message,
icon: 'error',
confirmButtonText: 'Okay'
});
ipcRenderer.send("do-update-check");
break;
case "update-complete":
Swal.fire({
title: 'Yaaay!',
text: "Your osu! client has been successfully updated!",
icon: 'success',
confirmButtonText: 'Thanks :3'
});
ipcRenderer.send("do-update-check");
break;
2022-10-16 19:13:30 +00:00
}
})
2022-10-16 20:21:02 +00:00
// workaround for the dark theme
$('head').append($('<link href="../assets/sweetalert2.dark.css" rel="stylesheet" />'));
2022-10-16 13:54:29 +00:00
})