Skip to content

Commit

Permalink
Normalized inspector-preload path and removed unneeded code
Browse files Browse the repository at this point in the history
  • Loading branch information
justinwilaby committed May 2, 2019
1 parent f0807da commit af6c453
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 46 deletions.
Expand Up @@ -40,15 +40,14 @@ import { combineReducers, createStore } from 'redux';
import { loadBotInfos, setActiveBot } from '../../../../../data/action/botActions';
import { switchTheme } from '../../../../../data/action/themeActions';
import { bot } from '../../../../../data/reducer/bot';
import { clientAwareSettings } from '../../../../../data/reducer/clientAwareSettingsReducer';
import { theme } from '../../../../../data/reducer/themeReducer';
import { ExtensionManager } from '../../../../../extensions';
import { LogService } from '../../../../../platform/log/logService';

import { Inspector } from './inspector';
import { InspectorContainer } from './inspectorContainer';

const mockStore = createStore(combineReducers({ theme, bot, clientAwareSettings }), {});
const mockStore = createStore(combineReducers({ theme, bot }), {});

jest.mock('../../../panel/panel.scss', () => ({}));

Expand Down
Expand Up @@ -72,7 +72,6 @@ interface IpcMessageEvent extends Event {

interface InspectorProps {
document: any;
cwdAsBase: string;
themeInfo: { themeName: string; themeComponents: string[] };
activeBot?: IBotConfiguration;
botHash?: string;
Expand Down Expand Up @@ -297,21 +296,14 @@ export class Inspector extends React.Component<InspectorProps, InspectorState> {
}

private createWebView(state: InspectorState): ElectronHTMLWebViewElement {
// const { cwdAsBase } = this.props;
// const preload = `file://${cwdAsBase}/../../../node_modules/@bfemulator/client/public/inspector-preload.js`;
// const preload = `file://node_modules/@bfemulator/client/public/inspector-preload.js`;
// THIS IS A HACK!! WILL FIX LATER
const preload = state.inspector.src
.replace(/extension-.*/, 'client/public/inspector-preload.js')
.replace('asar.unpacked', 'asar');
const webView: ElectronHTMLWebViewElement = document.createElement('webview');

webView.className = styles.webViewContainer;
webView.addEventListener('dragenter', this.onInspectorDrag, true);
webView.addEventListener('dragover', this.onInspectorDrag, true);
webView.addEventListener('ipc-message', this.ipcMessageEventHandler);
webView.setAttribute('partition', `persist:${state.botHash}`);
webView.setAttribute('preload', preload);
webView.setAttribute('preload', state.inspector.preloadPath);
webView.setAttribute('src', encodeURI(state.inspector.src));
return webView;
}
Expand Down
Expand Up @@ -40,16 +40,12 @@ import { CommandServiceImpl } from '../../../../../platform/commands/commandServ
import { Inspector } from './inspector';

const mapStateToProps = (state: RootState, ownProps: any) => {
const { bot, theme, clientAwareSettings } = state;
const cwdAsBase = !(clientAwareSettings.cwd || '').startsWith('/')
? `/${clientAwareSettings.cwd}`
: clientAwareSettings.cwd;
const { bot, theme } = state;
return {
...ownProps,
botHash: bot.activeBotDigest,
activeBot: bot.activeBot,
themeInfo: theme,
cwdAsBase,
};
};

Expand Down
54 changes: 24 additions & 30 deletions packages/app/main/src/extensions.ts
Expand Up @@ -236,36 +236,41 @@ class ExtManagerImpl extends DisposableImpl implements ExtensionManager {
});
}

public unloadExtensions() {
public async unloadExtensions() {
const extensionUnloadPromises = [];
for (const kvPair of this.extensions) {
this.unloadExtension(kvPair[0]);
extensionUnloadPromises.push(this.unloadExtension(kvPair[0]));
}
return Promise.all(extensionUnloadPromises);
}

public unloadExtension(ipc: IPC) {
private async unloadExtension(ipc: IPC) {
const extension = this.extensions.get(ipc);
if (extension) {
// eslint-disable-next-line no-console
console.log(`Removing extension ${extension.config.name}`);
// Disconnect from the extension process
extension.disconnect();
// Notify the client that the extension is gone.
mainWindow.commandService.remoteCall(SharedConstants.Commands.Extension.Disconnect, extension.config.location);
await mainWindow.commandService.remoteCall(
SharedConstants.Commands.Extension.Disconnect,
extension.config.location
);
// Cleanup
this.extensions.delete(ipc);
}
}

public addExtension(extension: ExtensionImpl, configPath: string) {
public async addExtension(extension: ExtensionImpl, configPath: string): Promise<void> {
// Cleanup configPath
configPath = configPath.replace(/\\/g, '/');
// Remove any previous extension with matching name.
this.unloadExtension(extension.ipc);
await this.unloadExtension(extension.ipc);
// Save it off.
this.extensions.set(extension.ipc, extension);
extension.on('exit', () => {
extension.on('exit', async () => {
// Unload the extension if its process exits.
this.unloadExtension(extension.ipc);
await this.unloadExtension(extension.ipc);
});
// eslint-disable-next-line no-console
console.log(`Adding extension ${extension.config.name}`);
Expand All @@ -280,31 +285,20 @@ class ExtManagerImpl extends DisposableImpl implements ExtensionManager {
inspectors.forEach(inspector => {
inspector.src = (inspector.src || '').replace(/\\/g, '/');
});
if (
extension.config.client.debug &&
extension.config.client.debug.enabled &&
extension.config.client.debug.webpack
) {
// If running in debug mode, rewrite inspector paths as http URLs for webpack-dev-server.
const port = extension.config.client.debug.webpack.port || 3030;
const host = extension.config.client.debug.webpack.host || 'localhost';
inspectors.forEach(inspector => {
inspector.src = `http://${host}:${port}/${inspector.src}`.replace(extension.config.client.basePath, '');
});
} else {
// If not in debug mode, rewrite paths as file path URLs.
inspectors.forEach(inspector => {
let folder = path.resolve(configPath).replace(/\\/g, '/');
if (folder[0] !== '/') {
folder = `/${folder}`;
}
inspector.src = `file://${folder}/` + inspector.src;
});
}
inspectors.forEach(inspector => {
let folder = path.resolve(configPath).replace(/\\/g, '/');
if (folder[0] !== '/') {
folder = `/${folder}`;
}
inspector.src = `file://${folder}/` + inspector.src;
inspector.preloadPath =
'file://' + path.resolve(path.join(__dirname, '..', 'extensions', 'inspector-preload.js'));
});

// Connect to the extension's node process (if any).
extension.connect();
// Notify the client of the new extension.
mainWindow.commandService.remoteCall(SharedConstants.Commands.Extension.Connect, extension.config);
return mainWindow.commandService.remoteCall(SharedConstants.Commands.Extension.Connect, extension.config);
}

// Check whether we're running from an 'app.asar' packfile. If so, it means we were installed
Expand Down
1 change: 1 addition & 0 deletions packages/sdk/shared/src/extensions/config.ts
Expand Up @@ -70,6 +70,7 @@ export interface ExtensionInspector {
criteria?: InspectorCriteria | InspectorCriteria[];
summaryText?: string | string[];
accessories?: InspectorAccessory[];
preloadPath?: string;
}

// =============================================================================
Expand Down

0 comments on commit af6c453

Please sign in to comment.