Skip to content

Commit c42c1b7

Browse files
authored
Fix Visual Refresh titlebar (#1104)
1 parent 765ffc0 commit c42c1b7

File tree

5 files changed

+52
-22
lines changed

5 files changed

+52
-22
lines changed

src/main/ipc.ts

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,17 @@
77
if (process.platform === "linux") import("./venmic");
88

99
import { execFile } from "child_process";
10-
import { app, BrowserWindow, clipboard, dialog, nativeImage, RelaunchOptions, session, shell } from "electron";
10+
import {
11+
app,
12+
BrowserWindow,
13+
clipboard,
14+
dialog,
15+
IpcMainInvokeEvent,
16+
nativeImage,
17+
RelaunchOptions,
18+
session,
19+
shell
20+
} from "electron";
1121
import { mkdirSync, readFileSync, watch } from "fs";
1222
import { open, readFile } from "fs/promises";
1323
import { release } from "os";
@@ -68,28 +78,29 @@ handle(IpcEvents.SHOW_ITEM_IN_FOLDER, (_, path) => {
6878
shell.showItemInFolder(path);
6979
});
7080

81+
function getWindow(e: IpcMainInvokeEvent, key?: string) {
82+
return key ? PopoutWindows.get(key)! : (BrowserWindow.fromWebContents(e.sender) ?? mainWin);
83+
}
84+
7185
handle(IpcEvents.FOCUS, () => {
7286
mainWin.show();
7387
mainWin.setSkipTaskbar(false);
7488
});
7589

7690
handle(IpcEvents.CLOSE, (e, key?: string) => {
77-
const popout = PopoutWindows.get(key!);
78-
if (popout) return popout.close();
79-
80-
const win = BrowserWindow.fromWebContents(e.sender) ?? e.sender;
81-
win.close();
91+
getWindow(e, key).close();
8292
});
8393

84-
handle(IpcEvents.MINIMIZE, e => {
85-
mainWin.minimize();
94+
handle(IpcEvents.MINIMIZE, (e, key?: string) => {
95+
getWindow(e, key).minimize();
8696
});
8797

88-
handle(IpcEvents.MAXIMIZE, e => {
89-
if (mainWin.isMaximized()) {
90-
mainWin.unmaximize();
98+
handle(IpcEvents.MAXIMIZE, (e, key?: string) => {
99+
const win = getWindow(e, key);
100+
if (win.isMaximized()) {
101+
win.unmaximize();
91102
} else {
92-
mainWin.maximize();
103+
win.maximize();
93104
}
94105
});
95106

src/preload/VesktopNative.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ export const VesktopNative = {
5555
win: {
5656
focus: () => invoke<void>(IpcEvents.FOCUS),
5757
close: (key?: string) => invoke<void>(IpcEvents.CLOSE, key),
58-
minimize: () => invoke<void>(IpcEvents.MINIMIZE),
59-
maximize: () => invoke<void>(IpcEvents.MAXIMIZE)
58+
minimize: (key?: string) => invoke<void>(IpcEvents.MINIMIZE, key),
59+
maximize: (key?: string) => invoke<void>(IpcEvents.MAXIMIZE, key)
6060
},
6161
capturer: {
6262
getLargeThumbnail: (id: string) => invoke<string>(IpcEvents.CAPTURER_GET_LARGE_THUMBNAIL, id)

src/renderer/patches/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ import "./screenShareFixes";
1414
import "./spellCheck";
1515
import "./windowsTitleBar";
1616
import "./streamerMode";
17-
import "./nativeFocus";
17+
import "./windowMethods";
1818
import "./hideDownloadAppsButton";
Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,18 @@ import { addPatch } from "./shared";
99
addPatch({
1010
patches: [
1111
{
12-
find: ".DEEP_LINK]:{",
12+
find: ",setSystemTrayApplications",
1313
replacement: [
14+
{
15+
// eslint-disable-next-line no-useless-escape
16+
match: /\i\.window\.(close|minimize|maximize)/,
17+
replace: `VesktopNative.win.$1`
18+
},
1419
{
1520
// TODO: Fix eslint rule
1621
// eslint-disable-next-line no-useless-escape
17-
match: /(?<=\.DEEP_LINK.{0,200}?)\i\.\i\.focus\(\)/,
18-
replace: "VesktopNative.win.focus()"
22+
match: /(focus(\(\i\)){).{0,150}?\.focus\(\i,\i\)/,
23+
replace: "$1VesktopNative.win.focus$2"
1924
}
2025
]
2126
}

src/renderer/patches/windowsTitleBar.tsx

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,25 @@ if (Settings.store.customTitleBar)
1919
// eslint-disable-next-line no-useless-escape
2020
match: /case \i\.\i\.WINDOWS:/,
2121
replace: 'case "WEB":'
22+
}
23+
]
24+
},
25+
// Visual Refresh
26+
{
27+
find: '"data-windows":',
28+
replacement: [
29+
{
30+
// TODO: Fix eslint rule
31+
// eslint-disable-next-line no-useless-escape
32+
match: /\i===\i\.PlatformTypes\.WINDOWS/g,
33+
replace: "true"
2234
},
23-
...["close", "minimize", "maximize"].map(op => ({
24-
match: new RegExp(String.raw`\i\.\i\.${op}\b`),
25-
replace: `VesktopNative.win.${op}`
26-
}))
35+
{
36+
// TODO: Fix eslint rule
37+
// eslint-disable-next-line no-useless-escape
38+
match: /\i===\i\.PlatformTypes\.WEB/g,
39+
replace: "false"
40+
}
2741
]
2842
}
2943
]

0 commit comments

Comments
 (0)