fix(electron): always show traffic light for mac (#7773)

fix AF-1209, fix PD-1550
This commit is contained in:
pengx17
2024-08-07 08:44:35 +00:00
parent 75a308ac79
commit 00ee2a8852
7 changed files with 20 additions and 45 deletions

View File

@@ -1,7 +1,6 @@
import { app, nativeTheme, shell } from 'electron';
import { getLinkPreview } from 'link-preview-js';
import { isMacOS } from '../../shared/utils';
import { persistentConfig } from '../config-storage/persist';
import { logger } from '../logger';
import type { NamespaceHandlers } from '../type';
@@ -43,12 +42,6 @@ export const uiHandlers = {
handleThemeChange: async (_, theme: (typeof nativeTheme)['themeSource']) => {
nativeTheme.themeSource = theme;
},
handleSidebarVisibilityChange: async (_, visible: boolean) => {
if (isMacOS()) {
const window = await getMainWindow();
window?.setWindowButtonVisibility(visible);
}
},
handleMinimizeApp: async () => {
const window = await getMainWindow();
window?.minimize();
@@ -68,8 +61,8 @@ export const uiHandlers = {
window.maximize();
}
},
handleWindowResize: async () => {
await handleWebContentsResize();
handleWindowResize: async e => {
await handleWebContentsResize(e.sender);
},
handleCloseApp: async () => {
app.quit();

View File

@@ -658,6 +658,8 @@ export class WebContentViewsManager {
sorted.forEach(({ view }, idx) => {
this.mainWindow?.contentView.addChildView(view, idx);
});
handleWebContentsResize(activeView?.webContents).catch(logger.error);
}
};
@@ -894,12 +896,12 @@ export async function getCookie(url?: string, name?: string) {
// there is no proper way to listen to webContents resize event
// we will rely on window.resize event in renderer instead
export async function handleWebContentsResize() {
export async function handleWebContentsResize(webContents?: WebContents) {
// right now when window is resized, we will relocate the traffic light positions
if (isMacOS()) {
const window = await getMainWindow();
const factor = window?.webContents.getZoomFactor() || 1;
window?.setWindowButtonPosition({ x: 20 * factor, y: 24 * factor - 6 });
const factor = webContents?.getZoomFactor() || 1;
window?.setWindowButtonPosition({ x: 16 * factor, y: 24 * factor - 6 });
}
}