{"size": 2060, "ext": "js", "max_stars_repo_path": "scripts/main.js", "max_stars_repo_name": "pnordin/evernote-linux", "max_stars_repo_stars_event_min_datetime": "2015-09-07T03:54:37.000Z", "max_stars_repo_stars_event_max_datetime": "2015-09-07T03:54:37.000Z", "max_issues_repo_path": "scripts/main.js", "max_issues_repo_name": "pnordin/evernote-linux", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "scripts/main.js", "max_forks_repo_name": "pnordin/evernote-linux", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 24.5238095238, "max_line_length": 74, "alphanum_fraction": 0.5762135922}
var TARGET_URL = 'https://www.evernote.com/Home.action';
var MIN_HEIGHT = 600;
var CONTAINER_WIDTH = 800;
var WINDOW_TITLE = 'Evernote';

// Initialize the main window
var gui = require('nw.gui');
var mainWindow = gui.Window.get();

// Setup tray and tray menu
var tray = new gui.Tray({ title: WINDOW_TITLE, icon: 'assets/logo.png' });
var trayMenu = new gui.Menu();
var trayExit = new gui.MenuItem({ type: 'normal', label: 'Exit' });
trayMenu.append(trayExit);
tray.menu = trayMenu;

var windowMinimized = false;
var windowHidden = true;

document.title = WINDOW_TITLE;

var view = document.getElementById('view');
view.src = TARGET_URL;

var loader = document.querySelector('.loader');

view.addEventListener('load', function () {   
    var winFrame = this.contentWindow;

    loader.className = 'loader hide';

    winFrame.onbeforeunload = function(e) {
        loader.className = 'loader';
    };

    winFrame.popup = function(url, title, w, h) {
        var oldHref = window.location.href;
        var win = gui.Window.open(url, { toolbar: false,
                                         position: 'center',
                                         title: title,
                                         width: w,
                                         height: h });

        win.on('close', function() {
            this.hide();
            this.close();
            window.location.href = oldHref;
        });

        return win;
    }
});

var changeWindowState = function() {
    if (windowMinimized) {
        mainWindow.restore();
        mainWindow.focus();
        windowMinimized = false;
    } else if (windowHidden) {
        mainWindow.show();
        mainWindow.focus();
        windowHidden = false;
    } else {
        mainWindow.hide();
        windowHidden = true;
    }
};

mainWindow.on('minimize', function() {
    windowMinimized = true;
});

mainWindow.on('close', function() {
    this.close(true);
});

tray.on('click', function() {
    changeWindowState();
});

trayExit.click = function() {
    mainWindow.close(true);
};
