diff --git a/lib/browser/api/browser-window.js b/lib/browser/api/browser-window.js index a9649f853d75..b3e27c580567 100644 --- a/lib/browser/api/browser-window.js +++ b/lib/browser/api/browser-window.js @@ -88,6 +88,18 @@ BrowserWindow.prototype._init = function() { }; })(this)); + // Evented visibilityState changes + this.on('minimize', (function(_this) { + return function() { + return _this.webContents.send('ATOM_RENDERER_WINDOW_VISIBILITY_CHANGE', false); + }; + })(this)); + this.on('restore', (function(_this) { + return function() { + return _this.webContents.send('ATOM_RENDERER_WINDOW_VISIBILITY_CHANGE', true); + }; + })(this)); + // Notify the creation of the window. app.emit('browser-window-created', {}, this); diff --git a/lib/renderer/api/ipc-renderer.js b/lib/renderer/api/ipc-renderer.js index dd614103cfaf..e946dc7a4c0a 100644 --- a/lib/renderer/api/ipc-renderer.js +++ b/lib/renderer/api/ipc-renderer.js @@ -3,7 +3,7 @@ const v8Util = process.atomBinding('v8_util'); var slice = [].slice; -// Created by init.coffee. +// Created by init.js. const ipcRenderer = v8Util.getHiddenValue(global, 'ipc'); ipcRenderer.send = function() { diff --git a/lib/renderer/inspector.js b/lib/renderer/inspector.js index edec3074b95e..d1473c7d1bed 100644 --- a/lib/renderer/inspector.js +++ b/lib/renderer/inspector.js @@ -3,7 +3,7 @@ window.onload = function() { InspectorFrontendHost.showContextMenuAtPoint = createMenu; // Use dialog API to override file chooser dialog. - return WebInspector.createFileSelectorElement = createFileSelectorElement; + return (WebInspector.createFileSelectorElement = createFileSelectorElement); }; var convertToMenuTemplate = function(items) { diff --git a/lib/renderer/override.js b/lib/renderer/override.js index 6ff1e80785d8..6a025af4ed11 100644 --- a/lib/renderer/override.js +++ b/lib/renderer/override.js @@ -3,6 +3,13 @@ const remote = require('electron').remote; var slice = [].slice; +// Cache browser window visibility +var _isVisible = (function() { + var currentWindow; + currentWindow = remote.getCurrentWindow(); + return currentWindow.isMinimized() || !currentWindow.isVisible(); +})(); + // Helper function to resolve relative url. var a = window.top.document.createElement('a'); @@ -30,7 +37,7 @@ var BrowserWindowProxy = (function() { ipcRenderer.once("ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_CLOSED_" + this.guestId, (function(_this) { return function() { BrowserWindowProxy.remove(_this.guestId); - return _this.closed = true; + return (_this.closed = true); }; })(this)); } @@ -87,7 +94,9 @@ window.open = function(url, frameName, features) { ref1 = features.split(/,\s*/); for (i = 0, len = ref1.length; i < len; i++) { feature = ref1[i]; - ref2 = feature.split(/\s*=/), name = ref2[0], value = ref2[1]; + ref2 = feature.split(/\s*=/); + name = ref2[0]; + value = ref2[1]; options[name] = value === 'yes' || value === '1' ? true : value === 'no' || value === '0' ? false : value; } if (options.left) { @@ -168,6 +177,12 @@ if (process.openerId != null) { window.opener = BrowserWindowProxy.getOrCreate(process.openerId); } +ipcRenderer.on('ATOM_RENDERER_WINDOW_VISIBILITY_CHANGE', function (event, isVisible) { + _isVisible = isVisible; + + document.dispatchEvent(new Event('visibilitychange')); +}); + ipcRenderer.on('ATOM_SHELL_GUEST_WINDOW_POSTMESSAGE', function(event, sourceId, message, sourceOrigin) { // Manually dispatch event instead of using postMessage because we also need to // set event.source. @@ -212,19 +227,15 @@ Object.defineProperty(window.history, 'length', { // Make document.hidden and document.visibilityState return the correct value. Object.defineProperty(document, 'hidden', { - get: function() { - var currentWindow; - currentWindow = remote.getCurrentWindow(); - return currentWindow.isMinimized() || !currentWindow.isVisible(); - } + get: !_isVisible }); Object.defineProperty(document, 'visibilityState', { get: function() { - if (document.hidden) { - return "hidden"; - } else { + if (_isVisible) { return "visible"; + } else { + return "hidden"; } } });