From c6fdc4531e1a22208710f2b689911f8ad1a2d0bb Mon Sep 17 00:00:00 2001 From: Jas Laferriere Date: Wed, 14 Sep 2022 21:32:04 -0400 Subject: [PATCH 1/2] feat: add handler for uri slippi://update --- release/app/package.json | 2 +- src/main/main.ts | 64 ++++++++++++++++++++++++---------------- 2 files changed, 39 insertions(+), 27 deletions(-) diff --git a/release/app/package.json b/release/app/package.json index 4312b85e6..92535b88f 100644 --- a/release/app/package.json +++ b/release/app/package.json @@ -2,7 +2,7 @@ "name": "slippi-launcher", "productName": "Slippi Launcher", "description": "Launch Slippi Online, browse and watch saved replays", - "version": "2.5.6", + "version": "2.5.7-beta.1", "main": "./dist/main/main.js", "author": { "name": "Jas Laferriere", diff --git a/src/main/main.ts b/src/main/main.ts index f349a7088..ed933e82c 100644 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -177,6 +177,35 @@ const waitForMainWindow = async () => { log.info(`Found mainWindow after ${retryIdx} tries.`); }; +const launchCloudReplay = async (replayPathIn: string) => { + let replayPath = replayPathIn; + if (!replayPath) { + return; + } + // For some reason the file refuses to download if it's prefixed with "/" + if (replayPath[0] === "/") { + replayPath = replayPath.slice(1); + } + + const tmpDir = path.join(app.getPath("userData"), "temp"); + await fs.ensureDir(tmpDir); + const destination = path.join(tmpDir, path.basename(replayPath)); + + const fileAlreadyExists = await fileExists(destination); + if (!fileAlreadyExists) { + const dlUrl = replayPath.startsWith("http") + ? replayPath + : `https://storage.googleapis.com/slippi.appspot.com/${replayPath}`; + log.info(`Downloading file ${replayPath} to ${destination}`); + // Dowload file + await download({ url: dlUrl, destinationFile: destination, overwrite: true }); + log.info(`Finished download`); + } else { + log.info(`${destination} already exists. Skipping download...`); + } + await playReplayAndShowStats(destination); +}; + const handleSlippiURIAsync = async (aUrl: string) => { log.info("Handling URL..."); log.info(aUrl); @@ -184,8 +213,9 @@ const handleSlippiURIAsync = async (aUrl: string) => { // Check if the input is // Specifying a base will provide sane defaults if the input is null or wrong const myUrl = new url.URL(aUrl, `null://null`); + const hostname = myUrl.hostname; let protocol = myUrl.protocol; - log.info(`protocol: ${myUrl.protocol}, hostname: ${myUrl.hostname}`); + log.info(`protocol: ${myUrl.protocol}, hostname: ${hostname}`); if (myUrl.protocol !== `${slippiProtocol}:`) { if (await fileExists(aUrl)) { log.info(`File ${aUrl} exists`); @@ -207,32 +237,14 @@ const handleSlippiURIAsync = async (aUrl: string) => { switch (protocol) { case "slippi:": { - let replayPath = myUrl.searchParams.get("path"); - if (!replayPath) { - return; - } - // For some reason the file refuses to download if it's prefixed with "/" - if (replayPath[0] === "/") { - replayPath = replayPath.slice(1); - } - - const tmpDir = path.join(app.getPath("userData"), "temp"); - await fs.ensureDir(tmpDir); - const destination = path.join(tmpDir, path.basename(replayPath)); - - const fileAlreadyExists = await fileExists(destination); - if (!fileAlreadyExists) { - const dlUrl = replayPath.startsWith("http") - ? replayPath - : `https://storage.googleapis.com/slippi.appspot.com/${replayPath}`; - log.info(`Downloading file ${replayPath} to ${destination}`); - // Dowload file - await download({ url: dlUrl, destinationFile: destination, overwrite: true }); - log.info(`Finished download`); - } else { - log.info(`${destination} already exists. Skipping download...`); + switch (hostname) { + case "play": + await launchCloudReplay(myUrl.searchParams.get("path") ?? ""); + break; + case "update": + await dolphinManager.installDolphin(DolphinLaunchType.NETPLAY); + break; } - await playReplayAndShowStats(destination); break; } case "file:": { From 9c7de8d9b2404e723296d734f42dbbe57f25d4af Mon Sep 17 00:00:00 2001 From: Jas Laferriere Date: Tue, 18 Oct 2022 15:18:26 -0400 Subject: [PATCH 2/2] feat: add code to kill running dolphin I remember this having problems... don't remember atm --- src/dolphin/instance.ts | 4 ++++ src/dolphin/manager.ts | 8 ++++++++ src/main/main.ts | 12 ++++++++++-- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/dolphin/instance.ts b/src/dolphin/instance.ts index 05ae09527..2e6655124 100644 --- a/src/dolphin/instance.ts +++ b/src/dolphin/instance.ts @@ -74,6 +74,10 @@ export class DolphinInstance extends EventEmitter { this.emit("error", err); }); } + + public async stop() { + this.process?.kill(); + } } export class PlaybackDolphinInstance extends DolphinInstance { diff --git a/src/dolphin/manager.ts b/src/dolphin/manager.ts index 3017f68b5..e21221ad3 100644 --- a/src/dolphin/manager.ts +++ b/src/dolphin/manager.ts @@ -26,6 +26,14 @@ export class DolphinManager { return new DolphinInstallation(launchType, dolphinPath); } + public async killNetplayDolphin(): Promise { + if (!this.netplayDolphinInstance) { + return; + } + + await this.netplayDolphinInstance.stop(); + } + public async installDolphin(dolphinType: DolphinLaunchType): Promise { const dolphinInstall = this.getInstallation(dolphinType); await dolphinInstall.validate({ diff --git a/src/main/main.ts b/src/main/main.ts index ed933e82c..c191c850c 100644 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -206,6 +206,13 @@ const launchCloudReplay = async (replayPathIn: string) => { await playReplayAndShowStats(destination); }; +const updateNetplayDolphin = async () => { + const sub = dolphinManager.events.subscribe((evt) => log.info(evt)); + await dolphinManager.killNetplayDolphin(); + await dolphinManager.installDolphin(DolphinLaunchType.NETPLAY); + sub.unsubscribe(); +}; + const handleSlippiURIAsync = async (aUrl: string) => { log.info("Handling URL..."); log.info(aUrl); @@ -241,9 +248,10 @@ const handleSlippiURIAsync = async (aUrl: string) => { case "play": await launchCloudReplay(myUrl.searchParams.get("path") ?? ""); break; - case "update": - await dolphinManager.installDolphin(DolphinLaunchType.NETPLAY); + case "update": { + await updateNetplayDolphin(); break; + } } break; }