titlebar fixes

This commit is contained in:
HorizonCode 2023-06-02 12:22:28 +02:00
parent fdfedab77f
commit cb1a05d58c
3 changed files with 244 additions and 240 deletions

3
app.js
View File

@ -1,5 +1,5 @@
const { app, BrowserWindow, ipcMain, dialog, Tray, Menu } = require('electron'); const { app, BrowserWindow, ipcMain, dialog, Tray, Menu } = require('electron');
const { setupTitlebar, attachTitlebarToWindow } = require('custom-electron-titlebar/main'); const { setupTitlebar } = require('custom-electron-titlebar/main');
const windowManager = require('./ui/windowManager'); const windowManager = require('./ui/windowManager');
const osuUtil = require('./osuUtil'); const osuUtil = require('./osuUtil');
const ezppUtil = require('./ezppUtil'); const ezppUtil = require('./ezppUtil');
@ -376,7 +376,6 @@ function createWindow() {
win.loadFile('./html/index.html'); win.loadFile('./html/index.html');
attachTitlebarToWindow(win);
win.webContents.setWindowOpenHandler(() => "deny"); win.webContents.setWindowOpenHandler(() => "deny");
win.webContents.on('did-finish-load', function () { win.webContents.on('did-finish-load', function () {
if (win.webContents.getZoomFactor() != 0.9) if (win.webContents.getZoomFactor() != 0.9)

View File

@ -1,256 +1,256 @@
const { ipcRenderer, shell } = require('electron'); const { ipcRenderer, shell } = require('electron');
const { Titlebar, Color } = require('custom-electron-titlebar'); const { Titlebar, TitlebarColor } = require('custom-electron-titlebar');
const appInfo = require('../appInfo'); const appInfo = require('../appInfo');
let titlebar;
let currentPage = "loading"; let currentPage = "loading";
let loggedIn = false; let loggedIn = false;
window.addEventListener('DOMContentLoaded', () => { window.addEventListener('DOMContentLoaded', () => {
titlebar = new Titlebar({ const titlebar = new Titlebar({
backgroundColor: Color.fromHex("#24283B"), backgroundColor: TitlebarColor.fromHex("#24283B"),
itemBackgroundColor: Color.fromHex("#121212"), itemBackgroundColor: TitlebarColor.fromHex("#121212"),
menu: null, menu: null,
maximizable: false enableMnemonics: false,
}); maximizable: false,
});
titlebar.updateTitle(`${appInfo.appName} ${appInfo.appVersion}`); titlebar.updateTitle(`${appInfo.appName} ${appInfo.appVersion}`);
const $ = require('jquery'); const $ = require('jquery');
const Swal = require('sweetalert2'); const Swal = require('sweetalert2');
$('#account-action').on('click', () => { $('#account-action').on('click', () => {
if (!loggedIn) { if (!loggedIn) {
changePage('login'); changePage('login');
} else {
$('#welcome-text').text(`Nice to see you!`);
$('#account-action').text('Click to login');
$('.user-image').css('background-image', `url(https://a.ez-pp.farm/0)`)
loggedIn = false;
ipcRenderer.send("perform-logout");
Swal.fire({
title: 'See ya soon!',
text: "Successfully logged out!",
icon: 'success',
confirmButtonText: 'Okay'
});
}
});
$('#action-cancel').on('click', () => {
if (!loggedIn) {
changePage('launch');
}
});
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 { } else {
$('#welcome-text').text(`Nice to see you!`); $("#launch-btn").attr('disabled', true);
$('#account-action').text('Click to login'); $('#launch-btn').html('Running...');
$('.user-image').css('background-image', `url(https://a.ez-pp.farm/0)`)
loggedIn = false;
ipcRenderer.send("perform-logout");
Swal.fire({
title: 'See ya soon!',
text: "Successfully logged out!",
icon: 'success',
confirmButtonText: 'Okay'
});
} }
}); break;
case "update-available":
$('#action-cancel').on('click', () => { $("#launch-btn").attr('disabled', true);
if (!loggedIn) { $('#launch-btn').html('Updating...');
changePage('launch'); ipcRenderer.send("do-update");
} break;
}); case "missing-folder":
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;
case "missing-folder":
const responseData = await ipcRenderer.invoke('set-osu-dir');
if (!responseData)
return;
if (responseData.validOsuDir) {
Swal.fire({
title: 'Success!',
text: 'osu! folder set.',
icon: 'success',
confirmButtonText: 'Cool'
})
$('#currentOsuPath').text(responseData.folderPath);
ipcRenderer.send("do-update-check");
} else {
Swal.fire({
title: 'Uh oh!',
text: 'The selected folder is not a osu! directory.',
icon: 'error',
confirmButtonText: 'Oops.. my bad!'
})
}
break;
}
});
$("#action-login").on('click', async () => {
const username = $('#login-username').val();
const password = $('#login-password').val();
$("#action-login").attr('disabled', true);
$("#action-cancel").attr('disabled', true);
const responseData = await ipcRenderer.invoke('perform-login', { username, password });
$("#action-login").attr('disabled', false);
$("#action-cancel").attr('disabled', false);
if (!responseData)
return;
if (responseData.code != 200) {
Swal.fire({
title: 'Uh oh!',
text: responseData.message,
icon: 'error',
confirmButtonText: 'Oops.. my bad!'
})
return;
}
$('#login-username').val("");
$('#login-password').val("");
$('#welcome-text').text(`Welcome back, ${responseData.user.name}!`);
$('#account-action').text('Not you?');
$('.user-image').css('background-image', `url(https://a.ez-pp.farm/${responseData.user.id})`);
loggedIn = true;
changePage('launch');
})
$("#change-folder-btn").on('click', async () => {
const responseData = await ipcRenderer.invoke('set-osu-dir'); const responseData = await ipcRenderer.invoke('set-osu-dir');
if (!responseData) if (!responseData)
return; return;
if (responseData.validOsuDir) { if (responseData.validOsuDir) {
Swal.fire({ Swal.fire({
title: 'Success!', title: 'Success!',
text: 'osu! folder set.', text: 'osu! folder set.',
icon: 'success', icon: 'success',
confirmButtonText: 'Cool' confirmButtonText: 'Cool'
}) })
$('#currentOsuPath').text(responseData.folderPath); $('#currentOsuPath').text(responseData.folderPath);
ipcRenderer.send("do-update-check"); ipcRenderer.send("do-update-check");
} else { } else {
Swal.fire({ Swal.fire({
title: 'Uh oh!', title: 'Uh oh!',
text: 'The selected folder is not a osu! directory.', text: 'The selected folder is not a osu! directory.',
icon: 'error', icon: 'error',
confirmButtonText: 'Oops.. my bad!' confirmButtonText: 'Oops.. my bad!'
}) })
} }
}); break;
ipcRenderer.on('config_update', (event, data) => {
if (data.osuPath) {
$('#currentOsuPath').text(data.osuPath);
}
})
ipcRenderer.on('launcher_update', async (event, data) => {
const res = await Swal.fire({
title: 'Update available!',
text: `Version ${data.version} has been released!`,
icon: 'info',
showCancelButton: true,
confirmButtonText: 'Download',
cancelButtonText: 'Remind me later',
});
if (res.isConfirmed) {
shell.openExternal(data.url);
}
})
ipcRenderer.on('account_update', (event, data) => {
switch (data.type) {
case "login-failed":
Swal.fire({
title: 'Uh oh!',
text: data.message,
icon: 'error',
confirmButtonText: 'Okay'
});
changePage("launch");
break;
case "not-loggedin":
changePage("launch");
break;
case "loggedin":
changePage("launch");
$('#welcome-text').text(`Welcome back, ${data.user.name}!`);
$('#account-action').text('Not you?');
$('.user-image').css('background-image', `url(https://a.ez-pp.farm/${data.user.id})`);
loggedIn = true;
break;
}
})
ipcRenderer.on('status_update', (event, status) => {
switch (status.type) {
case "up-to-date":
$("#launch-btn").attr('disabled', false);
$('#launch-btn').html('Launch');
currentState = status.type;
break;
case "update-available":
$("#launch-btn").attr('disabled', false);
$('#launch-btn').html('Update');
currentState = status.type;
break;
case "missing-folder":
$("#launch-btn").attr('disabled', false);
$('#launch-btn').html('set your osu! folder');
currentState = status.type;
break;
case "error":
Swal.fire({
title: 'Uh oh!',
text: status.message,
icon: 'error',
confirmButtonText: 'Okay'
});
ipcRenderer.send("do-update-check");
break;
case "info":
Swal.fire({
title: 'Info!',
text: status.message,
icon: 'info',
confirmButtonText: 'Okay'
});
break;
case "package-issue":
Swal.fire({
title: 'Uh oh!',
text: status.message,
icon: 'error',
confirmButtonText: 'Okay'
});
$("#launch-btn").attr('disabled', true);
$('#launch-btn').html('missing packages');
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;
}
})
function changePage(page) {
$(`#${currentPage}-page`).fadeOut(50, "swing", () => {
$(`#${page}-page`).fadeIn(350);
});
currentPage = page;
} }
});
// workaround for the dark theme $("#action-login").on('click', async () => {
$('head').append($('<link href="../assets/sweetalert2.dark.css" rel="stylesheet" />')); const username = $('#login-username').val();
const password = $('#login-password').val();
$("#action-login").attr('disabled', true);
$("#action-cancel").attr('disabled', true);
const responseData = await ipcRenderer.invoke('perform-login', { username, password });
$("#action-login").attr('disabled', false);
$("#action-cancel").attr('disabled', false);
if (!responseData)
return;
if (responseData.code != 200) {
Swal.fire({
title: 'Uh oh!',
text: responseData.message,
icon: 'error',
confirmButtonText: 'Oops.. my bad!'
})
return;
}
$('#login-username').val("");
$('#login-password').val("");
$('#welcome-text').text(`Welcome back, ${responseData.user.name}!`);
$('#account-action').text('Not you?');
$('.user-image').css('background-image', `url(https://a.ez-pp.farm/${responseData.user.id})`);
loggedIn = true;
changePage('launch');
})
$("#change-folder-btn").on('click', async () => {
const responseData = await ipcRenderer.invoke('set-osu-dir');
if (!responseData)
return;
if (responseData.validOsuDir) {
Swal.fire({
title: 'Success!',
text: 'osu! folder set.',
icon: 'success',
confirmButtonText: 'Cool'
})
$('#currentOsuPath').text(responseData.folderPath);
ipcRenderer.send("do-update-check");
} else {
Swal.fire({
title: 'Uh oh!',
text: 'The selected folder is not a osu! directory.',
icon: 'error',
confirmButtonText: 'Oops.. my bad!'
})
}
});
ipcRenderer.on('config_update', (event, data) => {
if (data.osuPath) {
$('#currentOsuPath').text(data.osuPath);
}
})
ipcRenderer.on('launcher_update', async (event, data) => {
const res = await Swal.fire({
title: 'Update available!',
text: `Version ${data.version} has been released!`,
icon: 'info',
showCancelButton: true,
confirmButtonText: 'Download',
cancelButtonText: 'Remind me later',
});
if (res.isConfirmed) {
shell.openExternal(data.url);
}
})
ipcRenderer.on('account_update', (event, data) => {
switch (data.type) {
case "login-failed":
Swal.fire({
title: 'Uh oh!',
text: data.message,
icon: 'error',
confirmButtonText: 'Okay'
});
changePage("launch");
break;
case "not-loggedin":
changePage("launch");
break;
case "loggedin":
changePage("launch");
$('#welcome-text').text(`Welcome back, ${data.user.name}!`);
$('#account-action').text('Not you?');
$('.user-image').css('background-image', `url(https://a.ez-pp.farm/${data.user.id})`);
loggedIn = true;
break;
}
})
ipcRenderer.on('status_update', (event, status) => {
switch (status.type) {
case "up-to-date":
$("#launch-btn").attr('disabled', false);
$('#launch-btn').html('Launch');
currentState = status.type;
break;
case "update-available":
$("#launch-btn").attr('disabled', false);
$('#launch-btn').html('Update');
currentState = status.type;
break;
case "missing-folder":
$("#launch-btn").attr('disabled', false);
$('#launch-btn').html('set your osu! folder');
currentState = status.type;
break;
case "error":
Swal.fire({
title: 'Uh oh!',
text: status.message,
icon: 'error',
confirmButtonText: 'Okay'
});
ipcRenderer.send("do-update-check");
break;
case "info":
Swal.fire({
title: 'Info!',
text: status.message,
icon: 'info',
confirmButtonText: 'Okay'
});
break;
case "package-issue":
Swal.fire({
title: 'Uh oh!',
text: status.message,
icon: 'error',
confirmButtonText: 'Okay'
});
$("#launch-btn").attr('disabled', true);
$('#launch-btn').html('missing packages');
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;
}
})
function changePage(page) {
$(`#${currentPage}-page`).fadeOut(50, "swing", () => {
$(`#${page}-page`).fadeIn(350);
});
currentPage = page;
}
// workaround for the dark theme
$('head').append($('<link href="../assets/sweetalert2.dark.css" rel="stylesheet" />'));
}) })

View File

@ -1,6 +1,6 @@
const path = require("path"); const path = require("path");
const appInfo = require('../appInfo'); const appInfo = require('../appInfo');
const { BrowserWindow } = require('electron'); const { BrowserWindow, Menu } = require('electron');
const { attachTitlebarToWindow } = require('custom-electron-titlebar/main'); const { attachTitlebarToWindow } = require('custom-electron-titlebar/main');
module.exports = { module.exports = {
@ -26,6 +26,10 @@ module.exports = {
}, },
icon: './assets/logo.png' icon: './assets/logo.png'
}) })
const menu = Menu.buildFromTemplate([])
Menu.setApplicationMenu(menu);
window.hide(); window.hide();
window.webContents.once("did-finish-load", function (event, input) { window.webContents.once("did-finish-load", function (event, input) {
@ -33,6 +37,7 @@ module.exports = {
}); });
window.webContents.setUserAgent(`${appInfo.appName} ${appInfo.appVersion}`); window.webContents.setUserAgent(`${appInfo.appName} ${appInfo.appVersion}`);
attachTitlebarToWindow(window); attachTitlebarToWindow(window);
return window; return window;