Expose 'getWindows' and 'createWindow' to plugins (#248)

This commit is contained in:
Cameron Spear 2016-07-18 17:11:30 -07:00 committed by Guillermo Rauch
parent 610d6c6d3e
commit 17af6cb85d

View file

@ -13,9 +13,12 @@ const config = require('./config');
config.init(); config.init();
const plugins = require('./plugins'); const plugins = require('./plugins');
const windowSet = new Set([]);
// expose to plugins // expose to plugins
app.config = config; app.config = config;
app.plugins = plugins; app.plugins = plugins;
app.getWindows = () => new Set([...windowSet]); // return a clone
if (isDev) { if (isDev) {
console.log('running in dev mode'); console.log('running in dev mode');
@ -40,7 +43,6 @@ app.on('window-all-closed', () => {
// terminal is closed // terminal is closed
}); });
let winCount = 0;
app.on('ready', () => { app.on('ready', () => {
function createWindow (fn) { function createWindow (fn) {
const cfg = plugins.getDecoratedConfig(); const cfg = plugins.getDecoratedConfig();
@ -60,7 +62,7 @@ app.on('ready', () => {
show: process.env.HYPERTERM_DEBUG || isDev show: process.env.HYPERTERM_DEBUG || isDev
}); });
winCount++; windowSet.add(win);
win.loadURL(url); win.loadURL(url);
const rpc = createRPC(win); const rpc = createRPC(win);
@ -195,7 +197,7 @@ app.on('ready', () => {
// the window can be closed by the browser process itself // the window can be closed by the browser process itself
win.on('close', () => { win.on('close', () => {
winCount--; windowSet.delete(win);
rpc.destroy(); rpc.destroy();
deleteSessions(); deleteSessions();
cfgUnsubscribe(); cfgUnsubscribe();
@ -206,11 +208,14 @@ app.on('ready', () => {
// when opening create a new window // when opening create a new window
createWindow(); createWindow();
// expose to plugins
app.createWindow = createWindow;
// mac only. when the dock icon is clicked // mac only. when the dock icon is clicked
// and we don't have any active windows open, // and we don't have any active windows open,
// we open one // we open one
app.on('activate', () => { app.on('activate', () => {
if (!winCount) { if (!windowSet.size) {
createWindow(); createWindow();
} }
}); });