|
@@ -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";
|
|
|
}
|
|
|
}
|
|
|
});
|