Merge pull request #167 from moonlight-mod/notnite/moonbase-branch-switcher
moonbase branch switcher
Cynthia Foxwell 1 month ago 3 files (+39, -10)
@@ -2,6 +2,7 @@ import * as electron from "electron";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();@@ -64,13 +65,39 @@ const i = entries.findIndex((e) => e.label === "Check for Updates...");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});}
@@ -58,7 +58,9 @@ return null;}},- 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]> {@@ -98,9 +100,9 @@ return [await zipReq.arrayBuffer(), ref];}const [tar, ref] =- moonlightGlobal.branch === MoonlightBranch.STABLE+ branch === MoonlightBranch.STABLE? await downloadStable()- : moonlightGlobal.branch === MoonlightBranch.NIGHTLY+ : branch === MoonlightBranch.NIGHTLY? await downloadNightly(): [null, null];
@@ -1,9 +1,9 @@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>;