Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

custom titlebar on linux #644

Open
wants to merge 7 commits into
base: v4.9.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions i18n/en-US.messages.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`
*
Expand Down
3 changes: 3 additions & 0 deletions i18n/en-US.messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -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**.",
});
1 change: 1 addition & 0 deletions src/globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ declare global {
paste: () => void;
read: () => string;
};
process: { platform: string };
};

export const _: typeof Lodash;
Expand Down
7 changes: 7 additions & 0 deletions src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down
16 changes: 16 additions & 0 deletions src/renderer/coremods/settings/pages/General.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ export const General = (): React.ReactElement => {
"reactDevTools",
);

const { value: titleBarValue, onChange: titleBarOnChange } = util.useSetting(
generalSettings,
"titleBar",
);
const [kKeys, setKKeys] = React.useState<number[]>([]);

const isEasterEgg = kKeys.toString().includes(konamiCode.join(","));
Expand Down Expand Up @@ -110,6 +114,18 @@ export const General = (): React.ReactElement => {
{intl.string(t.REPLUGGED_SETTINGS_QUICKCSS_AUTO_APPLY)}
</SwitchItem>

{DiscordNative.process.platform.includes("linux") && (
<SwitchItem
value={titleBarValue}
onChange={(value) => {
titleBarOnChange(value);
restartModal(true);
}}
note={intl.format(t.REPLUGGED_SETTINGS_CUSTOM_TITLE_BAR_DESC, {})}>
{intl.string(t.REPLUGGED_SETTINGS_CUSTOM_TITLE_BAR)}
</SwitchItem>
)}

<Category
title={intl.string(t.REPLUGGED_SETTINGS_ADVANCED)}
note={intl.string(t.REPLUGGED_SETTINGS_ADVANCED_DESC)}>
Expand Down
21 changes: 21 additions & 0 deletions src/renderer/coremods/titleBar/plaintextPatches.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { init } from "src/renderer/apis/settings";
import { type GeneralSettings, type PlaintextPatch, defaultSettings } from "src/types";

const generalSettings = await init<GeneralSettings, keyof typeof defaultSettings>(
"dev.replugged.Settings",
defaultSettings,
);

export default (DiscordNative.process.platform.includes("linux") && generalSettings.get("titleBar")
? [
{
find: ".appAsidePanelWrapper,",
replacements: [
{
match: /\(0,.\.getPlatform\)\(\)/,
replace: `"WINDOWS"`,
},
],
},
]
: []) as PlaintextPatch[];
2 changes: 2 additions & 0 deletions src/renderer/managers/coremods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -85,5 +86,6 @@ export function runPlaintextPatches(): void {
languagePlaintext,
settingsPlaintext,
badgesPlaintext,
titleBarPlaintext,
].forEach(patchPlaintext);
}
2 changes: 2 additions & 0 deletions src/types/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export type GeneralSettings = {
showWelcomeNoticeOnOpen?: boolean;
addonEmbeds?: boolean;
reactDevTools?: boolean;
titleBar?: boolean;
};

export const defaultSettings = {
Expand All @@ -24,4 +25,5 @@ export const defaultSettings = {
showWelcomeNoticeOnOpen: true,
reactDevTools: false,
addonEmbeds: true,
titleBar: false,
} satisfies Partial<GeneralSettings>;