mirror of
https://github.com/balena-io/etcher.git
synced 2025-07-17 08:16:32 +00:00
fix(gui): Fix DevTools opening in docked mode
This fixes the Developer Tools opening in docked mode by default. Change-Type: patch
This commit is contained in:
parent
df2ebf93b6
commit
a5aaf760d0
@ -19,6 +19,7 @@
|
|||||||
const electron = require('electron')
|
const electron = require('electron')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const EXIT_CODES = require('../shared/exit-codes')
|
const EXIT_CODES = require('../shared/exit-codes')
|
||||||
|
const buildWindowMenu = require('./menu')
|
||||||
let mainWindow = null
|
let mainWindow = null
|
||||||
|
|
||||||
electron.app.on('window-all-closed', electron.app.quit)
|
electron.app.on('window-all-closed', electron.app.quit)
|
||||||
@ -34,8 +35,6 @@ electron.app.on('before-quit', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
electron.app.on('ready', () => {
|
electron.app.on('ready', () => {
|
||||||
electron.Menu.setApplicationMenu(require('./menu'))
|
|
||||||
|
|
||||||
mainWindow = new electron.BrowserWindow({
|
mainWindow = new electron.BrowserWindow({
|
||||||
width: 800,
|
width: 800,
|
||||||
height: 380,
|
height: 380,
|
||||||
@ -50,6 +49,8 @@ electron.app.on('ready', () => {
|
|||||||
icon: path.join(__dirname, '..', '..', 'assets', 'icon.png')
|
icon: path.join(__dirname, '..', '..', 'assets', 'icon.png')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
buildWindowMenu(mainWindow)
|
||||||
|
|
||||||
// Prevent flash of white when starting the application
|
// Prevent flash of white when starting the application
|
||||||
mainWindow.on('ready-to-show', mainWindow.show)
|
mainWindow.on('ready-to-show', mainWindow.show)
|
||||||
|
|
||||||
|
213
lib/gui/menu.js
213
lib/gui/menu.js
@ -19,99 +19,130 @@
|
|||||||
const electron = require('electron')
|
const electron = require('electron')
|
||||||
const packageJson = require('../../package.json')
|
const packageJson = require('../../package.json')
|
||||||
|
|
||||||
const menuTemplate = [
|
/* eslint-disable no-magic-numbers */
|
||||||
{
|
|
||||||
role: 'editMenu'
|
/**
|
||||||
},
|
* @summary Builds a native application menu for a given window
|
||||||
{
|
* @param {electron.BrowserWindow} window - BrowserWindow instance
|
||||||
label: 'View',
|
* @example
|
||||||
submenu: [
|
* buildWindowMenu(mainWindow)
|
||||||
{
|
*/
|
||||||
role: 'toggledevtools',
|
const buildWindowMenu = (window) => {
|
||||||
click () {
|
/**
|
||||||
const window = electron.BrowserWindow.getFocusedWindow()
|
* @summary Toggle the main window's devtools
|
||||||
if (window) {
|
* @example
|
||||||
window.webContents.openDevTools({
|
* toggleDevTools()
|
||||||
mode: 'detach'
|
*/
|
||||||
})
|
const toggleDevTools = () => {
|
||||||
|
if (!window) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// NOTE: We can't use `webContents.toggleDevTools()` here,
|
||||||
|
// as we need to force detached mode
|
||||||
|
if (window.webContents.isDevToolsOpened()) {
|
||||||
|
window.webContents.closeDevTools()
|
||||||
|
} else {
|
||||||
|
window.webContents.openDevTools({
|
||||||
|
mode: 'detach'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @summary Open the main window's settings page
|
||||||
|
* @example
|
||||||
|
* showSettings()
|
||||||
|
*/
|
||||||
|
const showSettings = () => {
|
||||||
|
if (window) {
|
||||||
|
window.webContents.send('menu:preferences')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const menuTemplate = [
|
||||||
|
{
|
||||||
|
role: 'editMenu'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'View',
|
||||||
|
submenu: [
|
||||||
|
{
|
||||||
|
label: 'Toggle Developer Tools',
|
||||||
|
accelerator: process.platform === 'darwin'
|
||||||
|
? 'Command+Alt+I' : 'Control+Shift+I',
|
||||||
|
click: toggleDevTools
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
role: 'windowMenu'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
role: 'help',
|
||||||
|
submenu: [
|
||||||
|
{
|
||||||
|
label: 'Etcher Pro',
|
||||||
|
click () {
|
||||||
|
electron.shell.openExternal('https://etcher.io/pro')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Etcher Website',
|
||||||
|
click () {
|
||||||
|
electron.shell.openExternal('https://etcher.io')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Report an issue',
|
||||||
|
click () {
|
||||||
|
electron.shell.openExternal('https://github.com/resin-io/etcher/issues')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
]
|
||||||
]
|
}
|
||||||
},
|
]
|
||||||
{
|
|
||||||
role: 'windowMenu'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
role: 'help',
|
|
||||||
submenu: [
|
|
||||||
{
|
|
||||||
label: 'Etcher Pro',
|
|
||||||
click () {
|
|
||||||
electron.shell.openExternal('https://etcher.io/pro')
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: 'Etcher Website',
|
|
||||||
click () {
|
|
||||||
electron.shell.openExternal('https://etcher.io')
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: 'Report an issue',
|
|
||||||
click () {
|
|
||||||
electron.shell.openExternal('https://github.com/resin-io/etcher/issues')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|
||||||
if (process.platform === 'darwin') {
|
if (process.platform === 'darwin') {
|
||||||
menuTemplate.unshift({
|
menuTemplate.unshift({
|
||||||
label: packageJson.displayName,
|
label: packageJson.displayName,
|
||||||
submenu: [ {
|
submenu: [ {
|
||||||
role: 'about'
|
role: 'about'
|
||||||
}, {
|
}, {
|
||||||
type: 'separator'
|
type: 'separator'
|
||||||
}, {
|
}, {
|
||||||
label: 'Preferences',
|
label: 'Preferences',
|
||||||
accelerator: 'Command+,',
|
accelerator: 'Command+,',
|
||||||
click () {
|
click: showSettings
|
||||||
const window = electron.BrowserWindow.getFocusedWindow()
|
}, {
|
||||||
if (window) {
|
type: 'separator'
|
||||||
window.webContents.send('menu:preferences')
|
}, {
|
||||||
}
|
role: 'hide'
|
||||||
}
|
}, {
|
||||||
}, {
|
role: 'hideothers'
|
||||||
type: 'separator'
|
}, {
|
||||||
}, {
|
role: 'unhide'
|
||||||
role: 'hide'
|
}, {
|
||||||
}, {
|
type: 'separator'
|
||||||
role: 'hideothers'
|
}, {
|
||||||
}, {
|
role: 'quit'
|
||||||
role: 'unhide'
|
} ]
|
||||||
}, {
|
})
|
||||||
type: 'separator'
|
} else {
|
||||||
}, {
|
menuTemplate.unshift({
|
||||||
role: 'quit'
|
label: packageJson.displayName,
|
||||||
} ]
|
submenu: [ {
|
||||||
})
|
label: 'Settings',
|
||||||
} else {
|
click: showSettings
|
||||||
menuTemplate.unshift({
|
}, {
|
||||||
label: packageJson.displayName,
|
role: 'quit'
|
||||||
submenu: [ {
|
} ]
|
||||||
label: 'Settings',
|
})
|
||||||
click () {
|
}
|
||||||
const window = electron.BrowserWindow.getFocusedWindow()
|
|
||||||
if (window) {
|
const menu = electron.Menu.buildFromTemplate(menuTemplate)
|
||||||
window.webContents.send('menu:preferences')
|
|
||||||
}
|
electron.Menu.setApplicationMenu(menu)
|
||||||
}
|
|
||||||
}, {
|
|
||||||
role: 'quit'
|
|
||||||
} ]
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = electron.Menu.buildFromTemplate(menuTemplate)
|
module.exports = buildWindowMenu
|
||||||
|
Loading…
x
Reference in New Issue
Block a user