this repo has no description

Merge branch 'develop' into lunast

Changed files
+54
packages
core
injector
src
+49
packages/core/src/persist.ts
···
+
import { join, dirname } from "node:path";
+
import {
+
mkdirSync,
+
renameSync,
+
existsSync,
+
copyFileSync,
+
readdirSync
+
} from "node:fs";
+
import Logger from "./util/logger";
+
+
const logger = new Logger("core/persist");
+
+
export default function persist(asarPath: string) {
+
const updaterModule = require(join(asarPath, "common", "updater"));
+
const updater = updaterModule.Updater;
+
+
const currentAppDir = join(dirname(asarPath), "app");
+
+
const realEmit = updater.prototype.emit;
+
updater.prototype.emit = function (event: string, ...args: any[]) {
+
if (event === "host-updated") {
+
const versions = this.queryCurrentVersionsSync();
+
+
const newRootDir = join(
+
this.rootPath,
+
"app-" +
+
versions.current_host.map((v: number) => v.toString()).join(".")
+
);
+
logger.info(`Persisting moonlight - new root dir: ${newRootDir}`);
+
+
const newResources = join(newRootDir, "resources");
+
+
// app.asar -> _app.asar
+
const newAsar = join(newResources, "app.asar");
+
const newRenamedAsar = join(newResources, "_app.asar");
+
if (!existsSync(newRenamedAsar)) renameSync(newAsar, newRenamedAsar);
+
+
// copy the already existing app dir so we don't have to figure out the moonlight dir
+
const newAppDir = join(newResources, "app");
+
if (!existsSync(newAppDir)) mkdirSync(newAppDir);
+
+
for (const file of readdirSync(currentAppDir)) {
+
copyFileSync(join(currentAppDir, file), join(newAppDir, file));
+
}
+
}
+
+
return realEmit.call(this, event, ...args);
+
};
+
}
+5
packages/injector/src/index.ts
···
} from "@moonlight-mod/core/extension/loader";
import EventEmitter from "node:events";
import { join, resolve } from "node:path";
+
import persist from "@moonlight-mod/core/persist";
const logger = new Logger("injector");
···
}
if (isMoonlightDesktop) return;
+
+
if (!hasOpenAsar && !isMoonlightDesktop) {
+
persist(asarPath);
+
}
// Need to do this instead of require() or it breaks require.main
// @ts-expect-error Module internals