Skip to content

Commit 95a8420

Browse files
committed
fix(linux): window to have only one controls set
1 parent 7ca2156 commit 95a8420

File tree

8 files changed

+47
-174
lines changed

8 files changed

+47
-174
lines changed

src/base/components/titlebar.html

Lines changed: 0 additions & 110 deletions
This file was deleted.

src/base/index.html

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@
1818
id="include-controls"
1919
src="./components/controls.html"
2020
></sl-include>
21-
<sl-include
22-
id="include-titlebar"
23-
src="./components/titlebar.html"
24-
></sl-include>
2521
<sl-include src="./components/splash.html"></sl-include>
2622
<sl-include id="include-tabs" src="./components/tabs.html"></sl-include>
2723
<sl-include

src/base/styles/index.css

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -38,42 +38,6 @@ body {
3838
font-family: arial;
3939
}
4040

41-
.titlebar {
42-
position: fixed;
43-
top: 0px;
44-
right: 0px;
45-
width: max-content;
46-
text-align: right;
47-
margin: 4px 4px 0px 0px;
48-
cursor: default;
49-
z-index: 5;
50-
app-region: no-drag;
51-
display: flex;
52-
53-
.linux-titlebar {
54-
display: none;
55-
}
56-
57-
button {
58-
width: 32px;
59-
height: 32px;
60-
font-size: 0px;
61-
border: none;
62-
border-radius: 6px;
63-
background: transparent;
64-
65-
&:hover {
66-
background: #303236;
67-
}
68-
69-
svg {
70-
width: 16px;
71-
height: 16px;
72-
filter: invert(1);
73-
}
74-
}
75-
}
76-
7741
sl-include.alert-modal {
7842
position: fixed;
7943
z-index: 50;

src/base/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
"compilerOptions": {
44
"lib": ["ESNext", "DOM", "DOM.Iterable"]
55
},
6-
"include": ["**/*", "../types"]
6+
"include": ["**/*", "../tools", "../types"]
77
}

src/process/platform.js

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,4 @@ export function applyDirectStyling() {
1616
);
1717
}, 1500);
1818
}
19-
20-
if (process.platform === "linux") {
21-
setTimeout(() => {
22-
mainWindow.webContents.executeJavaScript(
23-
`document.querySelector(".linux-titlebar").style.display = 'block'`,
24-
);
25-
}, 1500);
26-
}
27-
28-
if (process.platform === "win32") {
29-
setTimeout(() => {
30-
mainWindow.webContents.executeJavaScript(
31-
`document.querySelector(".titlebar").style.right = '145px'`,
32-
);
33-
}, 1500);
34-
}
3519
}

src/process/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"extends": "../../tsconfig.json",
3-
"include": ["**/*", "../types"]
3+
"include": ["**/*", "../tools", "../types"]
44
}

src/process/window.js

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,23 @@ import path from "path";
44

55
import { setAppMenu, getTabMenu } from "./menu.js";
66
import { applyDirectStyling } from "./platform.js";
7+
import { deepFreeze } from "../tools/object.js";
78

89
/** @type {import("electron").BrowserWindow} */
910
let mainWindow;
11+
const TITLEBAR_OVERLAY = deepFreeze({
12+
BASE: {
13+
height: 42,
14+
},
15+
DARK: {
16+
color: "#18181a",
17+
symbolColor: "#ffffff",
18+
},
19+
LIGHT: {
20+
color: "#ffffff",
21+
symbolColor: "#000000",
22+
},
23+
});
1024

1125
export function getMainWindow() {
1226
return mainWindow;
@@ -34,12 +48,7 @@ export const MainWindow = {
3448
// Titlebar
3549
titleBarStyle: "hidden",
3650
trafficLightPosition: { x: 16, y: 12 }, // for macOS
37-
titleBarOverlay: {
38-
// For Windows
39-
color: "#1f1f1f",
40-
symbolColor: "white",
41-
height: 40,
42-
},
51+
titleBarOverlay: TITLEBAR_OVERLAY.BASE,
4352
// Other Options
4453
autoHideMenuBar: true,
4554
frame: false,
@@ -81,6 +90,13 @@ export const MainWindow = {
8190
});
8291
ipcMain.on("set-theme", (_event, themeId) => {
8392
nativeTheme.themeSource = themeId;
93+
94+
mainWindow.setTitleBarOverlay({
95+
...TITLEBAR_OVERLAY.BASE,
96+
...(nativeTheme.shouldUseDarkColors
97+
? TITLEBAR_OVERLAY.DARK
98+
: TITLEBAR_OVERLAY.LIGHT),
99+
});
84100
});
85101

86102
if (process.platform === "darwin") {

src/tools/object.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* Deep freeze an object.
3+
*
4+
* @template {object} T
5+
*
6+
* @param {T} obj
7+
*
8+
* @returns {Readonly<T>}
9+
*/
10+
export function deepFreeze(obj) {
11+
const isObject = typeof obj === "object";
12+
const isNull = obj === null;
13+
const isFrozen = Object.isFrozen(obj);
14+
15+
if (isObject && !isNull && !isFrozen) {
16+
for (const key of Object.getOwnPropertyNames(obj)) {
17+
deepFreeze(obj[/** @type {keyof T}*/ (key)]);
18+
}
19+
Object.freeze(obj);
20+
}
21+
22+
return obj;
23+
}

0 commit comments

Comments
 (0)