Skip to content

Commit

Permalink
Fixed: #128 || tray window display bug in multi screen
Browse files Browse the repository at this point in the history
  • Loading branch information
Molunerfinn committed Oct 20, 2018
1 parent 094b83b commit ca01d2c
Showing 1 changed file with 6 additions and 19 deletions.
25 changes: 6 additions & 19 deletions src/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ function createTray () {
}
tray.popUpContextMenu(contextMenu)
})
tray.on('click', () => {
tray.on('click', (event, bounds) => {
if (process.platform === 'darwin') {
let img = clipboard.readImage()
let obj = []
Expand All @@ -115,7 +115,7 @@ function createTray () {
imgUrl
})
}
toggleWindow()
toggleWindow(bounds)
setTimeout(() => {
window.webContents.send('clipboardFiles', obj)
}, 0)
Expand Down Expand Up @@ -301,29 +301,16 @@ const createMenu = () => {
}
}

const getWindowPosition = () => {
const windowBounds = window.getBounds()
const trayBounds = tray.getBounds()
const x = Math.round(trayBounds.x + (trayBounds.width / 2) - (windowBounds.width / 2))
const y = Math.round(trayBounds.y + trayBounds.height - 10)

return {
x,
y
}
}

const toggleWindow = () => {
const toggleWindow = (bounds) => {
if (window.isVisible()) {
window.hide()
} else {
showWindow()
showWindow(bounds)
}
}

const showWindow = () => {
const position = getWindowPosition()
window.setPosition(position.x, position.y, false)
const showWindow = (bounds) => {
window.setPosition(bounds.x - 98 + 11, bounds.y, false)
window.webContents.send('updateFiles')
window.show()
window.focus()
Expand Down

0 comments on commit ca01d2c

Please sign in to comment.