Electron-vue: Question: is there a way to disable auto focus of electron app after "npm run dev"

Created on 14 Jun 2017  路  5Comments  路  Source: SimulatedGREG/electron-vue

Hello, I've got tired of getting constantly switched to electron app window after I run npm run dev or make some changes in source code. Is there some way to disable this behaviour?

System

  • Node version: 8.1.0
  • NPM version: 5.0.3
  • vue-cli version: 2.8.2
  • Operating System: Mac OS 10.12.5
question

Most helpful comment

@imomaliev

You can simply change the BrowserWindow API used to mainWindow.showInactive() and set show to false in the constructor options.

https://electron.atom.io/docs/api/browser-window/#winshowinactive

src/main/index.js

mainWindow = new BrowserWindow({
  height: 563,
  useContentSize: true,
  width: 1000,

  // disable initial window from showing
  show: false
})

// load page with url
mainWindow.loadURL(winURL)

// show window without setting focus
mainWindow.showInactive()

Hope this helps.

All 5 comments

@imomaliev

You can simply change the BrowserWindow API used to mainWindow.showInactive() and set show to false in the constructor options.

https://electron.atom.io/docs/api/browser-window/#winshowinactive

src/main/index.js

mainWindow = new BrowserWindow({
  height: 563,
  useContentSize: true,
  width: 1000,

  // disable initial window from showing
  show: false
})

// load page with url
mainWindow.loadURL(winURL)

// show window without setting focus
mainWindow.showInactive()

Hope this helps.

@SimulatedGREG Thank you! That helped. I'm learning so much)

No problem. Glad to help 馃槃

@imomaliev

You can simply change the BrowserWindow API used to mainWindow.showInactive() and set show to false in the constructor options.

electron.atom.io/docs/api/browser-window/#winshowinactive

src/main/index.js

mainWindow = new BrowserWindow({
  height: 563,
  useContentSize: true,
  width: 1000,

  // disable initial window from showing
  show: false
})

// load page with url
mainWindow.loadURL(winURL)

// show window without setting focus
mainWindow.showInactive()

Hope this helps.

@SimulatedGREG what if we want to make the window visible but don't want the window to grab focus ?

@SimulatedGREG what if we want to make the window visible but don't want the window to grab focus ?

Actually with showInactive() it does get visible and does not grab the focus.

Was this page helpful?
0 / 5 - 0 ratings