var fs = require('fs-extra'),
    Path = require('path'),
    Url = require('url'),
    {BrowserWindow} = require('electron');

var Window = {
    openWindows: {}, // Keeps track of all open BrowserWindow's
    availableWindows: {}, // Stores all available windows to work with as JSON

    Open: function(windowName, template, events) {
        var window = Window.availableWindows[windowName];
        if(!window) return false; // A window by the specified name does not exist

        // The window.path is relative to the /views directory, but we are not
        var viewPath = Path.join(__dirname, '..', 'views', window.path);

        // If the requested view does not exist, exit
        if(!fs.existsSync(viewPath)) {
            console.log('Error opening new window: could not find view', viewPath);
            return false;
        }

        // If the window is already open and multiple are not allowed,
        // do not open another window
        if(!window.allowMultiple && Window.openWindows[windowName]) {
            Window.openWindows[windowName].focus(); // Bring the opened window to front-view
            return false;
        }

        // Indicate if this view uses Handlebars
        const isHandlebars =
            window.path.endsWith('.hbs') ||
            window.path.endsWith('.handlebars') ||
            window.requiresTemplate || // window specifies it needs a template
            template; // if we provide a template to an HTML file

        // Otherwise we create a new window
        var windowOptions = window;
        if(windowOptions.parent) {
            if(windowOptions.parent === '__root') {
                console.log('TODO: set window root');
                //windowOptions.parent = openWindows.root;
            }
            else {
                windowOptions.parent = Window.openWindows[windowOptions.parent];
            }
        }
        windowOptions.webPreferences = {
            // Set preload on all windows to run the global-script
            // so globals are available to every window via `globals` variable
            preload: Path.join(__dirname, '../preload.js')
        }

        var newWindow = new BrowserWindow(windowOptions); // Create a new window
        Window.openWindows[windowName] = newWindow; // Register the new window

        // Encode any template data in the POST body
        var addlData = {};
        if(isHandlebars && template) {
            addlData = {
                // Encode handlebars template in post data
                postData: [{
                    type: 'rawData',
                    bytes: Buffer.from(JSON.stringify(template))
                }],
                extraHeaders: 'Content-Type: application/x-www-form-urlencoded'
            };
        }

        // Load the window with the specified view
        newWindow.loadURL(
            Url.format({
                pathname: viewPath,
                protocol: (isHandlebars) ? 'hbs:' : 'file:',
                slashes: true
            }),
            addlData
        );

        // Always open dev tools
        newWindow.webContents.openDevTools();

        // Iterate over events and add a new one to the window for each
        if(events) {
            Object.keys(events).forEach((event) => {
                newWindow.on(event, () => {
                    events[event]();
                });
            });
        }

        // We always handle the closed event
        newWindow.on('closed', () => {
            delete Window.openWindows[windowName];
        });
    },

    Broadcast: function(eventName, data) {
        console.log('[ Event ]', eventName);

        Object.keys(Window.openWindows).forEach((window) => {
            Window.openWindows[window].webContents.send(eventName, data);
        })
    }
}

function loadWindowsFromDir() {
    var windowsPath = Path.resolve(__dirname, '..', 'windows'),
        windowManifests = fs.readdirSync(windowsPath);

    windowManifests.forEach((manifestPath) => {
        var manifest = fs.readJsonSync(Path.resolve(windowsPath, manifestPath));
        Window.availableWindows[manifest.name] = manifest;
    });
}

loadWindowsFromDir();
console.log('Loaded ' + Object.keys(Window.availableWindows).length + ' windows');
module.exports = Window;

@@ -3552,16 +3552,214 @@
     %7D,%0A%0A
+    SendMessage: function(windowName, eventName, data) %7B%0A        if(Window.openWindows%5BwindowName%5D) %7B%0A            Window.openWindows%5BwindowName%5D.webContents.send(eventName, data);%0A        %7D%0A    %7D,%0A%0A
     Broa

Create new method to send a message to an individual window