clean up dynamic plugin loading

Summary:
There are 3 sources where plugins can be loaded from:
* `src/plugins`
* `src/fb/plugins`
* any path specified in `~/.sonar/config.json`

Plugins found in the first two directories are bundled with the app when building.

Reviewed By: jknoxville

Differential Revision: D8636061

fbshipit-source-id: 2064090d43d11695ffd99df195e5b594559fe087
This commit is contained in:
Daniel Büchele
2018-06-26 07:10:57 -07:00
committed by Facebook Github Bot
parent 70e11e8269
commit 5edb8bd770
9 changed files with 31 additions and 91 deletions

View File

@@ -1,47 +0,0 @@
/**
* 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 electron from 'electron';
const DP_ARG = '--dynamicPlugins=';
/* Sometimes remote objects are missing intermittently. To reduce the chance of
* this being a problem while in use. Only read it once at startup.
* https://github.com/electron/electron/issues/8205 */
const _argv = electron.remote.process.argv;
const _loadsDynamicPlugins =
_argv.findIndex(arg => arg.startsWith(DP_ARG)) > -1;
const _isProduction = !/node_modules[\\/]electron[\\/]/.test(
electron.remote.process.execPath,
);
export function isProduction(): boolean {
return _isProduction;
}
export function loadsDynamicPlugins(): boolean {
return _loadsDynamicPlugins;
}
export function toggleDynamicPluginLoading() {
const args = _argv.filter(arg => !arg.startsWith(DP_ARG));
if (!loadsDynamicPlugins()) {
args.push(DP_ARG + '~/fbsource/xplat/sonar/src/plugins');
}
const {app} = electron.remote;
app.relaunch({args: args.slice(1).concat(['--relaunch'])});
app.exit(0);
}
export function dynamicPluginPath(): ?string {
const index = _argv.findIndex(arg => arg.startsWith(DP_ARG));
if (index > -1) {
return _argv[index].replace(DP_ARG, '');
} else {
null;
}
}

16
src/utils/isProduction.js Normal file
View File

@@ -0,0 +1,16 @@
/**
* 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 electron from 'electron';
const _isProduction = !/node_modules[\\/]electron[\\/]/.test(
electron.remote.process.execPath,
);
export default function isProduction(): boolean {
return _isProduction;
}