Skip to content

Commit

Permalink
feat(main window): display main window on the screen containing or cl…
Browse files Browse the repository at this point in the history
…osest to the mouse pointer (#678)

When displaying the main window for Cerebro so far the primary screen has been chosen. This is
inconvenient for workstations with more than 1 screen. After this commit is applied the main window
will be displayed in the screen containing the mouse pointer (or the screen closest to the pointer
if the pointer is in between screens).

fix #647
  • Loading branch information
emilioidk committed Nov 22, 2023
1 parent 9196576 commit 7fc430d
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions app/main.development.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import AppTray from './main/createWindow/AppTray'
import autoStart from './main/createWindow/autoStart'
import initAutoUpdater from './initAutoUpdater'

import {
WINDOW_WIDTH,
} from 'main/constants/ui'

const iconSrc = {
DEFAULT: `${__dirname}/tray_icon.png`,
darwin: `${__dirname}/tray_iconTemplate@2x.png`,
Expand Down Expand Up @@ -38,12 +42,27 @@ const setupEnvVariables = () => {
}

app.whenReady().then(() => {
// We cannot require the screen module until the app is ready.
const { screen } = require('electron')

setupEnvVariables()

mainWindow = createMainWindow({
isDev,
src: `file://${__dirname}/main/index.html`, // Main window html
})

mainWindow.on('show', (event) => {
const cursorScreenPoint = screen.getCursorScreenPoint()
const nearestDisplay = screen.getDisplayNearestPoint(cursorScreenPoint)

const goalWidth = WINDOW_WIDTH
const goalX = Math.floor(nearestDisplay.bounds.x + (nearestDisplay.size.width - goalWidth) / 2)
const goalY = nearestDisplay.bounds.y + 200 // "top" is hardcoded now, should get from config or calculate accordingly?

config.set('winPosition', [goalX, goalY])
})

// eslint-disable-next-line global-require
require('@electron/remote/main').initialize()
// eslint-disable-next-line global-require
Expand Down

0 comments on commit 7fc430d

Please sign in to comment.