feat: add custom protocol for ezpplauncher
This commit is contained in:
parent
084409a955
commit
9c1e958715
41
main.js
41
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 () {
|
||||
|
10
package.json
10
package.json
@ -22,7 +22,15 @@
|
||||
]
|
||||
},
|
||||
"linux": {},
|
||||
"mac": {}
|
||||
"mac": {},
|
||||
"protocols": [
|
||||
{
|
||||
"name": "ezpplauncher",
|
||||
"schemes": [
|
||||
"ezpplauncher"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"scripts": {
|
||||
"build": "rollup -c --bundleConfigAsCjs",
|
||||
|
Loading…
x
Reference in New Issue
Block a user