feat: add custom protocol for ezpplauncher

This commit is contained in:
HorizonCode 2025-05-14 11:46:41 +02:00
parent 084409a955
commit 9c1e958715
2 changed files with 38 additions and 13 deletions

41
main.js
View File

@ -1,5 +1,5 @@
// Modules to control application life and create native browser window // Modules to control application life and create native browser window
const { app, BrowserWindow, Menu, ipcMain, dialog, shell } = require( const { app, BrowserWindow, Menu, ipcMain, dialog, shell, protocol, session } = require(
"electron", "electron",
); );
@ -123,7 +123,7 @@ function startOsuStatus() {
lastOsuStatus = windowTitle; lastOsuStatus = windowTitle;
const currentStatusRequest = await fetch( const currentStatusRequest = await fetch(
"https://api.ez-pp.farm/v1/get_player_status?name=" + "https://api.ez-pp.farm/v1/get_player_status?name=" +
currentUser.username, currentUser.username,
{ {
headers: { headers: {
"User-Agent": "User-Agent":
@ -141,7 +141,7 @@ function startOsuStatus() {
const currentInfoRequest = await fetch( const currentInfoRequest = await fetch(
"https://api.ez-pp.farm/v1/get_player_info?name=" + "https://api.ez-pp.farm/v1/get_player_info?name=" +
currentUser.username + "&scope=all", currentUser.username + "&scope=all",
{ {
headers: { headers: {
"User-Agent": "User-Agent":
@ -554,9 +554,8 @@ function registerIPCPipes() {
progress: Math.ceil(data.progress), progress: Math.ceil(data.progress),
}); });
mainWindow.webContents.send("ezpplauncher:launchstatus", { mainWindow.webContents.send("ezpplauncher:launchstatus", {
status: `Downloading ${data.fileName}(${formatBytes(data.loaded)}/${ status: `Downloading ${data.fileName}(${formatBytes(data.loaded)}/${formatBytes(data.total)
formatBytes(data.total) })...`,
})...`,
}); });
}); });
await updateDownloader.startDownload(); await updateDownloader.startDownload();
@ -612,9 +611,8 @@ function registerIPCPipes() {
progress: Math.ceil(data.progress), progress: Math.ceil(data.progress),
}); });
mainWindow.webContents.send("ezpplauncher:launchstatus", { mainWindow.webContents.send("ezpplauncher:launchstatus", {
status: `Downloading ${data.fileName}(${ status: `Downloading ${data.fileName}(${formatBytes(data.loaded)
formatBytes(data.loaded) }/${formatBytes(data.total)})...`,
}/${formatBytes(data.total)})...`,
}); });
}); });
patcherDownloader.eventEmitter.on("delete", (data) => { patcherDownloader.eventEmitter.on("delete", (data) => {
@ -757,8 +755,7 @@ function registerIPCPipes() {
const osuGameplayFile = path.join(osuPath, "osu!gameplay.dll"); const osuGameplayFile = path.join(osuPath, "osu!gameplay.dll");
if (isWritable(osuUIFile) && isWritable(osuGameplayFile)) { if (isWritable(osuUIFile) && isWritable(osuGameplayFile)) {
logger.log( logger.log(
`Cleanup complete, took ${ `Cleanup complete, took ${((performance.now() - timeStart) / 1000).toFixed(3)
((performance.now() - timeStart) / 1000).toFixed(3)
} seconds.`, } seconds.`,
); );
clearInterval(cleanup); clearInterval(cleanup);
@ -789,7 +786,18 @@ function createWindow() {
app.quit(); app.quit();
return; return;
} }
app.on('second-instance', (e, argv) => {
if (process.platform !== 'darwin') {
// Find the arg that is our custom protocol url and store it
const deeplinkingUrl = argv.find((arg) => arg.startsWith('ezpplauncher://'));
console.log(deeplinkingUrl);
}
if (mainWindow) {
if (mainWindow.isMinimized()) mainWindow.restore();
mainWindow.focus();
}
});
setupTitlebar(); setupTitlebar();
// Create the browser window. // Create the browser window.
@ -870,7 +878,16 @@ function createWindow() {
// This method will be called when Electron has finished // This method will be called when Electron has finished
// initialization and is ready to create browser windows. // initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs. // Some APIs can only be used after this event occurs.
app.whenReady().then(createWindow) app.whenReady().then(() => {
createWindow();
if (isDev() && process.platform === 'win32') {
app.setAsDefaultProtocolClient('ezpplauncher', process.execPath, [
path.resolve(process.argv[1])
]);
} else {
app.setAsDefaultProtocolClient('ezpplauncher');
}
})
// Quit when all windows are closed. // Quit when all windows are closed.
app.on("window-all-closed", async function () { app.on("window-all-closed", async function () {

View File

@ -22,7 +22,15 @@
] ]
}, },
"linux": {}, "linux": {},
"mac": {} "mac": {},
"protocols": [
{
"name": "ezpplauncher",
"schemes": [
"ezpplauncher"
]
}
]
}, },
"scripts": { "scripts": {
"build": "rollup -c --bundleConfigAsCjs", "build": "rollup -c --bundleConfigAsCjs",