Summary: Refactors the plugin architecture of Sonar: - Before plugin rendering had it's own implementation of the react lifecycle. This means the `render`-function was not called by react, but rather by the application it self. In this diff, the render method is now called from react, which enables better debugging and allows react to do optimizations. - Business logic for querying emulators is moved away from the view components into its own dispatcher - All plugin handling is moved from `App.js` to `PluginContainer`. - The sidebar only shows one selected device. This allows us to add the screenshot feature as part of the Sonar main app and not a plugin. - This also fixes the inconsistency between the devices button and the sidebar Reviewed By: jknoxville Differential Revision: D8186933 fbshipit-source-id: 46404443025bcf18d6eeba0679e098d5440822d5
77 lines
1.8 KiB
JavaScript
77 lines
1.8 KiB
JavaScript
/**
|
|
* Copyright 2018-present Facebook.
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
* @format
|
|
*/
|
|
|
|
import {GK} from 'sonar';
|
|
import React from 'react';
|
|
import ReactDOM from 'react-dom';
|
|
import * as Sonar from 'sonar';
|
|
import {SonarPlugin, SonarBasePlugin} from '../plugin.js';
|
|
|
|
const plugins = new Map();
|
|
|
|
// expose Sonar and exact globally for dynamically loaded plugins
|
|
window.React = React;
|
|
window.ReactDOM = ReactDOM;
|
|
window.Sonar = Sonar;
|
|
|
|
const addIfNotAdded = plugin => {
|
|
if (!plugins.has(plugin.name)) {
|
|
plugins.set(plugin.name, plugin);
|
|
}
|
|
};
|
|
|
|
let disabledPlugins = [];
|
|
try {
|
|
disabledPlugins =
|
|
JSON.parse(window.process.env.CONFIG || '{}').disabledPlugins || [];
|
|
} catch (e) {
|
|
console.error(e);
|
|
}
|
|
|
|
// Load dynamic plugins
|
|
try {
|
|
JSON.parse(window.process.env.PLUGINS || '[]').forEach(addIfNotAdded);
|
|
} catch (e) {
|
|
console.error(e);
|
|
}
|
|
|
|
// DefaultPlugins that are included in the bundle.
|
|
// List of defaultPlugins is written at build time
|
|
let bundledPlugins = [];
|
|
try {
|
|
bundledPlugins = window.electronRequire('./defaultPlugins/index.json');
|
|
} catch (e) {}
|
|
bundledPlugins
|
|
.map(plugin => ({
|
|
...plugin,
|
|
out: './' + plugin.out,
|
|
}))
|
|
.forEach(addIfNotAdded);
|
|
|
|
const exportedPlugins: Array<Class<SonarPlugin<>>> = Array.from(
|
|
plugins.values(),
|
|
)
|
|
.map(plugin => {
|
|
if (
|
|
(plugin.gatekeeper && !GK.get(plugin.gatekeeper)) ||
|
|
disabledPlugins.indexOf(plugin.name) > -1
|
|
) {
|
|
return null;
|
|
} else {
|
|
try {
|
|
return window.electronRequire(plugin.out);
|
|
} catch (e) {
|
|
console.error(plugin, e);
|
|
return null;
|
|
}
|
|
}
|
|
})
|
|
.filter(Boolean)
|
|
.filter(plugin => plugin.prototype instanceof SonarBasePlugin);
|
|
|
|
export default exportedPlugins;
|