EZPPLauncher/app.js

72 lines
2.2 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", "");
if(fs.existsSync(osuPath)){
tempOsuPath = osuPath;
const osuConfig = await osuUtil.getLatestConfig(tempOsuPath);
console.log(osuConfig);
const lastVersion = await osuConfig.get("LastVersion");
console.log(lastVersion);
//Do update check
}
})
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 16:41:53 +00:00
const win = windowManager.createWindow(480, 350);
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();