Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions src/components/scenes/GuiPluginViewScene.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Bridge, onMethod } from 'yaob'
import { setPluginScene } from '../../modules/UI/scenes/Plugins/BackButton.js'
import { EdgeProvider } from '../../modules/UI/scenes/Plugins/EdgeProvider.js'
import { type GuiPlugin, type GuiPluginQuery, makePluginUri } from '../../types/GuiPluginTypes.js'
import type { Dispatch, State } from '../../types/reduxTypes.js'
import type { Dispatch, State as ReduxState } from '../../types/reduxTypes.js'
import { javascript } from '../../util/bridge/injectThisInWebView.js'
import { bestOfPlugins } from '../../util/ReferralHelpers.js'
import { SceneWrapper } from '../common/SceneWrapper.js'
Expand Down Expand Up @@ -118,30 +118,38 @@ type OwnProps = {
}

type DispatchProps = { dispatch: Dispatch }
type StateProps = { state: State }
type StateProps = { state: ReduxState }
type Props = OwnProps & DispatchProps & StateProps

type State = {
webViewKey: number
}

type PluginWorkerApi = {
setEdgeProvider(provider: EdgeProvider): Promise<mixed>
}

class GuiPluginView extends React.Component<Props> {
class GuiPluginView extends React.Component<Props, State> {
_callbacks: WebViewCallbacks
_canGoBack: boolean
_edgeProvider: EdgeProvider
_promoCode: string | void
_webview: WebView | void

constructor (props) {
const { deepPath, deepQuery, dispatch, plugin, state } = props
super(props)
setPluginScene(this)

// Set up the plugin:
const { deepPath, deepQuery, dispatch, plugin, state } = this.props
// Mechanism to re-boot the webview:
this.state = { webViewKey: 0 }
const restartPlugin = () => {
this.setState({ webViewKey: this.state.webViewKey + 1 })
}

// Set up the EdgeProvider:
this.updatePromoCode(plugin, state)
this._edgeProvider = new EdgeProvider(plugin, state, dispatch, deepPath, deepQuery, this._promoCode)
this._edgeProvider = new EdgeProvider(plugin, state, dispatch, restartPlugin, deepPath, deepQuery, this._promoCode)

// Set up the WebView bridge:
this._canGoBack = false
Expand Down Expand Up @@ -170,7 +178,7 @@ class GuiPluginView extends React.Component<Props> {
this._edgeProvider._updateState(state, deepPath, deepQuery, this._promoCode)
}

updatePromoCode (plugin: GuiPlugin, state: State) {
updatePromoCode (plugin: GuiPlugin, state: ReduxState) {
const accountPlugins = state.account.referralCache.accountPlugins
const accountReferral = state.account.accountReferral
const activePlugins = bestOfPlugins(accountPlugins, accountReferral, undefined)
Expand Down Expand Up @@ -232,6 +240,7 @@ class GuiPluginView extends React.Component<Props> {
onNavigationStateChange={this.onNavigationStateChange}
onMessage={this._callbacks.onMessage}
originWhitelist={originWhitelist}
key={`webView${this.state.webViewKey}`}
ref={this._callbacks.setRef}
setWebContentsDebuggingEnabled={true}
source={{ uri }}
Expand All @@ -246,6 +255,6 @@ class GuiPluginView extends React.Component<Props> {
// Connector -----------------------------------------------------------

export const GuiPluginViewScene = connect(
(state: State): StateProps => ({ state }),
(state: ReduxState): StateProps => ({ state }),
(dispatch: Dispatch): DispatchProps => ({ dispatch })
)(GuiPluginView)
17 changes: 14 additions & 3 deletions src/modules/UI/scenes/Plugins/EdgeProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,26 @@ export type EdgeProviderSpendTarget = {
}

export class EdgeProvider extends Bridgeable {
// Private properties:
_plugin: GuiPlugin
_dispatch: Dispatch
_state: State

// Properties:
// Public properties:
deepPath: string | void
deepQuery: GuiPluginQuery | void
promoCode: string | void

constructor (plugin: GuiPlugin, state: State, dispatch: Dispatch, deepPath?: string, deepQuery?: GuiPluginQuery, promoCode?: string) {
restartPlugin: () => void

constructor (
plugin: GuiPlugin,
state: State,
dispatch: Dispatch,
restartPlugin: () => void,
deepPath?: string,
deepQuery?: GuiPluginQuery,
promoCode?: string
) {
super()
this._plugin = plugin
this._dispatch = dispatch
Expand All @@ -102,6 +112,7 @@ export class EdgeProvider extends Bridgeable {
this.deepPath = deepPath
this.deepQuery = deepQuery
this.promoCode = promoCode
this.restartPlugin = restartPlugin
}

_updateState (state: State, deepPath?: string, deepQuery?: GuiPluginQuery, promoCode?: string): void {
Expand Down