From 9c1e9587159f0b22cad307a589eb528f4c13b978 Mon Sep 17 00:00:00 2001 From: HorizonCode Date: Wed, 14 May 2025 11:46:41 +0200 Subject: [PATCH] feat: add custom protocol for ezpplauncher --- main.js | 41 +++++++++++++++++++++++++++++------------ package.json | 10 +++++++++- 2 files changed, 38 insertions(+), 13 deletions(-) diff --git a/main.js b/main.js index 5ef5af5..727bab4 100644 --- a/main.js +++ b/main.js @@ -1,5 +1,5 @@ // 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", ); @@ -123,7 +123,7 @@ function startOsuStatus() { lastOsuStatus = windowTitle; const currentStatusRequest = await fetch( "https://api.ez-pp.farm/v1/get_player_status?name=" + - currentUser.username, + currentUser.username, { headers: { "User-Agent": @@ -141,7 +141,7 @@ function startOsuStatus() { const currentInfoRequest = await fetch( "https://api.ez-pp.farm/v1/get_player_info?name=" + - currentUser.username + "&scope=all", + currentUser.username + "&scope=all", { headers: { "User-Agent": @@ -554,9 +554,8 @@ function registerIPCPipes() { progress: Math.ceil(data.progress), }); mainWindow.webContents.send("ezpplauncher:launchstatus", { - status: `Downloading ${data.fileName}(${formatBytes(data.loaded)}/${ - formatBytes(data.total) - })...`, + status: `Downloading ${data.fileName}(${formatBytes(data.loaded)}/${formatBytes(data.total) + })...`, }); }); await updateDownloader.startDownload(); @@ -612,9 +611,8 @@ function registerIPCPipes() { progress: Math.ceil(data.progress), }); mainWindow.webContents.send("ezpplauncher:launchstatus", { - status: `Downloading ${data.fileName}(${ - formatBytes(data.loaded) - }/${formatBytes(data.total)})...`, + status: `Downloading ${data.fileName}(${formatBytes(data.loaded) + }/${formatBytes(data.total)})...`, }); }); patcherDownloader.eventEmitter.on("delete", (data) => { @@ -757,8 +755,7 @@ function registerIPCPipes() { const osuGameplayFile = path.join(osuPath, "osu!gameplay.dll"); if (isWritable(osuUIFile) && isWritable(osuGameplayFile)) { logger.log( - `Cleanup complete, took ${ - ((performance.now() - timeStart) / 1000).toFixed(3) + `Cleanup complete, took ${((performance.now() - timeStart) / 1000).toFixed(3) } seconds.`, ); clearInterval(cleanup); @@ -789,7 +786,18 @@ function createWindow() { app.quit(); 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(); // Create the browser window. @@ -870,7 +878,16 @@ function createWindow() { // This method will be called when Electron has finished // initialization and is ready to create browser windows. // 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. app.on("window-all-closed", async function () { diff --git a/package.json b/package.json index 41cdfcb..4192467 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,15 @@ ] }, "linux": {}, - "mac": {} + "mac": {}, + "protocols": [ + { + "name": "ezpplauncher", + "schemes": [ + "ezpplauncher" + ] + } + ] }, "scripts": { "build": "rollup -c --bundleConfigAsCjs",