Summary: Original commit changeset: ff84080d43fa This re-adds JS client support. The original version had a small bug that inadvertantly wrapped support for Android emulators in the dropdown in a GK that was only meant to cover JS clients. This is addressed here. Reviewed By: timur-valiev Differential Revision: D18707485 fbshipit-source-id: ceea8e279a21111f96073f8b784e852f6313e2a4
91 lines
2.2 KiB
JavaScript
91 lines
2.2 KiB
JavaScript
/**
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @format
|
|
*/
|
|
|
|
// ==============
|
|
// Preload script
|
|
// ==============
|
|
const {remote, ipcRenderer} = require('electron');
|
|
|
|
let FlipperMainWindowId = 0;
|
|
|
|
ipcRenderer.on('parent-window-id', (event, message) => {
|
|
FlipperMainWindowId = message;
|
|
});
|
|
|
|
let FlipperIsClientInit = false;
|
|
let FlipperMemoizedPlugins;
|
|
|
|
function initClient(plugins) {
|
|
if (FlipperIsClientInit) {
|
|
return;
|
|
}
|
|
if (plugins) {
|
|
FlipperMemoizedPlugins = plugins;
|
|
}
|
|
if (FlipperMainWindowId != 0) {
|
|
ipcRenderer.sendTo(FlipperMainWindowId, 'from-js-emulator-init-client', {
|
|
command: 'initClient',
|
|
windowId: remote.getCurrentWebContents().id,
|
|
payload: {
|
|
plugins: plugins ? plugins : FlipperMemoizedPlugins,
|
|
appName: 'kite/weblite',
|
|
},
|
|
});
|
|
FlipperIsClientInit = true;
|
|
}
|
|
}
|
|
|
|
window.FlipperWebviewBridge = {
|
|
registerPlugins: function(plugins) {
|
|
console.log(plugins);
|
|
if (FlipperMainWindowId != 0) {
|
|
ipcRenderer.sendTo(FlipperMainWindowId, 'from-js-emulator', {
|
|
command: 'registerPlugins',
|
|
payload: plugins,
|
|
});
|
|
}
|
|
},
|
|
start: function() {
|
|
console.log('start');
|
|
|
|
if (FlipperMainWindowId != 0) {
|
|
ipcRenderer.sendTo(FlipperMainWindowId, 'from-js-emulator', {
|
|
command: 'start',
|
|
payload: null,
|
|
});
|
|
}
|
|
},
|
|
sendFlipperObject: function(plugin, method, data) {
|
|
console.log(plugin, method, data);
|
|
initClient();
|
|
if (FlipperMainWindowId != 0) {
|
|
ipcRenderer.sendTo(FlipperMainWindowId, 'from-js-emulator', {
|
|
command: 'sendFlipperObject',
|
|
payload: {
|
|
api: plugin,
|
|
method: method,
|
|
params: data,
|
|
},
|
|
});
|
|
}
|
|
},
|
|
isFlipperSupported: true,
|
|
initClient: initClient,
|
|
};
|
|
|
|
ipcRenderer.on('message-to-plugin', (event, message) => {
|
|
const flipper = window.flipper;
|
|
if (!flipper) {
|
|
return;
|
|
}
|
|
const receiver = flipper.FlipperWebviewMessageReceiver.receive;
|
|
const {api, method, params} = message.params;
|
|
receiver(api, method, JSON.stringify(params));
|
|
});
|