]> khamidou — GitHub mirrors - electron.git/commitdiff
Focus WebContents when we first load url in BrowserWindow
authorCheng Zhao <zcbenz@gmail.com>
Fri, 24 Jul 2015 05:00:03 +0000 (13:00 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Fri, 24 Jul 2015 05:08:19 +0000 (13:08 +0800)
atom/browser/api/lib/browser-window.coffee
atom/browser/api/lib/navigation-controller.coffee

index e7a79d99fcbac4ae55945718825835668d8072de..68b5932a93b49c82468df38238d9e35572eef6a1 100644 (file)
@@ -30,6 +30,15 @@ BrowserWindow::_init = ->
   @webContents.on 'crashed', =>
     @emit 'crashed'
 
+  # Sometimes the webContents doesn't get focus when window is shown, so we have
+  # to force focusing on webContents in this case. The safest way is to focus it
+  # when we first start to load URL, if we do it earlier it won't have effect,
+  # if we do it later we might move focus in the page.
+  # Though this hack is only needed on OS X when the app is launched from
+  # Finder, we still do it on all platforms in case of other bugs we don't know.
+  @webContents.once 'load-url', ->
+    @focus()
+
   # Redirect focus/blur event to app instance too.
   @on 'blur', (event) =>
     app.emit 'browser-window-blur', event, this
index 3c8089d9c6fa32352d400757a2015a129a41f26d..a985931f47161a44823460e51644900eb0d77158 100644 (file)
@@ -40,6 +40,7 @@ class NavigationController
   loadUrl: (url, options={}) ->
     @pendingIndex = -1
     @webContents._loadUrl url, options
+    @webContents.emit 'load-url', url, options
 
   getUrl: ->
     if @currentIndex is -1