whole update logic working
This commit is contained in:
parent
c2a75319dc
commit
8d29bd6822
93
app.js
93
app.js
|
@ -21,10 +21,73 @@ const run = () => {
|
||||||
|
|
||||||
mainWindow = createWindow();
|
mainWindow = createWindow();
|
||||||
mainWindow.on('show', async () => {
|
mainWindow.on('show', async () => {
|
||||||
|
await doUpdateCheck(mainWindow);
|
||||||
|
})
|
||||||
|
app.on('activate', function () {
|
||||||
|
if (BrowserWindow.getAllWindows().length === 0) mainWindow = createWindow();
|
||||||
|
})
|
||||||
|
app.on('window-all-closed', () => {
|
||||||
|
app.quit()
|
||||||
|
})
|
||||||
|
ipcMain.on('do-update-check', async () => {
|
||||||
|
await doUpdateCheck(mainWindow);
|
||||||
|
})
|
||||||
|
ipcMain.on('do-update', async () => {
|
||||||
const osuPath = await config.get("osuPath", "");
|
const osuPath = await config.get("osuPath", "");
|
||||||
const isValid = await osuUtil.isValidOsuFolder(osuPath);
|
const isValid = await osuUtil.isValidOsuFolder(osuPath);
|
||||||
if (osuPath.trim == "" || !isValid) {
|
if (osuPath.trim == "" || !isValid) {
|
||||||
mainWindow.webContents.send('status_update', {
|
mainWindow.webContents.send('status_update', {
|
||||||
|
type: "error",
|
||||||
|
message: "Invalid osu! folder"
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (fs.existsSync(osuPath)) {
|
||||||
|
tempOsuPath = osuPath;
|
||||||
|
const osuConfig = await osuUtil.getLatestConfig(tempOsuPath);
|
||||||
|
const lastVersion = await osuConfig.get("LastVersion");
|
||||||
|
let releaseStream = "stable40";
|
||||||
|
if (lastVersion.endsWith("cuttingedge"))
|
||||||
|
releaseStream = "cuttingedge"
|
||||||
|
else if (lastVersion.endsWith("beta"))
|
||||||
|
releaseStream = "beta";
|
||||||
|
|
||||||
|
const releaseFiles = await osuUtil.getUpdateFiles(releaseStream);
|
||||||
|
const filesToDownload = await osuUtil.filesThatNeedUpdate(tempOsuPath, releaseFiles);
|
||||||
|
const downloadTask = await osuUtil.downloadUpdateFiles(osuPath, filesToDownload);
|
||||||
|
downloadTask.on('completed', () => {
|
||||||
|
mainWindow.webContents.send('status_update', {
|
||||||
|
type: "update-complete"
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
} else
|
||||||
|
mainWindow.webContents.send('status_update', {
|
||||||
|
type: "error",
|
||||||
|
message: "Invalid osu! folder"
|
||||||
|
});
|
||||||
|
})
|
||||||
|
ipcMain.handle('set-osu-dir', async (event) => {
|
||||||
|
const yes = await dialog.showOpenDialog({
|
||||||
|
properties: ['openDirectory']
|
||||||
|
})
|
||||||
|
if (yes.filePaths.length <= 0)
|
||||||
|
return undefined;
|
||||||
|
const folderPath = yes.filePaths[0];
|
||||||
|
const validOsuDir = await osuUtil.isValidOsuFolder(folderPath);
|
||||||
|
|
||||||
|
if (validOsuDir) await config.set("osuPath", folderPath);
|
||||||
|
|
||||||
|
return validOsuDir;
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
async function doUpdateCheck(window) {
|
||||||
|
const osuPath = await config.get("osuPath", "");
|
||||||
|
const isValid = await osuUtil.isValidOsuFolder(osuPath);
|
||||||
|
if (osuPath.trim == "" || !isValid) {
|
||||||
|
window.webContents.send('status_update', {
|
||||||
type: "missing-folder"
|
type: "missing-folder"
|
||||||
})
|
})
|
||||||
return;
|
return;
|
||||||
|
@ -41,38 +104,14 @@ const run = () => {
|
||||||
|
|
||||||
const releaseFiles = await osuUtil.getUpdateFiles(releaseStream);
|
const releaseFiles = await osuUtil.getUpdateFiles(releaseStream);
|
||||||
const filesToDownload = await osuUtil.filesThatNeedUpdate(tempOsuPath, releaseFiles);
|
const filesToDownload = await osuUtil.filesThatNeedUpdate(tempOsuPath, releaseFiles);
|
||||||
// const downloadTask = await osuUtil.downloadUpdateFiles(osuPath, filesToDownload);
|
console.log("sending update check " + (filesToDownload.length > 0 ? "update-available" : "up-to-date"))
|
||||||
// downloadTask.on('completed', () => {
|
window.webContents.send('status_update', {
|
||||||
// console.log("done!");
|
|
||||||
// });
|
|
||||||
mainWindow.webContents.send('status_update', {
|
|
||||||
type: filesToDownload.length > 0 ? "update-available" : "up-to-date"
|
type: filesToDownload.length > 0 ? "update-available" : "up-to-date"
|
||||||
})
|
})
|
||||||
} else
|
} else
|
||||||
mainWindow.webContents.send('status_update', {
|
window.webContents.send('status_update', {
|
||||||
type: "missing-folder"
|
type: "missing-folder"
|
||||||
})
|
})
|
||||||
})
|
|
||||||
app.on('activate', function () {
|
|
||||||
if (BrowserWindow.getAllWindows().length === 0) mainWindow = createWindow();
|
|
||||||
})
|
|
||||||
app.on('window-all-closed', () => {
|
|
||||||
app.quit()
|
|
||||||
})
|
|
||||||
ipcMain.handle('set-osu-dir', async (event) => {
|
|
||||||
const yes = await dialog.showOpenDialog({
|
|
||||||
properties: ['openDirectory']
|
|
||||||
})
|
|
||||||
if (yes.filePaths.length <= 0)
|
|
||||||
return undefined;
|
|
||||||
const folderPath = yes.filePaths[0];
|
|
||||||
const validOsuDir = await osuUtil.isValidOsuFolder(folderPath);
|
|
||||||
|
|
||||||
if (validOsuDir) await config.set("osuPath", folderPath);
|
|
||||||
|
|
||||||
return validOsuDir;
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function createWindow() {
|
function createWindow() {
|
||||||
|
|
|
@ -120,7 +120,9 @@ async function downloadUpdateFiles(osuPath, filesToUpdate) {
|
||||||
let completedIndex = 0;
|
let completedIndex = 0;
|
||||||
filesToUpdate.forEach(async (fileToUpdate) => {
|
filesToUpdate.forEach(async (fileToUpdate) => {
|
||||||
const filePath = path.join(osuPath, fileToUpdate.fileName);
|
const filePath = path.join(osuPath, fileToUpdate.fileName);
|
||||||
|
if (await fu.existsAsync(filePath))
|
||||||
await fs.promises.rm(filePath);
|
await fs.promises.rm(filePath);
|
||||||
|
|
||||||
const fileDownload = new DownloaderHelper(fileToUpdate.fileURL, osuPath, {
|
const fileDownload = new DownloaderHelper(fileToUpdate.fileURL, osuPath, {
|
||||||
fileName: fileToUpdate.fileName,
|
fileName: fileToUpdate.fileName,
|
||||||
override: true,
|
override: true,
|
||||||
|
|
|
@ -15,6 +15,21 @@ window.addEventListener('DOMContentLoaded', () => {
|
||||||
const $ = require('jquery');
|
const $ = require('jquery');
|
||||||
const Swal = require('sweetalert2');
|
const Swal = require('sweetalert2');
|
||||||
|
|
||||||
|
let currentState;
|
||||||
|
|
||||||
|
$("#launch-btn").on('click', async () => {
|
||||||
|
switch (currentState) {
|
||||||
|
case "up-to-date":
|
||||||
|
//TODO: launch client
|
||||||
|
break;
|
||||||
|
case "update-available":
|
||||||
|
$("#launch-btn").attr('disabled', true);
|
||||||
|
$('#launch-btn').html('Updating...');
|
||||||
|
ipcRenderer.send("do-update");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
$("#folder-btn").on('click', async () => {
|
$("#folder-btn").on('click', async () => {
|
||||||
const success = await ipcRenderer.invoke('set-osu-dir');
|
const success = await ipcRenderer.invoke('set-osu-dir');
|
||||||
if (success == undefined)
|
if (success == undefined)
|
||||||
|
@ -26,6 +41,7 @@ window.addEventListener('DOMContentLoaded', () => {
|
||||||
icon: 'success',
|
icon: 'success',
|
||||||
confirmButtonText: 'Cool'
|
confirmButtonText: 'Cool'
|
||||||
})
|
})
|
||||||
|
ipcRenderer.send("do-update-check");
|
||||||
} else {
|
} else {
|
||||||
Swal.fire({
|
Swal.fire({
|
||||||
title: 'Uh oh!',
|
title: 'Uh oh!',
|
||||||
|
@ -37,6 +53,7 @@ window.addEventListener('DOMContentLoaded', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcRenderer.on('status_update', (event, status) => {
|
ipcRenderer.on('status_update', (event, status) => {
|
||||||
|
currentState = status.type;
|
||||||
switch (status.type) {
|
switch (status.type) {
|
||||||
case "up-to-date":
|
case "up-to-date":
|
||||||
$("#launch-btn").attr('disabled', false);
|
$("#launch-btn").attr('disabled', false);
|
||||||
|
@ -47,7 +64,26 @@ window.addEventListener('DOMContentLoaded', () => {
|
||||||
$('#launch-btn').html('Update');
|
$('#launch-btn').html('Update');
|
||||||
break;
|
break;
|
||||||
case "missing-folder":
|
case "missing-folder":
|
||||||
$('#launch-btn').html('Please set your osu folder!');
|
$('#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;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -33,9 +33,9 @@ module.exports = {
|
||||||
|
|
||||||
window.webContents.setUserAgent("EZPPLauncher");
|
window.webContents.setUserAgent("EZPPLauncher");
|
||||||
attachTitlebarToWindow(window);
|
attachTitlebarToWindow(window);
|
||||||
window.webContents.openDevTools({
|
// window.webContents.openDevTools({
|
||||||
mode: "detach"
|
// mode: "detach"
|
||||||
});
|
// });
|
||||||
|
|
||||||
return window;
|
return window;
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue
Block a user