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 4 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
1 change: 1 addition & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"signingkey",
"Skema",
"skus",
"titlebar",
"uninject",
"uninjector",
"uninjectors",
Expand Down
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
19 changes: 19 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,21 @@ export const General = (): React.ReactElement => {
{intl.string(t.REPLUGGED_SETTINGS_QUICKCSS_AUTO_APPLY)}
</SwitchItem>

{
// TODO: i18n
DiscordNative.process.platform.includes("linux") && (
<SwitchItem
value={titlebarValue}
onChange={(value) => {
titlebarOnChange(value);
restartModal(false);
FedeIlLeone marked this conversation as resolved.
Show resolved Hide resolved
}}
note={"Use custom window titlebar instead of the default OS titlebar"}>
Custom Titlebar
</SwitchItem>
)
}

<Category
title={intl.string(t.REPLUGGED_SETTINGS_ADVANCED)}
note={intl.string(t.REPLUGGED_SETTINGS_ADVANCED_DESC)}>
Expand Down
25 changes: 25 additions & 0 deletions src/renderer/coremods/titlebar/plaintextPatches.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
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: "macOSFrame:!0",
replacements: [
{
match: /\[.&&(null!=.\?)/,
replace: (_, suffix: string) => `[${suffix}`,
},
],
},
{
find: "renderWindow:window",
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>;