remix-project mirror
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
remix-project/apps/remix-ide/src/app.js

406 lines
15 KiB

'use strict'
import { RunTab, makeUdapp } from './app/udapp'
import { RemixEngine } from './remixEngine'
import { RemixAppManager } from './remixAppManager'
import { ThemeModule } from './app/tabs/theme-module'
import { NetworkModule } from './app/tabs/network-module'
import { Web3ProviderModule } from './app/tabs/web3-provider'
import { IntelligentScriptExecutor } from './app/tabs/intelligent-script-executor'
import { SidePanel } from './app/components/side-panel'
import { HiddenPanel } from './app/components/hidden-panel'
import { VerticalIcons } from './app/components/vertical-icons'
import { LandingPage } from './app/ui/landing-page/landing-page'
import { MainPanel } from './app/components/main-panel'
import { PermissionHandlerPlugin } from './app/plugins/permission-handler-plugin'
3 years ago
import { AstWalker } from '@remix-project/remix-astwalker'
import { LinkLibraries, DeployLibraries, OpenZeppelinProxy } from '@remix-project/core-plugin'
import { WalkthroughService } from './walkthroughService'
import { OffsetToLineColumnConverter, CompilerMetadata, CompilerArtefacts, FetchAndCompile, CompilerImports, EditorContextListener, GistHandler } from '@remix-project/core-plugin'
3 years ago
import Registry from './app/state/registry'
3 years ago
import { ConfigPlugin } from './app/plugins/config'
import { StoragePlugin } from './app/plugins/storage'
3 years ago
import { Layout } from './app/panels/layout'
import { NotificationPlugin } from './app/plugins/notification'
import { Blockchain } from './blockchain/blockchain.js'
import { HardhatProvider } from './app/tabs/hardhat-provider'
const isElectron = require('is-electron')
const remixLib = require('@remix-project/remix-lib')
3 years ago
import { QueryParams } from '@remix-project/remix-lib'
3 years ago
const Storage = remixLib.Storage
const RemixDProvider = require('./app/files/remixDProvider')
const Config = require('./config')
const FileManager = require('./app/files/fileManager')
const FileProvider = require('./app/files/fileProvider')
const DGitProvider = require('./app/files/dgitProvider')
const WorkspaceFileProvider = require('./app/files/workspaceFileProvider')
const PluginManagerComponent = require('./app/components/plugin-manager-component')
const CompileTab = require('./app/tabs/compile-tab')
const SettingsTab = require('./app/tabs/settings-tab')
const AnalysisTab = require('./app/tabs/analysis-tab')
const { DebuggerTab } = require('./app/tabs/debugger-tab')
const TestTab = require('./app/tabs/test-tab')
const FilePanel = require('./app/panels/file-panel')
const Editor = require('./app/editor/editor')
const Terminal = require('./app/panels/terminal')
3 years ago
const { TabProxy } = require('./app/panels/tab-proxy.js')
3 years ago
class AppComponent {
constructor () {
3 years ago
this.appManager = new RemixAppManager({})
this.queryParams = new QueryParams()
this._components = {}
// setup storage
const configStorage = new Storage('config-v0.8:')
// load app config
const config = new Config(configStorage)
3 years ago
Registry.getInstance().put({ api: config, name: 'config' })
// load file system
3 years ago
this._components.filesProviders = {}
this._components.filesProviders.browser = new FileProvider('browser')
3 years ago
Registry.getInstance().put({
3 years ago
api: this._components.filesProviders.browser,
3 years ago
name: 'fileproviders/browser'
})
3 years ago
this._components.filesProviders.localhost = new RemixDProvider(
this.appManager
3 years ago
)
Registry.getInstance().put({
3 years ago
api: this._components.filesProviders.localhost,
3 years ago
name: 'fileproviders/localhost'
})
3 years ago
this._components.filesProviders.workspace = new WorkspaceFileProvider()
3 years ago
Registry.getInstance().put({
3 years ago
api: this._components.filesProviders.workspace,
3 years ago
name: 'fileproviders/workspace'
})
3 years ago
Registry.getInstance().put({
3 years ago
api: this._components.filesProviders,
3 years ago
name: 'fileproviders'
})
}
async run () {
// APP_MANAGER
3 years ago
const appManager = this.appManager
const pluginLoader = this.appManager.pluginLoader
this.panels = {}
this.workspace = pluginLoader.get()
this.engine = new RemixEngine()
this.engine.register(appManager);
3 years ago
const matomoDomains = {
'remix-alpha.ethereum.org': 27,
'remix-beta.ethereum.org': 25,
'remix.ethereum.org': 23
}
3 years ago
this.showMatamo =
3 years ago
matomoDomains[window.location.hostname] &&
!Registry.getInstance()
.get('config')
.api.exists('settings/matomo-analytics')
3 years ago
this.walkthroughService = new WalkthroughService(
3 years ago
appManager,
3 years ago
this.showMatamo
3 years ago
)
3 years ago
const hosts = ['127.0.0.1:8080', '192.168.0.101:8080', 'localhost:8080']
// workaround for Electron support
if (!isElectron() && !hosts.includes(window.location.host)) {
// Oops! Accidentally trigger refresh or bookmark.
window.onbeforeunload = function () {
return 'Are you sure you want to leave?'
}
}
// SERVICES
3 years ago
// ----------------- gist service ---------------------------------
3 years ago
this.gistHandler = new GistHandler()
// ----------------- theme service ---------------------------------
3 years ago
this.themeModule = new ThemeModule()
Registry.getInstance().put({ api: this.themeModule, name: 'themeModule' })
3 years ago
// ----------------- editor service ----------------------------
const editor = new Editor() // wrapper around ace editor
3 years ago
Registry.getInstance().put({ api: editor, name: 'editor' })
3 years ago
editor.event.register('requiringToSaveCurrentfile', () =>
fileManager.saveCurrentFile()
)
// ----------------- fileManager service ----------------------------
const fileManager = new FileManager(editor, appManager)
3 years ago
Registry.getInstance().put({ api: fileManager, name: 'filemanager' })
// ----------------- dGit provider ---------------------------------
const dGitProvider = new DGitProvider()
// ----------------- Storage plugin ---------------------------------
const storagePlugin = new StoragePlugin()
3 years ago
//----- search
3 years ago
// const search = new SearchPlugin()
3 years ago
// ----------------- import content service ------------------------
const contentImport = new CompilerImports()
3 years ago
const blockchain = new Blockchain(Registry.getInstance().get('config').api)
// ----------------- compilation metadata generation service ---------
const compilerMetadataGenerator = new CompilerMetadata()
// ----------------- compilation result service (can keep track of compilation results) ----------------------------
const compilersArtefacts = new CompilerArtefacts() // store all the compilation results (key represent a compiler name)
3 years ago
Registry.getInstance().put({
api: compilersArtefacts,
name: 'compilersartefacts'
})
// service which fetch contract artifacts from sourve-verify, put artifacts in remix and compile it
const fetchAndCompile = new FetchAndCompile()
// ----------------- network service (resolve network id / name) -----
const networkModule = new NetworkModule(blockchain)
// ----------------- represent the current selected web3 provider ----
const web3Provider = new Web3ProviderModule(blockchain)
const hardhatProvider = new HardhatProvider(blockchain)
// ----------------- convert offset to line/column service -----------
const offsetToLineColumnConverter = new OffsetToLineColumnConverter()
3 years ago
Registry.getInstance().put({
api: offsetToLineColumnConverter,
name: 'offsettolinecolumnconverter'
})
// ----------------- run script after each compilation results -----------
const intelligentScriptExecutor = new IntelligentScriptExecutor()
// -------------------Terminal----------------------------------------
3 years ago
makeUdapp(blockchain, compilersArtefacts, domEl => terminal.logHtml(domEl))
const terminal = new Terminal(
{ appManager, blockchain },
{
3 years ago
getPosition: event => {
3 years ago
const limitUp = 36
const limitDown = 20
const height = window.innerHeight
3 years ago
let newpos = event.pageY < limitUp ? limitUp : event.pageY
newpos = newpos < height - limitDown ? newpos : height - limitDown
return height - newpos
}
}
)
3 years ago
const contextualListener = new EditorContextListener(new AstWalker())
3 years ago
this.notification = new NotificationPlugin()
3 years ago
3 years ago
const configPlugin = new ConfigPlugin()
3 years ago
this.layout = new Layout()
const permissionHandler = new PermissionHandlerPlugin()
3 years ago
3 years ago
this.engine.register([
permissionHandler,
3 years ago
this.layout,
this.notification,
this.gistHandler,
3 years ago
configPlugin,
blockchain,
contentImport,
3 years ago
this.themeModule,
editor,
fileManager,
compilerMetadataGenerator,
compilersArtefacts,
networkModule,
offsetToLineColumnConverter,
contextualListener,
terminal,
web3Provider,
intelligentScriptExecutor,
fetchAndCompile,
dGitProvider,
storagePlugin,
3 years ago
hardhatProvider,
3 years ago
this.walkthroughService,
])
// LAYOUT & SYSTEM VIEWS
const appPanel = new MainPanel()
3 years ago
Registry.getInstance().put({ api: this.mainview, name: 'mainview' })
3 years ago
const tabProxy = new TabProxy(fileManager, editor)
3 years ago
this.engine.register([appPanel, tabProxy])
// those views depend on app_manager
3 years ago
this.menuicons = new VerticalIcons()
this.sidePanel = new SidePanel()
this.hiddenPanel = new HiddenPanel()
3 years ago
3 years ago
const pluginManagerComponent = new PluginManagerComponent(
appManager,
3 years ago
this.engine
3 years ago
)
const filePanel = new FilePanel(appManager)
const landingPage = new LandingPage(
3 years ago
appManager,
3 years ago
this.menuicons,
3 years ago
fileManager,
filePanel,
contentImport
)
3 years ago
this.settings = new SettingsTab(
3 years ago
Registry.getInstance().get('config').api,
editor,
appManager
)
3 years ago
this.engine.register([
this.menuicons,
landingPage,
3 years ago
this.hiddenPanel,
this.sidePanel,
filePanel,
pluginManagerComponent,
3 years ago
this.settings
])
// CONTENT VIEWS & DEFAULT PLUGINS
const openZeppelinProxy = new OpenZeppelinProxy(blockchain)
const linkLibraries = new LinkLibraries(blockchain)
const deployLibraries = new DeployLibraries(blockchain)
3 years ago
const compileTab = new CompileTab(
Registry.getInstance().get('config').api,
Registry.getInstance().get('filemanager').api
)
const run = new RunTab(
blockchain,
3 years ago
Registry.getInstance().get('config').api,
Registry.getInstance().get('filemanager').api,
Registry.getInstance().get('editor').api,
filePanel,
3 years ago
Registry.getInstance().get('compilersartefacts').api,
networkModule,
3 years ago
Registry.getInstance().get('fileproviders/browser').api
)
3 years ago
const analysis = new AnalysisTab()
const debug = new DebuggerTab()
const test = new TestTab(
3 years ago
Registry.getInstance().get('filemanager').api,
Registry.getInstance().get('offsettolinecolumnconverter').api,
filePanel,
compileTab,
appManager,
contentImport
)
3 years ago
this.engine.register([
compileTab,
run,
debug,
analysis,
test,
filePanel.remixdHandle,
filePanel.gitHandle,
filePanel.hardhatHandle,
filePanel.truffleHandle,
filePanel.slitherHandle,
linkLibraries,
deployLibraries,
openZeppelinProxy
])
3 years ago
3 years ago
this.layout.panels = {
3 years ago
tabs: { plugin: tabProxy, active: true },
editor: { plugin: editor, active: true },
main: { plugin: appPanel, active: false },
terminal: { plugin: terminal, active: true, minimized: false }
3 years ago
}
}
async activate () {
const queryParams = new QueryParams()
const params = queryParams.get()
3 years ago
if (isElectron()) {
3 years ago
this.appManager.activatePlugin('remixd')
}
try {
3 years ago
this.engine.register(await this.appManager.registeredPlugins())
} catch (e) {
3 years ago
console.log("couldn't register iframe plugins", e.message)
}
3 years ago
await this.appManager.activatePlugin(['layout'])
await this.appManager.activatePlugin(['notification'])
await this.appManager.activatePlugin(['editor'])
await this.appManager.activatePlugin(['permissionhandler', 'theme', 'fileManager', 'compilerMetadata', 'compilerArtefacts', 'network', 'web3Provider', 'offsetToLineColumnConverter'])
await this.appManager.activatePlugin(['mainPanel', 'menuicons', 'tabs'])
await this.appManager.activatePlugin(['sidePanel']) // activating host plugin separately
await this.appManager.activatePlugin(['home'])
await this.appManager.activatePlugin(['settings', 'config'])
await this.appManager.activatePlugin(['hiddenPanel', 'pluginManager', 'contextualListener', 'terminal', 'blockchain', 'fetchAndCompile', 'contentImport', 'gistHandler'])
await this.appManager.activatePlugin(['settings'])
3 years ago
await this.appManager.activatePlugin(['walkthrough','storage', 'intelligentScriptExecutor'])
3 years ago
this.appManager.on(
3 years ago
'filePanel',
'workspaceInitializationCompleted',
async () => {
3 years ago
await this.appManager.registerContextMenuItems()
3 years ago
}
)
3 years ago
await this.appManager.activatePlugin(['filePanel'])
// Set workspace after initial activation
3 years ago
this.appManager.on('editor', 'editorMounted', () => {
if (Array.isArray(this.workspace)) {
this.appManager
.activatePlugin(this.workspace)
3 years ago
.then(async () => {
try {
if (params.deactivate) {
3 years ago
await this.appManager.deactivatePlugin(
3 years ago
params.deactivate.split(',')
)
}
} catch (e) {
console.log(e)
}
3 years ago
if (params.code && (!params.activate || params.activate.split(',').includes('solidity'))) {
3 years ago
// if code is given in url we focus on solidity plugin
3 years ago
this.menuicons.select('solidity')
3 years ago
} else {
// If plugins are loaded from the URL params, we focus on the last one.
if (
3 years ago
this.appManager.pluginLoader.current === 'queryParams' &&
this.workspace.length > 0
) { this.menuicons.select(this.workspace[this.workspace.length - 1]) }
}
3 years ago
if (params.call) {
const callDetails = params.call.split('//')
if (callDetails.length > 1) {
3 years ago
this.appManager.call('notification', 'toast', `initiating ${callDetails[0]} ...`)
3 years ago
// @todo(remove the timeout when activatePlugin is on 0.3.0)
3 years ago
this.appManager.call(...callDetails).catch(console.error)
3 years ago
}
}
3 years ago
})
.catch(console.error)
}
})
// activate solidity plugin
this.appManager.activatePlugin(['solidity', 'udapp', 'deploy-libraries', 'link-libraries', 'openzeppelin-proxy'])
3 years ago
// Load and start the service who manager layout and frame
}
}
3 years ago
export default AppComponent