diff --git a/i18n/en-US.messages.d.ts b/i18n/en-US.messages.d.ts index 30e3e1568..477e6444c 100644 --- a/i18n/en-US.messages.d.ts +++ b/i18n/en-US.messages.d.ts @@ -1487,6 +1487,32 @@ declare const messages: { * Missing translations: `ar`, `bg`, `da`, `el`, `he`, `hi`, `hr`, `hu`, `lt`, `no`, `pt-PT`, `ro`, `sv-SE` */ 'REPLUGGED_SETTINGS_BADGES_DESC': TypedIntlMessageGetter<{}>, + /** + * Key: `5D5ltL` + * + * ### Definition + * ```text + * Custom Title Bar + * ``` + * + * ### Problems + * + * Missing translations: `ar`, `bg`, `cs`, `da`, `de`, `el`, `en-GB`, `es-ES`, `fi`, `fr`, `he`, `hi`, `hr`, `hu`, `id`, `it`, `ja`, `ko`, `lt`, `nl`, `no`, `pl`, `pt-BR`, `pt-PT`, `ro`, `ru`, `sk`, `sv-SE`, `tr`, `uk`, `vi`, `zh-CN`, `zh-TW` + */ + 'REPLUGGED_SETTINGS_CUSTOM_TITLE_BAR': TypedIntlMessageGetter<{}>, + /** + * Key: `x5PfoK` + * + * ### Definition + * ```text + * Use Discord's custom title bar instead of the system title bar. **Requires restart**. + * ``` + * + * ### Problems + * + * Missing translations: `ar`, `bg`, `cs`, `da`, `de`, `el`, `en-GB`, `es-ES`, `fi`, `fr`, `he`, `hi`, `hr`, `hu`, `id`, `it`, `ja`, `ko`, `lt`, `nl`, `no`, `pl`, `pt-BR`, `pt-PT`, `ro`, `ru`, `sk`, `sv-SE`, `tr`, `uk`, `vi`, `zh-CN`, `zh-TW` + */ + 'REPLUGGED_SETTINGS_CUSTOM_TITLE_BAR_DESC': TypedIntlMessageGetter<{$b?: HookFunction}>, /** * Key: `RIDq4u` * diff --git a/i18n/en-US.messages.js b/i18n/en-US.messages.js index c9ebe4246..ba6bb42ae 100644 --- a/i18n/en-US.messages.js +++ b/i18n/en-US.messages.js @@ -288,4 +288,7 @@ export default defineMessages({ "****WARNING:**** **Hardware acceleration** may need to be turned **off**. In some cases, you may experience a black background, such as when the window is cut off at the top or bottom due to the monitor resolution, or when the development tools are open and docked.", REPLUGGED_SETTINGS_ERROR_PLUGIN_NAME: "Plugin: {name}", REPLUGGED_STORE: "Store", + REPLUGGED_SETTINGS_CUSTOM_TITLE_BAR: "Custom Title Bar", + REPLUGGED_SETTINGS_CUSTOM_TITLE_BAR_DESC: + "Use Discord's custom title bar instead of the system title bar. **Requires restart**.", }); diff --git a/src/globals.d.ts b/src/globals.d.ts index f40d51cf5..59e6ca096 100644 --- a/src/globals.d.ts +++ b/src/globals.d.ts @@ -37,6 +37,7 @@ declare global { paste: () => void; read: () => string; }; + process: { platform: string }; }; export const _: typeof Lodash; diff --git a/src/main/index.ts b/src/main/index.ts index 8479570e1..1f6e0be89 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -10,6 +10,11 @@ const discordPath = join(dirname(require.main!.filename), "..", "app.orig.asar") const discordPackage = require(join(discordPath, "package.json")); require.main!.filename = join(discordPath, discordPackage.main); +let customTitleBar: boolean; +void getSetting("dev.replugged.Settings", "titleBar", false).then( + (titleBar) => (customTitleBar = titleBar), +); + Object.defineProperty(global, "appSettings", { set: (v /* : typeof global.appSettings*/) => { // cspell:ignore youre @@ -35,6 +40,8 @@ class BrowserWindow extends electron.BrowserWindow { }; }, ) { + if (opts.frame && process.platform.includes("linux") && customTitleBar) opts.frame = void 0; + const originalPreload = opts.webPreferences?.preload; if (opts.webContents) { diff --git a/src/renderer/coremods/settings/pages/General.tsx b/src/renderer/coremods/settings/pages/General.tsx index 8ca0bdd00..ee2d4a122 100644 --- a/src/renderer/coremods/settings/pages/General.tsx +++ b/src/renderer/coremods/settings/pages/General.tsx @@ -58,6 +58,10 @@ export const General = (): React.ReactElement => { "reactDevTools", ); + const { value: titleBarValue, onChange: titleBarOnChange } = util.useSetting( + generalSettings, + "titleBar", + ); const [kKeys, setKKeys] = React.useState([]); const isEasterEgg = kKeys.toString().includes(konamiCode.join(",")); @@ -110,6 +114,18 @@ export const General = (): React.ReactElement => { {intl.string(t.REPLUGGED_SETTINGS_QUICKCSS_AUTO_APPLY)} + {DiscordNative.process.platform.includes("linux") && ( + { + titleBarOnChange(value); + restartModal(true); + }} + note={intl.format(t.REPLUGGED_SETTINGS_CUSTOM_TITLE_BAR_DESC, {})}> + {intl.string(t.REPLUGGED_SETTINGS_CUSTOM_TITLE_BAR)} + + )} + diff --git a/src/renderer/coremods/titleBar/plaintextPatches.ts b/src/renderer/coremods/titleBar/plaintextPatches.ts new file mode 100644 index 000000000..6485bef01 --- /dev/null +++ b/src/renderer/coremods/titleBar/plaintextPatches.ts @@ -0,0 +1,21 @@ +import { init } from "src/renderer/apis/settings"; +import { type GeneralSettings, type PlaintextPatch, defaultSettings } from "src/types"; + +const generalSettings = await init( + "dev.replugged.Settings", + defaultSettings, +); + +export default (DiscordNative.process.platform.includes("linux") && generalSettings.get("titleBar") + ? [ + { + find: ".appAsidePanelWrapper,", + replacements: [ + { + match: /\(0,.\.getPlatform\)\(\)/, + replace: `"WINDOWS"`, + }, + ], + }, + ] + : []) as PlaintextPatch[]; diff --git a/src/renderer/managers/coremods.ts b/src/renderer/managers/coremods.ts index 4d2b1a845..422fb970b 100644 --- a/src/renderer/managers/coremods.ts +++ b/src/renderer/managers/coremods.ts @@ -10,6 +10,7 @@ import { default as contextMenu } from "../coremods/contextMenu/plaintextPatches import { default as languagePlaintext } from "../coremods/language/plaintextPatches"; import { default as settingsPlaintext } from "../coremods/settings/plaintextPatches"; import { default as badgesPlaintext } from "../coremods/badges/plaintextPatches"; +import { default as titleBarPlaintext } from "../coremods/titleBar/plaintextPatches"; import { Logger } from "../modules/logger"; const logger = Logger.api("Coremods"); @@ -85,5 +86,6 @@ export function runPlaintextPatches(): void { languagePlaintext, settingsPlaintext, badgesPlaintext, + titleBarPlaintext, ].forEach(patchPlaintext); } diff --git a/src/types/settings.ts b/src/types/settings.ts index 374d349fe..48f74fb7b 100644 --- a/src/types/settings.ts +++ b/src/types/settings.ts @@ -14,6 +14,7 @@ export type GeneralSettings = { showWelcomeNoticeOnOpen?: boolean; addonEmbeds?: boolean; reactDevTools?: boolean; + titleBar?: boolean; }; export const defaultSettings = { @@ -24,4 +25,5 @@ export const defaultSettings = { showWelcomeNoticeOnOpen: true, reactDevTools: false, addonEmbeds: true, + titleBar: false, } satisfies Partial;