/
githubmirror
/
marktext
Обзор
Документация
Войти
/
githubmirror
/
marktext
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
packages/desktop/src/main/windows/utils.ts
81 строка
3 KB
Ran Luo
chore: convert repo to pnpm monorepo (packages/desktop, muyajs, website) (#4302)
29 май 2026, 05:25
Не верифицирован
29 май 2026, 05:25
565bfcd
Код
Авторство
О чём код?
import { screen } from 'electron' import type { BrowserWindow, BrowserWindowConstructorOptions } from 'electron' import { isLinux } from '../config' export const zoomIn = (win: BrowserWindow | null | undefined): void => { if (!win) return const { webContents } = win const zoom = webContents.getZoomFactor() // WORKAROUND: We need to set zoom on the browser window due to Electron#16018. webContents.send('mt::window-zoom', Math.min(2.0, zoom + 0.125)) } export const zoomOut = (win: BrowserWindow | null | undefined): void => { if (!win) return const { webContents } = win const zoom = webContents.getZoomFactor() // WORKAROUND: We need to set zoom on the browser window due to Electron#16018. webContents.send('mt::window-zoom', Math.max(0.5, zoom - 0.125)) } export const centerWindowOptions = ( options: BrowserWindowConstructorOptions & { width: number height: number x?: number y?: number } ): void => { // "workArea" doesn't work on Linux const { bounds, workArea } = screen.getDisplayNearestPoint(screen.getCursorScreenPoint()) const screenArea = isLinux ? bounds : workArea const { width, height } = options options.x = Math.ceil(screenArea.x + (screenArea.width - width) / 2) options.y = Math.ceil(screenArea.y + (screenArea.height - height) / 2) } export interface WindowStateLike { x?: number y?: number width: number height: number } export const ensureWindowPosition = ( windowState: WindowStateLike ): { x: number; y: number; width: number; height: number } => { // "workArea" doesn't work on Linux const { bounds, workArea } = screen.getPrimaryDisplay() const screenArea = isLinux ? bounds : workArea let { x, y, width, height } = windowState let center = false if (x === undefined || y === undefined) { center = true // First app start; check whether window size is larger than screen size if (screenArea.width < width) width = screenArea.width if (screenArea.height < height) height = screenArea.height } else { center = !screen .getAllDisplays() .map( (display) => x! >= display.bounds.x && x! <= display.bounds.x + display.bounds.width && y! >= display.bounds.y && y! <= display.bounds.y + display.bounds.height ) .some((display) => display) } if (center) { x = Math.ceil(screenArea.x + (screenArea.width - width) / 2) y = Math.ceil(screenArea.y + (screenArea.height - height) / 2) } return { x: x as number, y: y as number, width, height } }