diff --git a/src/PluginContainer.js b/src/PluginContainer.js index 85aca7edf..88898fd27 100644 --- a/src/PluginContainer.js +++ b/src/PluginContainer.js @@ -22,6 +22,7 @@ import { import React from 'react'; import {connect} from 'react-redux'; import {setPluginState} from './reducers/pluginStates.js'; +import {selectPlugin} from './reducers/connections'; import {devicePlugins, clientPlugins} from './plugins/index.js'; import NotificationsHub from './NotificationsHub'; import {activateMenuItems} from './MenuBar.js'; @@ -53,6 +54,11 @@ type Props = { state: Object, }) => void, deepLinkPayload: ?string, + selectPlugin: (payload: {| + selectedPlugin: ?string, + selectedApp?: ?string, + deepLinkPayload: ?string, + |}) => mixed, }; type State = { @@ -144,6 +150,19 @@ class PluginContainer extends Component { setPersistedState: state => setPluginState({pluginKey, state}), target, deepLinkPayload: this.props.deepLinkPayload, + selectPlugin: (pluginID: string, deepLinkPayload: ?string) => { + const {target} = this.state; + // check if plugin will be available + if ( + target instanceof Client && + target.plugins.some(p => p === pluginID) + ) { + this.props.selectPlugin({selectedPlugin: pluginID, deepLinkPayload}); + return true; + } else { + return false; + } + }, ref: this.refChanged, }; @@ -185,5 +204,6 @@ export default connect( }), { setPluginState, + selectPlugin, }, )(PluginContainer); diff --git a/src/plugin.js b/src/plugin.js index 551b0539d..ec96d0cd6 100644 --- a/src/plugin.js +++ b/src/plugin.js @@ -40,6 +40,7 @@ export type Props = { setPersistedState: (state: $Shape) => void, target: PluginTarget, deepLinkPayload: ?string, + selectPlugin: (pluginID: string, deepLinkPayload: ?string) => boolean, }; export class FlipperBasePlugin< diff --git a/src/reducers/connections.js b/src/reducers/connections.js index 0276ef683..9b4a8b194 100644 --- a/src/reducers/connections.js +++ b/src/reducers/connections.js @@ -8,7 +8,7 @@ import type BaseDevice from '../devices/BaseDevice'; import type Client from '../Client'; -export type State = { +export type State = {| devices: Array, androidEmulators: Array, selectedDevice: ?BaseDevice, @@ -19,7 +19,8 @@ export type State = { userPreferredApp: ?string, error: ?string, clients: Array, -}; + deepLinkPayload: ?string, +|}; export type Action = | { @@ -40,10 +41,11 @@ export type Action = } | { type: 'SELECT_PLUGIN', - payload: { + payload: {| selectedPlugin: ?string, selectedApp: ?string, - }, + deepLinkPayload: ?string, + |}, } | { type: 'SELECT_USER_PREFERRED_PLUGIN', @@ -79,6 +81,7 @@ const INITAL_STATE: State = { userPreferredApp: null, error: null, clients: [], + deepLinkPayload: null, }; export default function reducer( @@ -170,7 +173,7 @@ export default function reducer( } case 'SELECT_PLUGIN': { const {payload} = action; - const {selectedPlugin} = payload; + const {selectedPlugin, selectedApp} = payload; if (selectedPlugin) { performance.mark(`activePlugin-${selectedPlugin}`); } @@ -178,7 +181,7 @@ export default function reducer( return { ...state, ...payload, - userPreferredApp: payload.selectedApp, + userPreferredApp: selectedApp || state.userPreferredApp, userPreferredPlugin: selectedPlugin, }; } @@ -249,10 +252,11 @@ export const preferDevice = (payload: string): Action => ({ payload, }); -export const selectPlugin = (payload: { +export const selectPlugin = (payload: {| selectedPlugin: ?string, - selectedApp: ?string, -}): Action => ({ + selectedApp?: ?string, + deepLinkPayload: ?string, +|}): Action => ({ type: 'SELECT_PLUGIN', payload, });