EZPPLauncher/app.js

84 lines
2.9 KiB
JavaScript
Raw Normal View History

2022-10-16 13:54:29 +00:00
const { app, BrowserWindow, ipcMain, dialog } = require('electron');
const { setupTitlebar, attachTitlebarToWindow } = require('custom-electron-titlebar/main');
const windowManager = require('./ui/windowManager');
2022-10-16 14:47:31 +00:00
const osuUtil = require('./osuUtil');
2022-10-16 16:41:53 +00:00
const config = require('./config');
const fs = require('fs');
let tempOsuPath;
2022-10-16 13:54:29 +00:00
const run = () => {
const gotTheLock = app.requestSingleInstanceLock()
if (!gotTheLock) {
app.quit();
return;
}
2022-10-16 16:41:53 +00:00
2022-10-16 13:54:29 +00:00
setupTitlebar();
let mainWindow;
app.whenReady().then(() => {
2022-10-16 16:41:53 +00:00
mainWindow = createWindow();
mainWindow.on('show', async () => {
const osuPath = await config.get("osuPath", "");
2022-10-16 16:52:34 +00:00
if (fs.existsSync(osuPath)) {
2022-10-16 16:41:53 +00:00
tempOsuPath = osuPath;
const osuConfig = await osuUtil.getLatestConfig(tempOsuPath);
const lastVersion = await osuConfig.get("LastVersion");
2022-10-16 16:52:34 +00:00
let releaseStream = "stable40";
if (lastVersion.endsWith("cuttingedge"))
releaseStream = "cuttingedge"
else if (lastVersion.endsWith("beta"))
releaseStream = "beta";
2022-10-16 19:13:30 +00:00
2022-10-16 16:52:34 +00:00
const releaseFiles = await osuUtil.getUpdateFiles(releaseStream);
2022-10-16 19:13:30 +00:00
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"
})
2022-10-16 16:41:53 +00:00
}
})
2022-10-16 13:54:29 +00:00
app.on('activate', function () {
if (BrowserWindow.getAllWindows().length === 0) mainWindow = createWindow();
})
app.on('window-all-closed', () => {
app.quit()
})
2022-10-16 14:47:31 +00:00
ipcMain.handle('set-osu-dir', async (event) => {
2022-10-16 13:54:29 +00:00
const yes = await dialog.showOpenDialog({
properties: ['openDirectory']
})
2022-10-16 14:47:31 +00:00
if (yes.filePaths.length <= 0)
return undefined;
const folderPath = yes.filePaths[0];
2022-10-16 16:41:53 +00:00
const validOsuDir = osuUtil.isValidOsuFolder(folderPath);
if (validOsuDir) await config.set("osuPath", folderPath);
return validOsuDir;
2022-10-16 13:54:29 +00:00
})
})
}
function createWindow() {
// Create the browser window.
2022-10-16 19:31:05 +00:00
const win = windowManager.createWindow(520, 420);
2022-10-16 13:54:29 +00:00
win.loadFile('./html/index.html');
attachTitlebarToWindow(win);
win.webContents.setWindowOpenHandler(() => "deny");
2022-10-16 13:54:29 +00:00
win.webContents.on('did-finish-load', function () {
if (win.webContents.getZoomFactor() != 0.9)
win.webContents.setZoomFactor(0.9)
});
return win;
}
run();