feat: Implemented download page for downloading roms from various sources using plugins. Added support for internet archive external plugin. feat: Added tasks page to track running tasks/downloads feat: Added tanstack caching feat: Added quick play action Fixes #6 feat: Added quick emulator launch action fix: Made task queue only support 1 task per group and task ID should now be unique
104 lines
No EOL
2.5 KiB
TypeScript
104 lines
No EOL
2.5 KiB
TypeScript
import EventEmitter from "events";
|
|
import browser from '../src/bun/browser';
|
|
import { tmpdir } from "os";
|
|
import path from "path";
|
|
import { watch } from "fs";
|
|
import { sleep } from "bun";
|
|
const events = new EventEmitter();
|
|
const abortController = new AbortController();
|
|
let restarting = false;
|
|
|
|
process.env.WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS = "--remote-debugging-port=9222";
|
|
process.env.NODE_ENV = "development";
|
|
|
|
function spawnServer ()
|
|
{
|
|
const s = Bun.spawn(["bun", '--install=fallback', "run", "--inspect=127.0.0.1:9228/fixed-session", "./src/bun/index.ts"], {
|
|
env: {
|
|
...process.env,
|
|
HEADLESS: "true",
|
|
},
|
|
stdout: 'inherit',
|
|
stderr: 'inherit',
|
|
stdin: 'inherit',
|
|
signal: abortController.signal,
|
|
killSignal: 'SIGKILL',
|
|
ipc (message, subprocess, handle)
|
|
{
|
|
if (message === 'focus')
|
|
{
|
|
events.emit('focus');
|
|
} else if (message === 'exitapp')
|
|
{
|
|
events.emit('exitapp');
|
|
}
|
|
},
|
|
onExit (subprocess, exitCode, signalCode)
|
|
{
|
|
if (!restarting)
|
|
{
|
|
console.log("Existing Dev With", exitCode);
|
|
process.exit();
|
|
}
|
|
}
|
|
});
|
|
return s;
|
|
}
|
|
|
|
function spawnBrowser ()
|
|
{
|
|
try
|
|
{
|
|
|
|
return browser(events, {
|
|
configPath: path.join(tmpdir(), 'gameflow'),
|
|
isSteamDeckGameMode: false,
|
|
forceBrowser: process.env.FORCE_BROWSER === "true"
|
|
});
|
|
} catch (error)
|
|
{
|
|
console.error(error);
|
|
};
|
|
}
|
|
|
|
async function restart ()
|
|
{
|
|
if (server)
|
|
{
|
|
restarting = true;
|
|
server.kill();
|
|
await server.exited;
|
|
server = undefined;
|
|
console.log("Old Server stopped");
|
|
}
|
|
|
|
server = spawnServer();
|
|
await sleep(1000);
|
|
console.log("New Server started");
|
|
restarting = false;
|
|
}
|
|
|
|
watch("./src/bun", { recursive: true }, (event, filename) =>
|
|
{
|
|
if (restarting) return;
|
|
console.log(`[watcher] ${event}: ${filename} — restarting...`);
|
|
restart();
|
|
});
|
|
|
|
watch("./src/packages", { recursive: true }, (event, filename) =>
|
|
{
|
|
if (restarting) return;
|
|
console.log(`[watcher] ${event}: ${filename} — restarting...`);
|
|
restart();
|
|
});
|
|
|
|
let server: Bun.Subprocess | undefined = spawnServer();
|
|
if (!process.env.HEADLESS)
|
|
{
|
|
spawnBrowser()?.then(async e =>
|
|
{
|
|
if (!server) return;
|
|
abortController.abort();
|
|
await server.exited;
|
|
});
|
|
} |