This commit is contained in:
Luka Leer 2024-04-17 20:21:20 +00:00 committed by GitHub
commit 6f2293397c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 74 additions and 5 deletions

View File

@ -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": {
@ -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"
},

View File

@ -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;
}`);
});
}
}
}

View File

@ -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";

View File

@ -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()
});
}
};

View File

@ -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}
]
},
{

View File

@ -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();