Add Window class and options plugin decoration (#3485)

* Add Window class and optios plugin decoration

* Propatation to BrowserWindow
This commit is contained in:
Philippe Potvin 2019-03-02 17:09:15 -05:00 committed by GitHub
parent 1747c57bc3
commit 2d399baa87
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 1 deletions

View file

@ -19,7 +19,6 @@ const checkSquirrel = () => {
squirrel = require('electron-squirrel-startup'); squirrel = require('electron-squirrel-startup');
//eslint-disable-next-line no-empty //eslint-disable-next-line no-empty
} catch (err) {} } catch (err) {}
if (squirrel) { if (squirrel) {
// eslint-disable-next-line unicorn/no-process-exit // eslint-disable-next-line unicorn/no-process-exit
process.exit(); process.exit();

View file

@ -318,6 +318,20 @@ exports.onApp = app_ => {
}); });
}; };
exports.onWindowClass = win => {
modules.forEach(plugin => {
if (plugin.onWindowClass) {
try {
plugin.onWindowClass(win);
} catch (e) {
notify('Plugin error!', `"${plugin._name}" has encountered an error. Check Developer Tools for details.`, {
error: e
});
}
}
});
};
exports.onWindow = win => { exports.onWindow = win => {
modules.forEach(plugin => { modules.forEach(plugin => {
if (plugin.onWindow) { if (plugin.onWindow) {
@ -417,6 +431,10 @@ exports.getDecoratedBrowserOptions = defaults => {
return decorateObject(defaults, 'decorateBrowserOptions'); return decorateObject(defaults, 'decorateBrowserOptions');
}; };
exports.decorateWindowClass = defaults => {
return decorateObject(defaults, 'decorateWindowClass');
};
exports.decorateSessionOptions = defaults => { exports.decorateSessionOptions = defaults => {
return decorateObject(defaults, 'decorateSessionOptions'); return decorateObject(defaults, 'decorateSessionOptions');
}; };

View file

@ -1,6 +1,8 @@
module.exports = { module.exports = {
availableExtensions: new Set([ availableExtensions: new Set([
'onApp', 'onApp',
'onWindowClass',
'decorateWindowClass',
'onWindow', 'onWindow',
'onRendererWindow', 'onRendererWindow',
'onUnload', 'onUnload',

View file

@ -18,6 +18,12 @@ const {decorateSessionOptions, decorateSessionClass} = require('../plugins');
module.exports = class Window { module.exports = class Window {
constructor(options_, cfg, fn) { constructor(options_, cfg, fn) {
const classOpts = Object.assign({uid: uuid.v4()});
app.plugins.decorateWindowClass(classOpts);
this.uid = classOpts.uid;
app.plugins.onWindowClass(this);
const winOpts = Object.assign( const winOpts = Object.assign(
{ {
minWidth: 370, minWidth: 370,
@ -34,7 +40,10 @@ module.exports = class Window {
}, },
options_ options_
); );
const window = new BrowserWindow(app.plugins.getDecoratedBrowserOptions(winOpts)); const window = new BrowserWindow(app.plugins.getDecoratedBrowserOptions(winOpts));
window.uid = classOpts.uid;
const rpc = createRPC(window); const rpc = createRPC(window);
const sessions = new Map(); const sessions = new Map();