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

Add ability to use native OS frame #1709

Open
wants to merge 5 commits into
base: main
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion assets/locales/en-us.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
},
"frame": {
"name": "Window Frame",
"note": "Adds the native os window frame to the main window"
"note": "Adds the native OS window frame to the main window (requires restart)"
}
},
"addons": {
Expand Down Expand Up @@ -237,6 +237,10 @@
"enabledInfo": "This option requires a transparent theme in order to work properly. On Windows this may break your aero snapping and maximizing.\n\nIn order to take effect, Discord needs to be restarted. Do you want to restart now?",
"disabledInfo": "In order to take effect, Discord needs to be restarted. Do you want to restart now?"
},
"NativeFrame": {
"enabledInfo": "In order to take effect, Discord needs to be restarted. Do you want to restart now?",
"disabledInfo": "In order to take effect, Discord needs to be restarted. Do you want to restart now?"
},
"Notices": {
"moreInfo": "More Info"
},
Expand Down
28 changes: 26 additions & 2 deletions injector/src/modules/browserwindow.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,36 @@ class BrowserWindow extends electron.BrowserWindow {
}

// Only affect frame if it is *explicitly* set
// const shouldHaveFrame = BetterDiscord.getSetting("window", "frame");
// if (typeof(shouldHaveFrame) === "boolean") options.frame = shouldHaveFrame;
const shouldHaveFrame = BetterDiscord.getSetting("window", "frame");
if (typeof(shouldHaveFrame) === "boolean") options.frame = shouldHaveFrame;

super(options);
this.__originalPreload = originalPreload;
BetterDiscord.setup(this);

if (typeof(shouldHaveFrame) === "boolean" && shouldHaveFrame) {
// Override the window open handler to force new windows (such as pop-outs) to have frames
this.webContents.on("did-finish-load", () => {
const originalWindowOpenHandler = this.webContents._windowOpenHandler;

this.webContents.setWindowOpenHandler((details) => {
const originalResponse = originalWindowOpenHandler(details);
// Only set the frame option if it's a pop-out
if (details.frameName === "DISCORD_CHANNEL_CALL_POPOUT") {
originalResponse.overrideBrowserWindowOptions.frame = true;
}
return originalResponse;
});
});

// Remove the title bar and menu from new windows
this.webContents.on("did-create-window", (window) => {
window.removeMenu();
window.webContents.insertCSS(`div[class^="titleBar_"], div[class*=" titleBar_"] {
display: none !important;
}`);
});
}
}
}

Expand Down
1 change: 1 addition & 0 deletions renderer/src/builtins/builtins.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ export {default as StopDevToolsWarning} from "./developer/devtoolswarning";
export {default as DebugLogs} from "./developer/debuglogs";

export {default as WindowPrefs} from "./window/transparency";
export {default as NativeFrame} from "./window/frame";
export {default as RemoveMinimumSize} from "./window/removeminimumsize";
33 changes: 33 additions & 0 deletions renderer/src/builtins/window/frame.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import Builtin from "@structs/builtin";

import Strings from "@modules/strings";
import IPC from "@modules/ipc";

import Modals from "@ui/modals";


export default new class NativeFrame extends Builtin {
get name() {return "NativeFrame";}
get category() {return "window";}
get id() {return "frame";}

enabled() {
this.showModal(Strings.NativeFrame.enabledInfo);
document.body.classList.add("bd-frame");
}

disabled() {
this.showModal(Strings.NativeFrame.disabledInfo);
document.body.classList.remove("bd-frame");
}

showModal(info) {
if (!this.initialized) return;
Modals.showConfirmationModal(Strings.Modals.additionalInfo, info, {
confirmText: Strings.Modals.restartNow,
cancelText: Strings.Modals.restartLater,
danger: true,
onConfirm: () => IPC.relaunch()
});
}
};
4 changes: 2 additions & 2 deletions renderer/src/data/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ export default [
shown: false,
settings: [
{type: "switch", id: "transparency", value: false},
{type: "switch", id: "removeMinimumSize", value: false},
{type: "switch", id: "frame", value: false, hidden: true}
{type: "switch", id: "frame", value: false},
{type: "switch", id: "removeMinimumSize", value: false}
]
},
{
Expand Down
7 changes: 7 additions & 0 deletions renderer/src/modules/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ export default new class Core {
Logger.log("Startup", "Initializing Settings");
Settings.initialize();

Logger.log("Startup", "Injecting Setting-dependent BD Styles");
if (Settings.get("settings", "window", "frame", false)) {
DOMManager.injectStyle("bd-frame", `div[class^="titleBar_"], div[class*=" titleBar_"] {
display: none !important;
}`);
}

Logger.log("Startup", "Initializing DOMManager");
DOMManager.initialize();

Expand Down