2 Commits

3 changed files with 51 additions and 27 deletions

View File

@@ -34,23 +34,22 @@ module.exports = {
if (!richPresence) {
richPresence = new DiscordRPC.AutoClient({ transport: "ipc" });
richPresence.endlessLogin({ clientId });
richPresence.once("ready", () => {
richPresence.once("ready", async () => {
console.log(
"connected presence with user " + richPresence.user.username,
);
richPresence.setActivity(currentStatus);
intervalId = setInterval(() => {
richPresence.setActivity(currentStatus);
}, 2500);
await richPresence.setActivity(currentStatus);
intervalId = setInterval(() => richPresence.setActivity(currentStatus), 2500);
});
}
},
disconnect: async () => {
if (richPresence) {
clearInterval(intervalId);
await richPresence.clearActivity();
await richPresence.destroy();
const presence = richPresence;
richPresence = null;
clearInterval(intervalId);
await presence.clearActivity();
await presence.destroy();
}
},
updateStatus: ({ state, details, largeImageKey }) => {
@@ -62,9 +61,9 @@ module.exports = {
currentStatus.smallImageKey = id ? `https://a.ez-pp.farm/${id}` : " ";
currentStatus.smallImageText = username ?? " ";
},
update: () => {
update: async () => {
if (richPresence && richPresence.user) {
richPresence.setActivity(currentStatus);
await richPresence.setActivity(currentStatus);
}
},
hasPresence: () => richPresence != undefined,

49
main.js
View File

@@ -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",
);
@@ -98,7 +98,7 @@ function startOsuStatus() {
id,
username,
});
richPresence.update();
await richPresence.update();
}
}
} catch {
@@ -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":
@@ -235,7 +235,7 @@ function startOsuStatus() {
largeImageKey,
});
richPresence.update();
await richPresence.update();
}
}, 2500);
}
@@ -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) => {
@@ -732,7 +730,7 @@ function registerIPCPipes() {
logger.log("Launching osu!...");
const onExitHook = () => {
const onExitHook = async () => {
logger.log("osu! has exited.");
mainWindow.show();
mainWindow.focus();
@@ -745,7 +743,7 @@ function registerIPCPipes() {
state: "Idle in Launcher...",
details: undefined,
});
richPresence.update();
await richPresence.update();
mainWindow.webContents.send("ezpplauncher:launchstatus", {
status: "Waiting for cleanup...",
});
@@ -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 () {

View File

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