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