Compare commits
7 Commits
c2a75319dc
...
1.0.0
Author | SHA1 | Date | |
---|---|---|---|
2b12654825 | |||
293ea1b798 | |||
5f36de6697 | |||
a0628cc873 | |||
5c87704b10 | |||
72958950b7 | |||
8d29bd6822 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,2 +1,3 @@
|
||||
node_modules/
|
||||
release/
|
||||
yarn.lock
|
80
app.js
80
app.js
@@ -21,12 +21,31 @@ const run = () => {
|
||||
|
||||
mainWindow = createWindow();
|
||||
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.handle('launch', async () => {
|
||||
const result = await osuUtil.startOsuWithDevServer(tempOsuPath, "ez-pp.farm", async () => {
|
||||
await doUpdateCheck(mainWindow);
|
||||
});
|
||||
return result;
|
||||
})
|
||||
ipcMain.on('do-update-check', async () => {
|
||||
await doUpdateCheck(mainWindow);
|
||||
})
|
||||
ipcMain.on('do-update', async () => {
|
||||
const osuPath = await config.get("osuPath", "");
|
||||
const isValid = await osuUtil.isValidOsuFolder(osuPath);
|
||||
if (osuPath.trim == "" || !isValid) {
|
||||
mainWindow.webContents.send('status_update', {
|
||||
type: "missing-folder"
|
||||
})
|
||||
type: "error",
|
||||
message: "Invalid osu! folder"
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (fs.existsSync(osuPath)) {
|
||||
@@ -41,23 +60,18 @@ const run = () => {
|
||||
|
||||
const releaseFiles = await osuUtil.getUpdateFiles(releaseStream);
|
||||
const filesToDownload = await osuUtil.filesThatNeedUpdate(tempOsuPath, releaseFiles);
|
||||
// const downloadTask = await osuUtil.downloadUpdateFiles(osuPath, filesToDownload);
|
||||
// downloadTask.on('completed', () => {
|
||||
// console.log("done!");
|
||||
// });
|
||||
mainWindow.webContents.send('status_update', {
|
||||
type: filesToDownload.length > 0 ? "update-available" : "up-to-date"
|
||||
})
|
||||
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: "missing-folder"
|
||||
})
|
||||
})
|
||||
app.on('activate', function () {
|
||||
if (BrowserWindow.getAllWindows().length === 0) mainWindow = createWindow();
|
||||
})
|
||||
app.on('window-all-closed', () => {
|
||||
app.quit()
|
||||
type: "error",
|
||||
message: "Invalid osu! folder"
|
||||
});
|
||||
})
|
||||
ipcMain.handle('set-osu-dir', async (event) => {
|
||||
const yes = await dialog.showOpenDialog({
|
||||
@@ -75,9 +89,39 @@ const run = () => {
|
||||
})
|
||||
}
|
||||
|
||||
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"
|
||||
})
|
||||
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);
|
||||
window.webContents.send('status_update', {
|
||||
type: filesToDownload.length > 0 ? "update-available" : "up-to-date"
|
||||
})
|
||||
} else
|
||||
window.webContents.send('status_update', {
|
||||
type: "missing-folder"
|
||||
})
|
||||
}
|
||||
|
||||
function createWindow() {
|
||||
// Create the browser window.
|
||||
const win = windowManager.createWindow(520, 420);
|
||||
const win = windowManager.createWindow(520, 350);
|
||||
|
||||
win.loadFile('./html/index.html');
|
||||
|
||||
|
4
appInfo.js
Normal file
4
appInfo.js
Normal file
@@ -0,0 +1,4 @@
|
||||
const appName = "EZPPLauncher"
|
||||
const appVersion = "1.0.0";
|
||||
|
||||
module.exports = { appName, appVersion };
|
@@ -26,7 +26,6 @@ async function get(key, defaultValue) {
|
||||
}
|
||||
|
||||
async function set(key, value) {
|
||||
console.log("setting " + key + " to " + value);
|
||||
const configValues = new Map();
|
||||
const fileStream = await fs.promises.readFile(configLocation, "utf-8");
|
||||
const lines = fileStream.split(/\r?\n/)
|
||||
|
18
executeUtil.js
Normal file
18
executeUtil.js
Normal file
@@ -0,0 +1,18 @@
|
||||
const childProcess = require('child_process');
|
||||
module.exports = {
|
||||
runFile: (folder, file, args, onExit) => {
|
||||
childProcess.execFile(file, args, {
|
||||
cwd: folder
|
||||
}, (_err, _stdout, _stderr) => {
|
||||
onExit();
|
||||
});
|
||||
},
|
||||
runFileDetached: (folder, file, args) => {
|
||||
const subprocess = childProcess.spawn(file + " " + args, {
|
||||
cwd: folder,
|
||||
detached: true,
|
||||
stdio: 'ignore'
|
||||
})
|
||||
subprocess.unref()
|
||||
}
|
||||
}
|
@@ -40,7 +40,7 @@
|
||||
type="button" style="background-color:#d6016f" disabled>Looking for
|
||||
updates...</button>
|
||||
</div>
|
||||
<button class="btn btn-dark btn-sm float-start" id="account-btn">
|
||||
<button class="btn btn-dark btn-sm float-start" id="account-btn" disabled>
|
||||
set account
|
||||
</button>
|
||||
<button class="btn btn-dark btn-sm float-end" id="folder-btn">
|
||||
|
18
osuUtil.js
18
osuUtil.js
@@ -3,6 +3,7 @@ const fu = require('./fileUtil');
|
||||
const path = require('path');
|
||||
const crypto = require('crypto');
|
||||
const axios = require('axios').default;
|
||||
const executeUtil = require('./executeUtil');
|
||||
const { EventEmitter } = require('events');
|
||||
const { DownloaderHelper } = require('node-downloader-helper');
|
||||
|
||||
@@ -102,14 +103,14 @@ async function filesThatNeedUpdate(osuPath, updateFiles) {
|
||||
fileName,
|
||||
fileURL
|
||||
})
|
||||
console.log("hashes are not matching", `(${existingFileMD5} - ${fileHash})`);
|
||||
// console.log("hashes are not matching", `(${existingFileMD5} - ${fileHash})`);
|
||||
}
|
||||
} else {
|
||||
filesToDownload.push({
|
||||
fileName,
|
||||
fileURL
|
||||
});
|
||||
console.log("new file " + fileName);
|
||||
// console.log("new file " + fileName);
|
||||
}
|
||||
}
|
||||
return filesToDownload;
|
||||
@@ -120,7 +121,9 @@ async function downloadUpdateFiles(osuPath, filesToUpdate) {
|
||||
let completedIndex = 0;
|
||||
filesToUpdate.forEach(async (fileToUpdate) => {
|
||||
const filePath = path.join(osuPath, fileToUpdate.fileName);
|
||||
await fs.promises.rm(filePath);
|
||||
if (await fu.existsAsync(filePath))
|
||||
await fs.promises.rm(filePath);
|
||||
|
||||
const fileDownload = new DownloaderHelper(fileToUpdate.fileURL, osuPath, {
|
||||
fileName: fileToUpdate.fileName,
|
||||
override: true,
|
||||
@@ -137,4 +140,11 @@ async function downloadUpdateFiles(osuPath, filesToUpdate) {
|
||||
return eventEmitter;
|
||||
}
|
||||
|
||||
module.exports = { isValidOsuFolder, getLatestConfig, getUpdateFiles, filesThatNeedUpdate, downloadUpdateFiles }
|
||||
async function startWithDevServer(osuPath, serverDomain, onExit) {
|
||||
const osuExe = path.join(osuPath, "osu!.exe");
|
||||
if (!await fu.existsAsync(osuExe)) return false;
|
||||
executeUtil.runFile(osuPath, osuExe, ["-devserver", serverDomain], onExit);
|
||||
return true;
|
||||
}
|
||||
|
||||
module.exports = { isValidOsuFolder, getLatestConfig, getUpdateFiles, filesThatNeedUpdate, downloadUpdateFiles, startOsuWithDevServer: startWithDevServer }
|
@@ -3,6 +3,7 @@
|
||||
"version": "1.0.0",
|
||||
"main": "app.js",
|
||||
"license": "MIT",
|
||||
"author": "HorizonCode",
|
||||
"build": {
|
||||
"appId": "farm.ezpp.ezppfarm.launcher",
|
||||
"productName": "ezpplauncher",
|
||||
|
@@ -1,5 +1,6 @@
|
||||
const { ipcRenderer } = require('electron');
|
||||
const { Titlebar, Color } = require('custom-electron-titlebar');
|
||||
const appInfo = require('../appInfo');
|
||||
let titlebar;
|
||||
|
||||
window.addEventListener('DOMContentLoaded', () => {
|
||||
@@ -10,11 +11,41 @@ window.addEventListener('DOMContentLoaded', () => {
|
||||
maximizable: false
|
||||
});
|
||||
|
||||
titlebar.updateTitle("EZPPLauncher");
|
||||
titlebar.updateTitle(`${appInfo.appName} ${appInfo.appVersion}`);
|
||||
|
||||
const $ = require('jquery');
|
||||
const Swal = require('sweetalert2');
|
||||
|
||||
let currentState;
|
||||
|
||||
$("#launch-btn").on('click', async () => {
|
||||
switch (currentState) {
|
||||
case "up-to-date":
|
||||
$("#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...');
|
||||
}
|
||||
break;
|
||||
case "update-available":
|
||||
$("#launch-btn").attr('disabled', true);
|
||||
$('#launch-btn').html('Updating...');
|
||||
ipcRenderer.send("do-update");
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
$("#folder-btn").on('click', async () => {
|
||||
const success = await ipcRenderer.invoke('set-osu-dir');
|
||||
if (success == undefined)
|
||||
@@ -26,6 +57,7 @@ window.addEventListener('DOMContentLoaded', () => {
|
||||
icon: 'success',
|
||||
confirmButtonText: 'Cool'
|
||||
})
|
||||
ipcRenderer.send("do-update-check");
|
||||
} else {
|
||||
Swal.fire({
|
||||
title: 'Uh oh!',
|
||||
@@ -37,6 +69,7 @@ window.addEventListener('DOMContentLoaded', () => {
|
||||
});
|
||||
|
||||
ipcRenderer.on('status_update', (event, status) => {
|
||||
currentState = status.type;
|
||||
switch (status.type) {
|
||||
case "up-to-date":
|
||||
$("#launch-btn").attr('disabled', false);
|
||||
@@ -47,7 +80,26 @@ window.addEventListener('DOMContentLoaded', () => {
|
||||
$('#launch-btn').html('Update');
|
||||
break;
|
||||
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;
|
||||
}
|
||||
})
|
||||
|
||||
|
@@ -1,4 +1,5 @@
|
||||
const path = require("path");
|
||||
const appInfo = require('../appInfo');
|
||||
const { BrowserWindow } = require('electron');
|
||||
const { attachTitlebarToWindow } = require('custom-electron-titlebar/main');
|
||||
|
||||
@@ -31,11 +32,11 @@ module.exports = {
|
||||
window.show();
|
||||
});
|
||||
|
||||
window.webContents.setUserAgent("EZPPLauncher");
|
||||
window.webContents.setUserAgent(`${appInfo.appName} ${appInfo.appVersion}`);
|
||||
attachTitlebarToWindow(window);
|
||||
window.webContents.openDevTools({
|
||||
mode: "detach"
|
||||
});
|
||||
// window.webContents.openDevTools({
|
||||
// mode: "detach"
|
||||
// });
|
||||
|
||||
return window;
|
||||
},
|
||||
|
Reference in New Issue
Block a user