plugin manager

pull/2074/head
filip mertens 3 years ago
parent f986a65da5
commit a5d382aef7
  1. 33
      apps/remix-ide/src/app/components/plugin-manager-component.js
  2. 29
      apps/remix-ide/src/app/plugins/ViewPluginUI.tsx
  3. 33
      apps/remix-ide/src/app/tabs/settings-tab.tsx

@ -3,6 +3,7 @@ import React from 'react' // eslint-disable-line
import ReactDOM from 'react-dom' import ReactDOM from 'react-dom'
import {RemixUiPluginManager} from '@remix-ui/plugin-manager' // eslint-disable-line import {RemixUiPluginManager} from '@remix-ui/plugin-manager' // eslint-disable-line
import * as packageJson from '../../../../../package.json' import * as packageJson from '../../../../../package.json'
import { ViewPluginUI } from '../plugins/ViewPluginUI'
const _paq = window._paq = window._paq || [] const _paq = window._paq = window._paq || []
const profile = { const profile = {
@ -31,6 +32,7 @@ class PluginManagerComponent extends ViewPlugin {
this.inactivePlugins = [] this.inactivePlugins = []
this.activeProfiles = this.appManager.actives this.activeProfiles = this.appManager.actives
this._paq = _paq this._paq = _paq
this.dispatch = null
this.listenOnEvent() this.listenOnEvent()
} }
@ -40,7 +42,7 @@ class PluginManagerComponent extends ViewPlugin {
* RemixAppManager * RemixAppManager
* @param {string} name name of Plugin * @param {string} name name of Plugin
*/ */
isActive (name) { isActive = (name) =>{
return this.appManager.actives.includes(name) return this.appManager.actives.includes(name)
} }
@ -49,7 +51,7 @@ class PluginManagerComponent extends ViewPlugin {
* RemixAppManager to enable plugin activation * RemixAppManager to enable plugin activation
* @param {string} name name of Plugin * @param {string} name name of Plugin
*/ */
activateP (name) { activateP = (name) => {
this.appManager.activatePlugin(name) this.appManager.activatePlugin(name)
_paq.push(['trackEvent', 'manager', 'activate', name]) _paq.push(['trackEvent', 'manager', 'activate', name])
} }
@ -60,7 +62,7 @@ class PluginManagerComponent extends ViewPlugin {
* @param {Profile} pluginName * @param {Profile} pluginName
* @returns {void} * @returns {void}
*/ */
async activateAndRegisterLocalPlugin (localPlugin) { activateAndRegisterLocalPlugin = async (localPlugin) => {
if (localPlugin) { if (localPlugin) {
this.engine.register(localPlugin) this.engine.register(localPlugin)
this.appManager.activatePlugin(localPlugin.profile.name) this.appManager.activatePlugin(localPlugin.profile.name)
@ -75,28 +77,37 @@ class PluginManagerComponent extends ViewPlugin {
* of the plugin * of the plugin
* @param {string} name name of Plugin * @param {string} name name of Plugin
*/ */
deactivateP (name) { deactivateP = (name) => {
this.call('manager', 'deactivatePlugin', name) this.call('manager', 'deactivatePlugin', name)
_paq.push(['trackEvent', 'manager', 'deactivate', name]) _paq.push(['trackEvent', 'manager', 'deactivate', name])
} }
onActivation () { onActivation () {
}
setDispatch (dispatch) {
this.dispatch = dispatch
this.renderComponent() this.renderComponent()
} }
updateComponent(state){
return <div id='pluginManager'><RemixUiPluginManager
pluginComponent={state}/></div>
}
renderComponent () { renderComponent () {
ReactDOM.render( if(this.dispatch) this.dispatch({...this, activePlugins: this.activePlugins, inactivePlugins: this.inactivePlugins})
<RemixUiPluginManager
pluginComponent={this}
/>,
this.htmlElement)
} }
render () { render () {
return this.htmlElement return (
<ViewPluginUI plugin={this} />
);
} }
getAndFilterPlugins (filter) { getAndFilterPlugins = (filter) => {
this.filter = typeof filter === 'string' ? filter.toLowerCase() : this.filter this.filter = typeof filter === 'string' ? filter.toLowerCase() : this.filter
const isFiltered = (profile) => (profile.displayName ? profile.displayName : profile.name).toLowerCase().includes(this.filter) const isFiltered = (profile) => (profile.displayName ? profile.displayName : profile.name).toLowerCase().includes(this.filter)

@ -0,0 +1,29 @@
import React from "react"
import { useEffect, useState } from "react"
interface IViewPluginUI {
plugin: any
}
export const ViewPluginUI = (props: IViewPluginUI) => {
const [state, setState] = useState<any>(null)
useEffect(() => {
console.log(props.plugin)
if(props.plugin.setDispatch){
props.plugin.setDispatch(setState)
}
}, [])
useEffect(() => {
console.log(state)
}, [state])
return (
<>{state?
<div>{props.plugin.updateComponent(state)}</div>
:<></>
}</>
)
}

@ -5,6 +5,7 @@ import * as packageJson from '../../../../../package.json'
import { RemixUiSettings } from '@remix-ui/settings' //eslint-disable-line import { RemixUiSettings } from '@remix-ui/settings' //eslint-disable-line
import Registry from '../state/registry' import Registry from '../state/registry'
import { ViewReactPlugin } from '../plugins/viewReactPlugin' import { ViewReactPlugin } from '../plugins/viewReactPlugin'
import { ViewPluginUI } from '../plugins/ViewPluginUI'
const profile = { const profile = {
name: 'settings', name: 'settings',
@ -48,7 +49,6 @@ module.exports = class SettingsTab extends ViewReactPlugin {
} }
render() { render() {
return ( return (
<div id='settingsTab'> <div id='settingsTab'>
<ViewPluginUI plugin={this} /> <ViewPluginUI plugin={this} />
@ -57,7 +57,6 @@ module.exports = class SettingsTab extends ViewReactPlugin {
} }
updateComponent(state: any){ updateComponent(state: any){
console.log('updateComponent', state)
return <RemixUiSettings return <RemixUiSettings
config={state.config} config={state.config}
editor={state.editor} editor={state.editor}
@ -68,7 +67,6 @@ module.exports = class SettingsTab extends ViewReactPlugin {
} }
renderComponent () { renderComponent () {
console.log('dispatching', this.useMatomoAnalytics, this.dispatch)
this.dispatch(this) this.dispatch(this)
} }
@ -77,7 +75,6 @@ module.exports = class SettingsTab extends ViewReactPlugin {
} }
updateMatomoAnalyticsChoice (isChecked) { updateMatomoAnalyticsChoice (isChecked) {
console.log('update matomo')
this.config.set('settings/matomo-analytics', isChecked) this.config.set('settings/matomo-analytics', isChecked)
this.useMatomoAnalytics = isChecked this.useMatomoAnalytics = isChecked
this.dispatch({ this.dispatch({
@ -85,31 +82,3 @@ module.exports = class SettingsTab extends ViewReactPlugin {
}) })
} }
} }
export interface IViewPluginUI {
plugin: any
}
export const ViewPluginUI = (props: IViewPluginUI) => {
const [state, setState] = useState<any>(null)
useEffect(() => {
console.log(props.plugin)
if(props.plugin.setDispatch){
props.plugin.setDispatch(setState)
}
}, [])
useEffect(() => {
console.log(state)
}, [state])
return (
<>{state?
<div>{props.plugin.updateComponent(state)}</div>
:<></>
}</>
)
}
Loading…
Cancel
Save