Skip to content

Commit

Permalink
Fix OS X bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
staniel359 committed Jun 8, 2021
1 parent 4203fc4 commit 9e45833
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 33 deletions.
79 changes: 48 additions & 31 deletions electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const height = 600

const isDevelopment =
process.env.NODE_ENV === 'development'
const isOSX = process.platform === 'darwin'

const iconPath = path.join(
__dirname,
Expand All @@ -38,18 +39,20 @@ const browserWindowOptions = {
}
}

let win = null
let mainWindow = null
let tray = null

if (isDevelopment) {
app.setPath(
'userData',
path.join(__dirname, 'electron-data')
const userDataPath = path.join(
__dirname,
'electron-data'
)

app.setPath('userData', userDataPath)
}

function createWindow () {
win = new BrowserWindow(
mainWindow = new BrowserWindow(
browserWindowOptions
)

Expand All @@ -60,15 +63,15 @@ function createWindow () {
} = require('electron-devtools-installer')

installExtension(VUEJS_DEVTOOLS).then(() => {
win.loadURL(developmentUrl)
mainWindow.loadURL(developmentUrl)
})

win.webContents.openDevTools()
mainWindow.webContents.openDevTools()
}

const setupProduction = () => {
win.loadURL(productionPath)
win.setMenu(null)
mainWindow.loadURL(productionPath)
mainWindow.setMenu(null)
}

if (isDevelopment) {
Expand All @@ -78,53 +81,56 @@ function createWindow () {
}

const handleReadyToShow = () => {
win.setMinimumSize(width, height)
win.show()
mainWindow.setMinimumSize(width, height)
mainWindow.show()
}

const handleClose = event => {
event.preventDefault()

win.hide()
mainWindow.hide()
}

win.on('ready-to-show', handleReadyToShow)
win.on('close', handleClose)
mainWindow.on('ready-to-show', handleReadyToShow)
mainWindow.on('close', handleClose)

const handleNewWindow = event => {
event.preventDefault()
}

win.webContents.on(
mainWindow.webContents.on(
'new-window',
handleNewWindow
)
}

function createTray () {
tray = new Tray(iconPath)

const handleCloseClick = () => {
function createTrayOrDock () {
const handleQuitClick = () => {
app.exit()
}

const menuItems = [
const menu = Menu.buildFromTemplate([
{
type: 'normal',
label: 'Close',
click: handleCloseClick
label: 'Quit',
click: handleQuitClick
}
]
const menu = Menu.buildFromTemplate(menuItems)
])

if (isOSX) {
app.dock.setMenu(menu)
} else {
tray = new Tray(iconPath)

tray.setContextMenu(menu)
tray.setToolTip(appName)
tray.setContextMenu(menu)
tray.setToolTip(appName)

const handleClick = () => {
win.show()
}
const handleTrayIconClick = () => {
mainWindow.show()
}

tray.on('click', handleClick)
tray.on('click', handleTrayIconClick)
}
}

function createHeadersHandler () {
Expand All @@ -150,7 +156,7 @@ function setup () {
ElectronStore.initRenderer()

createWindow()
createTray()
createTrayOrDock()
createHeadersHandler()
}

Expand All @@ -162,11 +168,22 @@ function handleAllWindowsClose (event) {
event.preventDefault()
}

function handleActivate () {
isAnyWindowsOpen =
!!BrowserWindow.getAllWindows().length

if (!isAnyWindowsOpen) {
createWindow()
}
}

app.on(
'window-all-closed',
handleAllWindowsClose
)

app.on('activate', handleActivate)

function handleSetTrayTooltip (event, value) {
tray.setToolTip(value)
}
Expand Down
3 changes: 1 addition & 2 deletions src/components/layout/TheSearchModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ export default {
mounted () {
Mousetrap.bind(
'mod+f',
this.handleSearchCall,
'keyup'
this.handleSearchCall
)
},
methods: {
Expand Down

0 comments on commit 9e45833

Please sign in to comment.