Skip to content

Commit

Permalink
add types for RemixAppManager
Browse files Browse the repository at this point in the history
  • Loading branch information
joeizang committed Jan 15, 2025
1 parent 374c577 commit 5993076
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const profile = {
maintainedBy: "Remix"
}

export class PluginManagerComponent extends ViewPlugin {
export default class PluginManagerComponent extends ViewPlugin {
appManager: RemixAppManager
engine: RemixEngine
htmlElement: HTMLDivElement
Expand Down
11 changes: 6 additions & 5 deletions apps/remix-ide/src/remixAppManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { EventEmitter } from 'events'
import { QueryParams } from '@remix-project/remix-lib'
import { IframePlugin } from '@remixproject/engine-web'
import { Registry } from '@remix-project/remix-lib'
import { RemixNavigator } from './types'
import { IRemixAppManager, RemixNavigator } from './types'
import { Profile } from '@remixproject/plugin-utils'

const _paq = (window._paq = window._paq || [])

Expand Down Expand Up @@ -170,7 +171,7 @@ export function canActivate(from, to) {
return ['ethdoc'].includes(from.name) || isNative(from.name) || (to && from && from.canActivate && from.canActivate.includes(to.name))
}

export class RemixAppManager extends PluginManager {
export class RemixAppManager extends PluginManager implements IRemixAppManager {
actives = []
pluginsDirectory: string
event: EventEmitter
Expand Down Expand Up @@ -264,16 +265,16 @@ export class RemixAppManager extends PluginManager {
_paq.push(['trackEvent', 'pluginManager', 'deactivate', plugin.name])
}

isDependent(name) {
isDependent(name: string): boolean {
return dependentModules.includes(name)
}

isRequired(name) {
isRequired(name: string): boolean {
// excluding internal use plugins
return requiredModules.includes(name) || isInjectedProvider(name) || isVM(name) || isScriptRunner(name)
}

async registeredPlugins() {
async registeredPlugins(): Promise<IframePlugin[]> {
let plugins
try {
const res = await fetch(this.pluginsDirectory)
Expand Down
20 changes: 20 additions & 0 deletions apps/remix-ide/src/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,23 @@ type NavigatorUAData = {
export interface RemixNavigator extends Navigator {
userAgentData: NavigatorUAData
}

export interface IRemixAppManager {
actives: string[]
pluginsDirectory: string
event: EventEmitter
pluginLoader: PluginLoader
canActivatePlugin(from: any, to: any): Promise<boolean>
canDeactivatePlugin(from: any, to: any): Promise<boolean>
checkCanDeactivate(from: any, to: any): Promise<boolean>
deactivatePlugin(name: string): Promise<void>
canCall(from: string, to: string, method: string, message: string): Promise<boolean>
onPluginActivated(plugin: any): void
onPluginDeactivated(plugin: any): void
getAll(): Profile<any>[]
getIds(): string[]
isDependent(name: string): boolean
isRequired(name: string): boolean
registeredPlugins(): Promise<any[]>
registerContextMenuItems(): Promise<void>
}

0 comments on commit 5993076

Please sign in to comment.