Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] [PR] Handle netplay Dolphin update via URI #340

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion release/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 4 additions & 0 deletions src/dolphin/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ export class DolphinInstance extends EventEmitter {
this.emit("error", err);
});
}

public async stop() {
this.process?.kill();
}
}

export class PlaybackDolphinInstance extends DolphinInstance {
Expand Down
8 changes: 8 additions & 0 deletions src/dolphin/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ export class DolphinManager {
return new DolphinInstallation(launchType, dolphinPath);
}

public async killNetplayDolphin(): Promise<void> {
if (!this.netplayDolphinInstance) {
return;
}

await this.netplayDolphinInstance.stop();
}

public async installDolphin(dolphinType: DolphinLaunchType): Promise<void> {
const dolphinInstall = this.getInstallation(dolphinType);
await dolphinInstall.validate({
Expand Down
72 changes: 46 additions & 26 deletions src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,52 @@ 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 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);

// 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`);
Expand All @@ -207,32 +244,15 @@ 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 updateNetplayDolphin();
break;
}
}
await playReplayAndShowStats(destination);
break;
}
case "file:": {
Expand Down