Added 'show' & 'hide' events to browser-window, fixed visibilitychange event in renderer
This commit is contained in:
parent
ee61ab2d26
commit
c1267b2320
8 changed files with 88 additions and 60 deletions
|
@ -20,7 +20,7 @@ BrowserWindow.prototype._init = function() {
|
|||
}
|
||||
|
||||
// Make new windows requested by links behave like "window.open"
|
||||
this.webContents.on('-new-window', function(event, url, frameName) {
|
||||
this.webContents.on('-new-window', (event, url, frameName) => {
|
||||
var options;
|
||||
options = {
|
||||
show: true,
|
||||
|
@ -32,27 +32,21 @@ BrowserWindow.prototype._init = function() {
|
|||
|
||||
// window.resizeTo(...)
|
||||
// window.moveTo(...)
|
||||
this.webContents.on('move', (function(_this) {
|
||||
return function(event, size) {
|
||||
return _this.setBounds(size);
|
||||
};
|
||||
})(this));
|
||||
this.webContents.on('move', (event, title) => {
|
||||
return this.setBounds(size);
|
||||
});
|
||||
|
||||
// Hide the auto-hide menu when webContents is focused.
|
||||
this.webContents.on('activate', (function(_this) {
|
||||
return function() {
|
||||
if (process.platform !== 'darwin' && _this.isMenuBarAutoHide() && _this.isMenuBarVisible()) {
|
||||
return _this.setMenuBarVisibility(false);
|
||||
}
|
||||
};
|
||||
})(this));
|
||||
this.webContents.on('activate', () => {
|
||||
if (process.platform !== 'darwin' && this.isMenuBarAutoHide() && this.isMenuBarVisible()) {
|
||||
return this.setMenuBarVisibility(false);
|
||||
}
|
||||
});
|
||||
|
||||
// Forward the crashed event.
|
||||
this.webContents.on('crashed', (function(_this) {
|
||||
return function() {
|
||||
return _this.emit('crashed');
|
||||
};
|
||||
})(this));
|
||||
this.webContents.on('crashed', () => {
|
||||
return this.emit('crashed');
|
||||
});
|
||||
|
||||
// Change window title to page title.
|
||||
this.webContents.on('page-title-updated', (event, title) => {
|
||||
|
@ -77,48 +71,40 @@ BrowserWindow.prototype._init = function() {
|
|||
});
|
||||
|
||||
// Redirect focus/blur event to app instance too.
|
||||
this.on('blur', (function(_this) {
|
||||
return function(event) {
|
||||
return app.emit('browser-window-blur', event, _this);
|
||||
};
|
||||
})(this));
|
||||
this.on('focus', (function(_this) {
|
||||
return function(event) {
|
||||
return app.emit('browser-window-focus', event, _this);
|
||||
};
|
||||
})(this));
|
||||
this.on('blur', (event) => {
|
||||
return app.emit('browser-window-blur', event, this);
|
||||
});
|
||||
this.on('focus', (event) => {
|
||||
return app.emit('browser-window-focus', event, 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));
|
||||
this.on('show', () => {
|
||||
return this.webContents.send('ATOM_RENDERER_WINDOW_VISIBILITY_CHANGE', true, this.isMinimized());
|
||||
});
|
||||
this.on('hide', () => {
|
||||
return this.webContents.send('ATOM_RENDERER_WINDOW_VISIBILITY_CHANGE', false, this.isMinimized());
|
||||
});
|
||||
this.on('minimize', () => {
|
||||
return this.webContents.send('ATOM_RENDERER_WINDOW_VISIBILITY_CHANGE', this.isVisible(), true);
|
||||
});
|
||||
this.on('restore', () => {
|
||||
return this.webContents.send('ATOM_RENDERER_WINDOW_VISIBILITY_CHANGE', this.isVisible(), false);
|
||||
});
|
||||
|
||||
// Notify the creation of the window.
|
||||
app.emit('browser-window-created', {}, this);
|
||||
|
||||
// Be compatible with old APIs.
|
||||
this.webContents.on('devtools-focused', (function(_this) {
|
||||
return function() {
|
||||
return _this.emit('devtools-focused');
|
||||
};
|
||||
})(this));
|
||||
this.webContents.on('devtools-opened', (function(_this) {
|
||||
return function() {
|
||||
return _this.emit('devtools-opened');
|
||||
};
|
||||
})(this));
|
||||
this.webContents.on('devtools-closed', (function(_this) {
|
||||
return function() {
|
||||
return _this.emit('devtools-closed');
|
||||
};
|
||||
})(this));
|
||||
this.webContents.on('devtools-focused', () => {
|
||||
return this.emit('devtools-focused');
|
||||
});
|
||||
this.webContents.on('devtools-opened', () => {
|
||||
return this.emit('devtools-opened');
|
||||
});
|
||||
this.webContents.on('devtools-closed', () => {
|
||||
return this.emit('devtools-closed');
|
||||
});
|
||||
return Object.defineProperty(this, 'devToolsWebContents', {
|
||||
enumerable: true,
|
||||
configurable: false,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue