Files
gulp-haxetool/src/impl/ruffle.ts
T

69 lines
2.1 KiB
TypeScript
Executable File

import os from "os";
import path from "path";
import through from "through2";
import { Env } from "../common/env";
import { System } from "../common/system";
import { TailVinyl } from "../common/tail";
import run from "../run";
import { FlashPlayer } from "./flashplayer";
export class RufflePlayer extends FlashPlayer {
static ID = "ruffle";
static VERSION_2026_05_15 = "nightly-2026_05_15";
static VERSION = RufflePlayer.VERSION_2026_05_15;
BASE_URL = "https://github.com/ruffle-rs/ruffle/releases/download";
constructor(debug: boolean, version: string) {
super(debug, version || RufflePlayer.VERSION, RufflePlayer.ID);
this.baseUrl = Env.get("RUFFLE_URL") || this.BASE_URL;
}
get link(): string {
const baseUrl = `${this.baseUrl}/${this.version.replaceAll("_", "-")}`;
if (System.isWindows) {
return baseUrl + `/ruffle-${this.version}-windows-x86_64.zip`;
} else if (System.isLinux) {
return baseUrl + `/ruffle-${this.version}-linux-x86_64.tar.gz`;
} else {
throw `Unsupported os '${os.type()}'`;
}
}
get flashPlayerBin(): string {
if (System.isWindows) {
return path.join(this.path, "ruffle.exe");
} else if (System.isLinux) {
return path.join(this.path, "ruffle");
} else {
throw `Unsupported os '${os.type()}'`;
}
}
static get log(): string {
return path.join(os.homedir(), ".cache/ruffle/log/ruffle.log");
}
run(filename: string, params: any) {
this.log.i("_run_ *%s*", filename);
return run(`${this.flashPlayerBin} ${filename}`, params)
.exec()
.pipe(
through.obj(function (file: any, enc: string, callback: any) {
const log = new TailVinyl({
path: RufflePlayer.log,
handler: (line: string) => {
if (line.includes("avm_trace")) {
return line.split("avm_trace: ").pop();
}
},
});
this.on("end", () => log.dispose());
this.push(log);
callback();
}),
);
}
}