Skip to content

Commit d36b46b

Browse files
committed
feat: add release branch settings
1 parent 4fb3912 commit d36b46b

File tree

6 files changed

+136
-7
lines changed

6 files changed

+136
-7
lines changed

i18n/en-US.messages.d.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1684,6 +1684,58 @@ export declare const messages: {
16841684
* Missing translations: `bg`, `da`, `el`, `es-419`, `hi`, `hr`, `hu`, `ko`, `lt`, `nl`, `no`, `ro`, `sv-SE`, `th`
16851685
*/
16861686
'REPLUGGED_SETTINGS_REACT_DEVTOOLS_FAILED': TypedIntlMessageGetter<{}>,
1687+
/**
1688+
* Key: `8XW5yc`
1689+
*
1690+
* ### Definition
1691+
* ```text
1692+
* Release Branch
1693+
* ```
1694+
*
1695+
* ### Problems
1696+
*
1697+
* Missing translations: `bg`, `cs`, `da`, `de`, `el`, `en-GB`, `es-419`, `es-ES`, `fi`, `fr`, `hi`, `hr`, `hu`, `it`, `ja`, `ko`, `lt`, `nl`, `no`, `pl`, `pt-BR`, `ro`, `ru`, `sv-SE`, `th`, `tr`, `uk`, `vi`, `zh-CN`, `zh-TW`
1698+
*/
1699+
'REPLUGGED_SETTINGS_RELEASE_BRANCH': TypedIntlMessageGetter<{}>,
1700+
/**
1701+
* Key: `mk6xTE`
1702+
*
1703+
* ### Definition
1704+
* ```text
1705+
* Stable will give you the officially tested and reliable version, while Nightly provides the latest changes and features directly from the github, which may be less stable.
1706+
* ```
1707+
*
1708+
* ### Problems
1709+
*
1710+
* Missing translations: `bg`, `cs`, `da`, `de`, `el`, `en-GB`, `es-419`, `es-ES`, `fi`, `fr`, `hi`, `hr`, `hu`, `it`, `ja`, `ko`, `lt`, `nl`, `no`, `pl`, `pt-BR`, `ro`, `ru`, `sv-SE`, `th`, `tr`, `uk`, `vi`, `zh-CN`, `zh-TW`
1711+
*/
1712+
'REPLUGGED_SETTINGS_RELEASE_BRANCH_DESC': TypedIntlMessageGetter<{}>,
1713+
/**
1714+
* Key: `qkh2nZ`
1715+
*
1716+
* ### Definition
1717+
* ```text
1718+
* Nightly
1719+
* ```
1720+
*
1721+
* ### Problems
1722+
*
1723+
* Missing translations: `bg`, `cs`, `da`, `de`, `el`, `en-GB`, `es-419`, `es-ES`, `fi`, `fr`, `hi`, `hr`, `hu`, `it`, `ja`, `ko`, `lt`, `nl`, `no`, `pl`, `pt-BR`, `ro`, `ru`, `sv-SE`, `th`, `tr`, `uk`, `vi`, `zh-CN`, `zh-TW`
1724+
*/
1725+
'REPLUGGED_SETTINGS_RELEASE_BRANCH_NIGHTLY': TypedIntlMessageGetter<{}>,
1726+
/**
1727+
* Key: `g9f/7e`
1728+
*
1729+
* ### Definition
1730+
* ```text
1731+
* Stable
1732+
* ```
1733+
*
1734+
* ### Problems
1735+
*
1736+
* Missing translations: `bg`, `cs`, `da`, `de`, `el`, `en-GB`, `es-419`, `es-ES`, `fi`, `fr`, `hi`, `hr`, `hu`, `it`, `ja`, `ko`, `lt`, `nl`, `no`, `pl`, `pt-BR`, `ro`, `ru`, `sv-SE`, `th`, `tr`, `uk`, `vi`, `zh-CN`, `zh-TW`
1737+
*/
1738+
'REPLUGGED_SETTINGS_RELEASE_BRANCH_STABLE': TypedIntlMessageGetter<{}>,
16871739
/**
16881740
* Key: `LBwcjY`
16891741
*

i18n/en-US.messages.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,5 +209,9 @@ export default defineMessages({
209209
"REPLUGGED_SETTINGS_DISABLE_MIN_SIZE_DESC": "Remove Discord's minimum window size restrictions. **Requires restart**.",
210210
"REPLUGGED_SETTINGS_WIN_UPDATER": "Keep Replugged After Updates",
211211
"REPLUGGED_SETTINGS_WIN_UPDATER_DESC": "Automatically reapplies Replugged after Discord updates.",
212-
"REPLUGGED_SETTINGS_DEVELOPMENT_TOOLS": "Development Tools"
213-
});
212+
"REPLUGGED_SETTINGS_DEVELOPMENT_TOOLS": "Development Tools",
213+
"REPLUGGED_SETTINGS_RELEASE_BRANCH": "Release Branch",
214+
"REPLUGGED_SETTINGS_RELEASE_BRANCH_DESC": "Stable will give you the officially tested and reliable version, while Nightly provides the latest changes and features directly from the github, which may be less stable.",
215+
"REPLUGGED_SETTINGS_RELEASE_BRANCH_STABLE": "Stable",
216+
"REPLUGGED_SETTINGS_RELEASE_BRANCH_NIGHTLY": "Nightly",
217+
});

src/main/index.ts

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@ import { dirname, join } from "path";
33
import { CONFIG_PATHS } from "src/util.mjs";
44
import type { PackageJson } from "type-fest";
55
import { pathToFileURL } from "url";
6-
import type { BackgroundMaterialType, RepluggedWebContents, VibrancyType } from "../types";
6+
import {
7+
type BackgroundMaterialType,
8+
RepluggedBranchs,
9+
type RepluggedWebContents,
10+
type VibrancyType,
11+
} from "../types";
712
import { getAddonInfo, getRepluggedVersion, installAddon } from "./ipc/installer";
8-
import { getAllSettings, getSetting } from "./ipc/settings";
13+
import { getAllSettings, getSetting, writeTransaction } from "./ipc/settings";
914
import patchAutoStartUpdate from "./winUpdaterPatch";
1015

1116
const electronPath = require.resolve("electron");
@@ -122,6 +127,10 @@ protocol.registerSchemesAsPrivileged = (customSchemes: Electron.CustomScheme[])
122127
// Monkey patch to add our menu items into the tray context menu
123128
const originalBuildFromTemplate = Menu.buildFromTemplate.bind(Menu);
124129

130+
async function confirm(title: string, message: string): Promise<Electron.MessageBoxReturnValue> {
131+
return dialog.showMessageBox({ type: "question", title, message, buttons: ["OK", "Cancel"] });
132+
}
133+
125134
async function showInfo(title: string, message: string): Promise<Electron.MessageBoxReturnValue> {
126135
return dialog.showMessageBox({ type: "info", title, message, buttons: ["Ok"] });
127136
}
@@ -132,8 +141,8 @@ async function showError(title: string, message: string): Promise<Electron.Messa
132141
Menu.buildFromTemplate = (items: Electron.MenuItemConstructorOptions[]) => {
133142
if (items[0]?.label !== "Discord" || items.some((e) => e.label === "Replugged"))
134143
return originalBuildFromTemplate(items);
135-
136144
const currentVersion = getRepluggedVersion();
145+
const currentBranch = getSetting("dev.replugged.Settings", "branch", RepluggedBranchs.STABLE);
137146

138147
const repluggedMenuItems: Electron.MenuItemConstructorOptions = {
139148
label: "Replugged",
@@ -213,6 +222,47 @@ Menu.buildFromTemplate = (items: Electron.MenuItemConstructorOptions[]) => {
213222
}
214223
},
215224
},
225+
{
226+
label: "Release Branch",
227+
submenu: Object.values(RepluggedBranchs).map((value) => {
228+
const label = RepluggedBranchs.STABLE === value ? "Stable" : "Nightly";
229+
return {
230+
label,
231+
type: "radio",
232+
233+
checked: currentBranch === value,
234+
235+
onClick: async (): Promise<void> => {
236+
if (currentBranch === value) return;
237+
const response = await confirm(
238+
"Change Branch?",
239+
`Are you sure you want to change release branch to ${label}?`,
240+
);
241+
if (response.response !== 0) return;
242+
243+
try {
244+
writeTransaction("dev.replugged.Settings", (settings) =>
245+
settings.set("branch", value),
246+
);
247+
await showInfo(
248+
"Successfully Changed Branch",
249+
process.platform === "linux"
250+
? "Replugged release branch changed but we can't relaunch automatically on Linux. Discord will close now."
251+
: "Replugged release branch changed and will relaunch Discord now to take effect!",
252+
);
253+
electron.app.relaunch();
254+
electron.app.exit(0);
255+
} catch (err) {
256+
console.error(err);
257+
await showError(
258+
"Update Error",
259+
"An unexpected error occurred. Check logs for details.",
260+
);
261+
}
262+
},
263+
};
264+
}),
265+
},
216266
{
217267
enabled: false,
218268
label: `Version: ${currentVersion === "dev" ? "dev" : `v${currentVersion}`}`,

src/renderer/coremods/settings/pages/General.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
Divider,
66
FieldSet,
77
Notice,
8+
RadioGroup,
89
Select,
910
Stack,
1011
Switch,
@@ -17,7 +18,7 @@ import * as QuickCSS from "src/renderer/managers/quick-css";
1718
import { generalSettings } from "src/renderer/managers/settings";
1819
import { t } from "src/renderer/modules/i18n";
1920
import { useSetting, useSettingArray } from "src/renderer/util";
20-
import { BACKGROUND_MATERIALS, VIBRANCY_SELECT_OPTIONS } from "src/types";
21+
import { BACKGROUND_MATERIALS, RepluggedBranchs, VIBRANCY_SELECT_OPTIONS } from "src/types";
2122

2223
import "./General.css";
2324

@@ -78,6 +79,21 @@ function GeneralTab(): React.ReactElement {
7879
return (
7980
<Stack gap={24}>
8081
<Stack gap={16}>
82+
<RadioGroup
83+
{...useSetting(generalSettings, "branch")}
84+
label={intl.string(t.REPLUGGED_SETTINGS_RELEASE_BRANCH)}
85+
description={intl.string(t.REPLUGGED_SETTINGS_RELEASE_BRANCH_DESC)}
86+
options={[
87+
{
88+
name: intl.string(t.REPLUGGED_SETTINGS_RELEASE_BRANCH_STABLE),
89+
value: RepluggedBranchs.STABLE,
90+
},
91+
{
92+
name: intl.string(t.REPLUGGED_SETTINGS_RELEASE_BRANCH_NIGHTLY),
93+
value: RepluggedBranchs.NIGHTLY,
94+
},
95+
]}
96+
/>
8197
<Switch
8298
{...useSetting(generalSettings, "badges")}
8399
label={intl.string(t.REPLUGGED_SETTINGS_BADGES)}

src/renderer/managers/settings.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { WEBSITE_URL } from "src/constants";
22
import { init } from "src/renderer/apis/settings";
3-
import type { BackgroundMaterialType, VibrancyType } from "src/types";
3+
import { type BackgroundMaterialType, RepluggedBranchs, type VibrancyType } from "src/types";
44

55
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
66
export type GeneralSettings = {
@@ -20,6 +20,7 @@ export type GeneralSettings = {
2020
backgroundMaterial?: BackgroundMaterialType;
2121
vibrancy?: VibrancyType | null;
2222
disableMinimumSize?: boolean;
23+
branch: RepluggedBranchs;
2324
};
2425

2526
const defaultSettings = {
@@ -39,6 +40,7 @@ const defaultSettings = {
3940
backgroundMaterial: "auto",
4041
vibrancy: null,
4142
disableMinimumSize: false,
43+
branch: RepluggedBranchs.STABLE,
4244
} satisfies Partial<GeneralSettings>;
4345

4446
export const generalSettings = init<GeneralSettings, keyof typeof defaultSettings>(

src/types/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import type { WebContents } from "electron";
22
import type { PluginManifest, ThemeManifest } from "./addon";
33

4+
export enum RepluggedBranchs {
5+
STABLE = "REPLUGGED_STABLE",
6+
NIGHTLY = "REPLUGGED_NIGHTLY",
7+
}
8+
49
export type RepluggedWebContents = WebContents & {
510
originalPreload?: string;
611
};

0 commit comments

Comments
 (0)