From: Cheng Zhao Date: Fri, 24 Jul 2015 05:00:03 +0000 (+0800) Subject: Focus WebContents when we first load url in BrowserWindow X-Git-Tag: v0.30.1~3^2 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=29c574cf0f573eeac0b382961572b69888415197;p=electron.git Focus WebContents when we first load url in BrowserWindow --- diff --git a/atom/browser/api/lib/browser-window.coffee b/atom/browser/api/lib/browser-window.coffee index e7a79d99..68b5932a 100644 --- a/atom/browser/api/lib/browser-window.coffee +++ b/atom/browser/api/lib/browser-window.coffee @@ -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 diff --git a/atom/browser/api/lib/navigation-controller.coffee b/atom/browser/api/lib/navigation-controller.coffee index 3c8089d9..a985931f 100644 --- a/atom/browser/api/lib/navigation-controller.coffee +++ b/atom/browser/api/lib/navigation-controller.coffee @@ -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