{"size": 1482, "ext": "js", "max_stars_repo_path": "MainApp.js", "max_stars_repo_name": "easylogic/openproxy-ui", "max_stars_repo_stars_event_min_datetime": "2016-12-25T15:15:41.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-13T23:34:07.000Z", "max_issues_repo_path": "MainApp.js", "max_issues_repo_name": "easylogic/openproxy-ui", "max_issues_repo_issues_event_min_datetime": "2017-01-03T17:33:11.000Z", "max_issues_repo_issues_event_max_datetime": "2017-01-03T17:33:11.000Z", "max_forks_repo_path": "MainApp.js", "max_forks_repo_name": "easylogic/openproxy-ui", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 13, "max_issues_count": 1, "max_forks_count": null, "avg_line_length": 26.4642857143, "max_line_length": 112, "alphanum_fraction": 0.5904183536}
const fs = require('fs');
const path = require('path');
const { app, Menu } = require('electron');
const MainPlugin = require('./lib/MainPlugin');

module.exports = class App extends MainPlugin {
    constructor(options) {
        super(Object.assign({
            name : 'app'
        }, options || {}));

        this.plugin_root = __dirname + "/plugin";
        this.plugin_instances = {};
        this.plugin_tables = [];

        this.loadPlugins();
    }

    loadPlugins () {
        let plugins = fs.readdirSync(this.plugin_root);
        let that = this;

        this.plugin_instances = {};
        this.plugin_tables = [];

        let plugin_root = this.plugin_root;

        plugins.forEach(function(plugin) {
            let PluginObject = JSON.parse(fs.readFileSync(path.join(plugin_root, plugin, "package.json")) + "");

            let PluginClass = require(path.join(plugin_root , plugin , "main"));

            // use directory name as plugin id
            PluginObject.id = plugin;

            that.addPlugin(PluginObject, PluginClass);
        });

        this.plugin_tables.sort(function (a, b) {
            return a.order > b.order;
        })
    }

    plugin (name) {
        return this.plugin_instances[name];
    }

    addPlugin(options, PluginClass) {
        this.plugin_instances[options.name] = new PluginClass(options);
        this.plugin_tables.push(options);

        app.openproxy.addPlugin(this.plugin_instances[options.name]);
    }
}

