mirror of
https://github.com/scratchfoundation/scratch-desktop.git
synced 2024-12-22 21:52:31 -05:00
fix: use ELECTRON_WEBPACK_WDS_PORT env instead of hardcoded webpack-dev-server port number
Focus main window if dev tool window opened on start
This commit is contained in:
parent
f1310556fb
commit
2cc0d0c32f
1 changed files with 17 additions and 8 deletions
|
@ -8,26 +8,35 @@ const isDevelopment = process.env.NODE_ENV !== 'production'
|
||||||
// Necessary to prevent win from being garbage collected
|
// Necessary to prevent win from being garbage collected
|
||||||
let mainWindow
|
let mainWindow
|
||||||
|
|
||||||
function createMainWindow () {
|
function createMainWindow() {
|
||||||
// Construct new BrowserWindow
|
// Construct new BrowserWindow
|
||||||
let win = new BrowserWindow()
|
const window = new BrowserWindow()
|
||||||
|
|
||||||
// Set url for `win`
|
// Set url for `win`
|
||||||
// points to `webpack-dev-server` in development
|
// points to `webpack-dev-server` in development
|
||||||
// points to `index.html` in production
|
// points to `index.html` in production
|
||||||
let url = isDevelopment
|
const url = isDevelopment
|
||||||
? 'http://localhost:9080'
|
? `http://localhost:${process.env.ELECTRON_WEBPACK_WDS_PORT}`
|
||||||
: `file://${__dirname}/index.html`
|
: `file://${__dirname}/index.html`
|
||||||
|
|
||||||
if (isDevelopment) win.webContents.openDevTools()
|
if (isDevelopment) {
|
||||||
|
window.webContents.openDevTools()
|
||||||
|
}
|
||||||
|
|
||||||
win.loadURL(url)
|
window.loadURL(url)
|
||||||
|
|
||||||
win.on('closed', () => {
|
window.on('closed', () => {
|
||||||
mainWindow = null
|
mainWindow = null
|
||||||
})
|
})
|
||||||
|
|
||||||
return win
|
window.webContents.on('devtools-opened', () => {
|
||||||
|
window.focus()
|
||||||
|
setImmediate(() => {
|
||||||
|
window.focus()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
return window
|
||||||
}
|
}
|
||||||
|
|
||||||
// Quit application when all windows are closed
|
// Quit application when all windows are closed
|
||||||
|
|
Loading…
Reference in a new issue