Browse Source

Add menu for open Dev Tools and Chrome Dev Tools

master
Loëck Vézien 7 years ago
parent
commit
bda2c52a0e
No known key found for this signature in database GPG Key ID: CBCDCE384E853AC4
  1. 32
      src/main/app.js
  2. 73
      src/main/menu.js

32
src/main/app.js

@ -24,6 +24,16 @@ const getWindowPosition = (height, width, display = screen.getPrimaryDisplay())
} }
} }
const handleCloseWindow = w => e => {
if (!forceClose) {
e.preventDefault()
if (w !== null) {
w.hide()
}
}
}
const getDefaultUrl = () => const getDefaultUrl = () =>
__DEV__ __DEV__
? `http://localhost:${process.env.ELECTRON_WEBPACK_WDS_PORT || ''}` ? `http://localhost:${process.env.ELECTRON_WEBPACK_WDS_PORT || ''}`
@ -89,22 +99,16 @@ function createMainWindow() {
const url = getDefaultUrl() const url = getDefaultUrl()
if (devTools) { if (devTools) {
window.webContents.openDevTools() window.webContents.openDevTools({
mode: 'detach',
})
} }
saveWindowSettings(window) saveWindowSettings(window)
window.loadURL(url) window.loadURL(url)
window.on('close', e => { window.on('close', handleCloseWindow(window))
if (!forceClose) {
e.preventDefault()
if (mainWindow !== null) {
mainWindow.hide()
}
}
})
window.webContents.on('devtools-opened', () => { window.webContents.on('devtools-opened', () => {
window.focus() window.focus()
@ -120,16 +124,16 @@ function createDevWindow() {
const MIN_HEIGHT = 500 const MIN_HEIGHT = 500
const MIN_WIDTH = 360 const MIN_WIDTH = 360
const savedDimensions = db.getIn('settings', 'window.DevWindow.dimensions', {})
const savedPositions = db.getIn('settings', 'window.DevWindow.positions', null) const savedPositions = db.getIn('settings', 'window.DevWindow.positions', null)
const width = savedDimensions.width || MIN_WIDTH const width = MIN_WIDTH
const height = savedDimensions.height || MIN_HEIGHT const height = MIN_HEIGHT
const windowOptions = { const windowOptions = {
...defaultWindowOptions, ...defaultWindowOptions,
...(savedPositions !== null ? savedPositions : {}), ...(savedPositions !== null ? savedPositions : {}),
fullscreenable: false, fullscreenable: false,
resizable: false,
height, height,
minHeight: MIN_HEIGHT, minHeight: MIN_HEIGHT,
minWidth: MIN_WIDTH, minWidth: MIN_WIDTH,
@ -149,6 +153,8 @@ function createDevWindow() {
window.loadURL(`${url}/#/dev`) window.loadURL(`${url}/#/dev`)
window.on('close', handleCloseWindow(window))
window.on('ready-to-show', () => { window.on('ready-to-show', () => {
window.show() window.show()
}) })

73
src/main/menu.js

@ -1,30 +1,69 @@
import { app, Menu } from 'electron' import { BrowserWindow, app, Menu } from 'electron'
const props = (predicate, values, defaultValue = {}) => (predicate ? values : defaultValue)
const template = [ const template = [
...(process.platform === 'darwin' ...props(
? [ process.platform === 'darwin',
{ [
label: app.getName(), {
submenu: [ label: app.getName(),
{ role: 'hide' }, submenu: [
{ role: 'hideothers' }, { role: 'hide' },
{ role: 'unhide' }, { role: 'hideothers' },
{ role: 'unhide' },
{ type: 'separator' },
{ role: 'quit' },
],
},
],
[],
),
...props(process.platform === 'darwin' || __DEV__, [
{
role: 'window',
submenu: [
...props(
__DEV__,
[
{
label: 'App Dev Tools',
click() {
const devWindow = BrowserWindow.getAllWindows().find(w => w.name === 'DevWindow')
if (devWindow) {
devWindow.show()
}
},
},
{
label: 'Main Window Dev Tools',
click() {
const mainWindow = BrowserWindow.getAllWindows().find(w => w.name === 'MainWindow')
if (mainWindow) {
mainWindow.openDevTools({
mode: 'detach',
})
}
},
},
{ type: 'separator' }, { type: 'separator' },
{ role: 'quit' },
], ],
}, [],
{ ),
role: 'window', ...props(
submenu: [ process.platform === 'darwin',
[
{ role: 'close' }, { role: 'close' },
{ role: 'minimize' }, { role: 'minimize' },
{ role: 'zoom' }, { role: 'zoom' },
{ type: 'separator' }, { type: 'separator' },
{ role: 'front' }, { role: 'front' },
], ],
}, [],
] ),
: []), ],
},
]),
] ]
export default Menu.buildFromTemplate(template) export default Menu.buildFromTemplate(template)

Loading…
Cancel
Save