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 Window Bar #207

Draft
wants to merge 37 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
ebb6525
Custom Window Bar
goosesima Aug 3, 2022
46b48c3
fix typo
goosesima Aug 3, 2022
ff32722
Update sources/code/renderer/preload/main.ts
goosesima Aug 3, 2022
95e29e0
Update sources/translations/en/settings.json
goosesima Aug 3, 2022
1e1a86e
Update sources/code/main/modules/config.ts
goosesima Aug 3, 2022
375fdab
Better custom bar
goosesima Aug 24, 2022
2378d22
Bug when custom bar disabled
goosesima Aug 24, 2022
d4cf135
Merge branch 'master' into master
goosesima Aug 26, 2022
e7bd0fc
Merge branch 'master' into master
SpacingBat3 Aug 26, 2022
60c3d4d
Merge branch 'master' into master
SpacingBat3 Aug 28, 2022
b3fde34
Update sources/code/renderer/preload/settings.ts
goosesima Aug 29, 2022
6108d36
Optimization
goosesima Aug 29, 2022
8ccd883
Merge branch 'master' into master
goosesima Aug 29, 2022
940e28f
Optimization
goosesima Aug 29, 2022
03ea921
Optimization
goosesima Aug 29, 2022
4086c98
Merge branch 'master' into master
SpacingBat3 Aug 30, 2022
cae3090
Remove note from settings.json
goosesima Aug 30, 2022
258b2bf
Merge branch 'master' into master
goosesima Sep 1, 2022
a674e58
Add GooseSima to contributors in `package.json`.
SpacingBat3 Sep 1, 2022
efce472
Add/update localization files.
SpacingBat3 Sep 1, 2022
a4162e7
Merge branch 'master' into master
goosesima Sep 3, 2022
48bc22c
Merge branch 'master' into master
goosesima Sep 4, 2022
3fad6e9
Merge branch 'master' into master
SpacingBat3 Sep 11, 2022
f9fe794
Merge branch 'master' into master
SpacingBat3 Sep 12, 2022
cba332c
Merge branch 'master' into master
SpacingBat3 Oct 1, 2022
5989dca
Fix code for `strict-boolean-expressions` rule.
SpacingBat3 Oct 1, 2022
5e25ac2
Merge branch 'master' into master
SpacingBat3 Oct 16, 2022
c0314f3
Merge branch 'master' into master
SpacingBat3 Nov 26, 2022
adacfd5
Merge branch 'master' into master
SpacingBat3 Dec 8, 2022
91a1c8f
Merge branch 'master' into master
SpacingBat3 Dec 17, 2022
8e22de4
Move to `typeMerge` in `Config` class.
SpacingBat3 Dec 17, 2022
ab6cf74
Even more const enums.
SpacingBat3 Dec 18, 2022
0b5a8e0
Update badges.
SpacingBat3 Dec 18, 2022
28adfeb
Make `test` command synchronous.
SpacingBat3 Dec 18, 2022
d695066
General code optimizations and fixes.
SpacingBat3 Dec 20, 2022
42586a4
Minior fixes
SpacingBat3 Dec 21, 2022
f781525
Merge `SpacingBat3:master` into `goosesima:master`
SpacingBat3 Dec 21, 2022
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 sources/assets/icons/symbols/custombar/close-hover.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions sources/assets/icons/symbols/custombar/close.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions sources/assets/icons/symbols/custombar/maximize.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions sources/assets/icons/symbols/custombar/minimize.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
74 changes: 74 additions & 0 deletions sources/assets/web/css/custombar.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
body {
margin: 0;
padding: 0;
background: #202225;
overflow: hidden;
}
.titlebar {
display: flex;
flex-direction: row;
align-content: center;
align-items: center;
height: 20px;
-webkit-app-region: drag;
margin-left: 15px;
font-size: 0.8em;
text-transform: uppercase;
color: #ddd;
font-weight: 600;
}

.titlebar .title {
margin-right: auto;
}

.titlebar * {
-webkit-app-region: no-drag;
cursor: pointer;
background-size: 12px;
background-repeat: no-repeat;
background-position: center;
}

.titlebar .btn {
height: 12px;
width: 12px;
padding: 8px;
}

.titlebar .title {
padding-left: 2px;
padding-right: 2px;
font-family: system-ui;
}

.titlebar .title:hover {
background-color: #fff;
color: #000;
border-radius: 20px;
}

.titlebar .btn:hover {
background-color: #32353b;
}

.titlebar .closebutton:hover {
background-image: url("../../icons/symbols/custombar/close-hover.svg");
background-color: #f53d3d;
}

.titlebar .closebutton {
background-image: url("../../icons/symbols/custombar/close.svg");
}

.titlebar .maximizebutton {
background-image: url("../../icons/symbols/custombar/maximize.svg");
}

.titlebar .minimizebutton {
background-image: url("../../icons/symbols/custombar/minimize.svg");
}

.titlebar+#app-mount {
height: calc(100% - 20px);
}
goosesima marked this conversation as resolved.
Show resolved Hide resolved
7 changes: 7 additions & 0 deletions sources/assets/web/css/discord-custombar.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
body {
padding-top: 20px !important;
}

#app-mount {
height: calc(100% - 20px);
}
1 change: 1 addition & 0 deletions sources/assets/web/css/load.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ html, body {
margin: 0;
background-color: #36393F;
height: 100%;
-webkit-app-region: drag;
goosesima marked this conversation as resolved.
Show resolved Hide resolved
}
body, div.aura {
text-align: center;
Expand Down
10 changes: 10 additions & 0 deletions sources/assets/web/html/custombar.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<meta http-equiv="Content-Security-Policy" content="default-src 'self'">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="../css/custombar.css" rel="stylesheet" type="text/css">
</head>
<body>
</body>
goosesima marked this conversation as resolved.
Show resolved Hide resolved
</html>
3 changes: 3 additions & 0 deletions sources/code/main/modules/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ const defaultAppConfig = {
},
taskbar: {
flash: true
},
custombar: {
use: false
}
},
privacy: {
Expand Down
52 changes: 52 additions & 0 deletions sources/code/main/windows/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { getWebCordCSP } from "../modules/csp";
import l10n from "../../common/modules/l10n";
import { loadChromiumExtensions, styles } from "../modules/extensions";
import { commonCatches } from "../modules/error";
import loadSettingsWindow from "../windows/settings";

import type { PartialRecursive } from "../../common/global";

Expand All @@ -44,6 +45,8 @@ export default function createMainWindow(flags:MainWindowFlags): BrowserWindow {

// Browser window

const useCustomBar = configData.get().settings.general.custombar.use;

const win = new BrowserWindow({
title: app.getName(),
minWidth: appInfo.minWinWidth,
Expand All @@ -52,6 +55,7 @@ export default function createMainWindow(flags:MainWindowFlags): BrowserWindow {
width: mainWindowState.initState.width,
backgroundColor: appInfo.backgroundColor,
show: false,
frame: !useCustomBar,
webPreferences: {
preload: resolve(app.getAppPath(), "app/code/renderer/preload/main.js"),
nodeIntegration: false, // Never set to "true"!
Expand All @@ -68,6 +72,43 @@ export default function createMainWindow(flags:MainWindowFlags): BrowserWindow {
},
...(process.platform !== "win32" ? {icon: appInfo.icons.app} : {}),
});

// Custom Bar
if (useCustomBar){
const custombarView = new BrowserView({
webPreferences: {
nodeIntegration: false,
preload: resolve(app.getAppPath(), "app/code/renderer/preload/custombar.js")
}
});
win.setBrowserView(custombarView);
custombarView.setAutoResize({ width: true })
custombarView.webContents.loadFile(resolve(app.getAppPath(), "sources/assets/web/html/custombar.html"));
custombarView.setBounds({ width: win.getBounds().width, height: 20, x: 0, y: 0 });
custombarView.webContents.on('ipc-message', (_event, channel) => {
switch (channel) {
case 'window-minimize':
console.debug("[Custom Bar] Minimize window...");
win.minimize();
break;
case 'window-maximize':
console.debug("[Custom Bar] Maximize window...");
win.isMaximized() ? win.unmaximize() : win.maximize();
break;
case 'window-close':
console.debug("[Custom Bar] Maximize window...");
win.close();
break;
case 'opensettings':
console.debug("[Custom Bar] Opening settings...");
loadSettingsWindow(win);
break;
default:
break;
}
});
goosesima marked this conversation as resolved.
Show resolved Hide resolved
}

win.webContents.on("did-fail-load", (_event, errorCode, errorDescription, validatedURL) => {
if (errorCode <= -100 && errorCode >= -199)
// Show offline page on connection errors.
Expand Down Expand Up @@ -341,6 +382,17 @@ export default function createMainWindow(flags:MainWindowFlags): BrowserWindow {
.then(buffer => buffer.toString())
.then(data => win.webContents.insertCSS(data))
.catch(commonCatches.print);

if(useCustomBar){
styles.load(win.webContents)
.catch(commonCatches.print);
import("fs")
.then(fs => fs.promises.readFile)
.then(read => read(resolve(app.getAppPath(), "sources/assets/web/css/discord-custombar.css")))
.then(buffer => buffer.toString())
.then(data => win.webContents.insertCSS(data))
.catch(commonCatches.print);
}
}
});

Expand Down
38 changes: 38 additions & 0 deletions sources/code/renderer/preload/custombar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const { ipcRenderer } = require('electron');

window.addEventListener("DOMContentLoaded", () => {
/*
* Custom title bar
*/

const titlebar = document.createElement("div");
goosesima marked this conversation as resolved.
Show resolved Hide resolved
titlebar.className = "titlebar";

const title = document.createElement("div");
// title.innerText = location.host.split(".")[0]!;
title.innerText = "webcord";
title.className = "title";
const minimizebutton = document.createElement("div");
minimizebutton.className = "minimizebutton btn";
const maximizebutton = document.createElement("div");
maximizebutton.className = "maximizebutton btn";
const closebutton = document.createElement("div");
closebutton.className = "closebutton btn";
titlebar.appendChild(title);
titlebar.appendChild(minimizebutton);
titlebar.appendChild(maximizebutton);
titlebar.appendChild(closebutton);
document.body.prepend(titlebar);
title.onclick = function () {
ipcRenderer.send('opensettings', '')
};
minimizebutton.onclick = function () {
ipcRenderer.send('window-minimize', '')
};
maximizebutton.onclick = function () {
ipcRenderer.send('window-maximize', '')
};
closebutton.onclick = function () {
ipcRenderer.send('window-close', '')
};
});
6 changes: 3 additions & 3 deletions sources/code/renderer/preload/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ function generateSettings(optionsGroups: htmlConfig) {
});
} else if(!("dropdown" in setting || "input" in setting || "keybind" in setting)) {
(Object.keys as keys)(setting).sort().map(key => {
if(key !== "name" && key !== "description" && key !== "labels" && setting[key] !== undefined) {
if (key !== "name" && key !== "description" && key !== "labels" && setting[key] !== undefined && setting.labels) {
goosesima marked this conversation as resolved.
Show resolved Hide resolved
formContainer.appendChild(createForm({
type:"checkbox",
id: groupId+"."+settingKey+"."+key,
type: "checkbox",
id: groupId + "." + settingKey + "." + key,
isChecked: setting[key] === true,
label: labels[key] ?? "N/A"
}));
Expand Down
7 changes: 7 additions & 0 deletions sources/translations/en/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@
"disable": "Disable hiding window to the system tray functionality."
}
},
"custombar": {
"name": "Custom window bar",
"description": "Uses non-native window bar. To access settings press title of window. <b>Important:</b> it injects custom CSS. This might potentially let Discord to know it is modded.",
"labels": {
"use": "Use custom window bar. (Requires restart)"
}
},
goosesima marked this conversation as resolved.
Show resolved Hide resolved
"taskbar": {
"name": "Taskbar",
"description": "Controls the behavior of taskbar entry of WebCord.",
Expand Down