this repo has no description

Merge pull request #167 from moonlight-mod/notnite/moonbase-branch-switcher

moonbase branch switcher

Changed files
+39 -10
packages
core-extensions
src
+32 -5
packages/core-extensions/src/moonbase/host.ts
···
import * as fs from "node:fs/promises";
import * as path from "node:path";
import getNatives from "./native";
+
import { MoonlightBranch } from "@moonlight-mod/types";
const natives = getNatives();
···
if (i === -1) return original.call(this, entries);
if (!entries.find((e) => e.label === "moonlight")) {
+
const options: Electron.MenuItemConstructorOptions[] = [
+
{ label: "Update and restart", click: updateAndRestart },
+
{ label: "Reset config", click: resetConfig }
+
];
+
+
if (moonlightHost.branch !== MoonlightBranch.DEV) {
+
options.push({
+
label: "Switch branch",
+
submenu: [MoonlightBranch.STABLE, MoonlightBranch.NIGHTLY].map((branch) => ({
+
label: branch,
+
type: "radio",
+
checked: moonlightHost.branch === branch,
+
click: async () => {
+
if (moonlightHost.branch === branch) return;
+
if (!(await confirm("switch branches"))) return;
+
try {
+
await natives.updateMoonlight(branch);
+
await electron.dialog.showMessageBox({ message: "Branch switch successful, restarting Discord." });
+
electron.app.relaunch();
+
electron.app.exit(0);
+
} catch (e) {
+
await electron.dialog.showMessageBox({ message: "Failed to switch branches:\n" + e, type: "error" });
+
}
+
}
+
}))
+
});
+
}
+
+
options.push({ label: "About", click: showAbout });
+
entries.splice(i + 1, 0, {
label: "moonlight",
-
submenu: [
-
{ label: "Update and restart", click: updateAndRestart },
-
{ label: "Reset config", click: resetConfig },
-
{ label: "About", click: showAbout }
-
]
+
submenu: options
});
}
+5 -3
packages/core-extensions/src/moonbase/native.ts
···
}
},
-
async updateMoonlight() {
+
async updateMoonlight(overrideBranch?: MoonlightBranch) {
+
const branch = overrideBranch ?? moonlightGlobal.branch;
+
// Note: this won't do anything on browser, we should probably disable it
// entirely when running in browser.
async function downloadStable(): Promise<[ArrayBuffer, string]> {
···
}
const [tar, ref] =
-
moonlightGlobal.branch === MoonlightBranch.STABLE
+
branch === MoonlightBranch.STABLE
? await downloadStable()
-
: moonlightGlobal.branch === MoonlightBranch.NIGHTLY
+
: branch === MoonlightBranch.NIGHTLY
? await downloadNightly()
: [null, null];
+2 -2
packages/core-extensions/src/moonbase/types.ts
···
import { ExtensionCompat } from "@moonlight-mod/core/extension/loader";
-
import { DetectedExtension, ExtensionManifest } from "@moonlight-mod/types";
+
import { DetectedExtension, ExtensionManifest, MoonlightBranch } from "@moonlight-mod/types";
export type MoonbaseNatives = {
checkForMoonlightUpdate(): Promise<string | null>;
-
updateMoonlight(): Promise<void>;
+
updateMoonlight(overrideBranch?: MoonlightBranch): Promise<void>;
fetchRepositories(repos: string[]): Promise<Record<string, RepositoryManifest[]>>;
installExtension(manifest: RepositoryManifest, url: string, repo: string): Promise<void>;