diff --git a/apps/remix-ide/src/app.js b/apps/remix-ide/src/app.js index cb101b2b0f..01b1b6ff08 100644 --- a/apps/remix-ide/src/app.js +++ b/apps/remix-ide/src/app.js @@ -71,6 +71,7 @@ const Config = require('./config') const FileManager = require('./app/files/fileManager') import FileProvider from "./app/files/fileProvider" +import { appPlatformTypes } from '@remix-ui/app' const DGitProvider = require('./app/files/dgitProvider') const WorkspaceFileProvider = require('./app/files/workspaceFileProvider') @@ -87,10 +88,22 @@ const Terminal = require('./app/panels/terminal') const {TabProxy} = require('./app/panels/tab-proxy.js') +export class platformApi { + get name () { + return isElectron() ? appPlatformTypes.desktop : appPlatformTypes.web + } + isDesktop () { + return isElectron() + } +} class AppComponent { constructor() { - + const PlatFormAPi = new platformApi() + Registry.getInstance().put({ + api: PlatFormAPi, + name: 'platform' + }) this.appManager = new RemixAppManager({}) this.queryParams = new QueryParams() this._components = {} @@ -129,6 +142,8 @@ class AppComponent { api: this._components.filesProviders, name: 'fileproviders' }) + + } async run() { diff --git a/apps/remix-ide/src/app/files/dgitProvider.ts b/apps/remix-ide/src/app/files/dgitProvider.ts index aa14683a77..889aef6c4e 100644 --- a/apps/remix-ide/src/app/files/dgitProvider.ts +++ b/apps/remix-ide/src/app/files/dgitProvider.ts @@ -14,7 +14,7 @@ import JSZip from 'jszip' import path from 'path' import FormData from 'form-data' import axios from 'axios' -import isElectron from 'is-electron' +import Registry from '../state/registry' const profile = { name: 'dGitProvider', @@ -57,7 +57,7 @@ class DGitProvider extends Plugin { async getGitConfig() { - if (isElectron()) { + if ((Registry.getInstance().get('platform').api.isDesktop())) { return { fs: window.remixFileSystem, dir: '/' @@ -89,7 +89,7 @@ class DGitProvider extends Plugin { } async init(input?) { - if (isElectron()) { + if ((Registry.getInstance().get('platform').api.isDesktop())) { await this.call('isogit', 'init', { defaultBranch: (input && input.branch) || 'main' }) @@ -105,7 +105,7 @@ class DGitProvider extends Plugin { } async version() { - if (isElectron()) { + if ((Registry.getInstance().get('platform').api.isDesktop())) { return await this.call('isogit', 'version') } @@ -115,7 +115,7 @@ class DGitProvider extends Plugin { async status(cmd) { - if (isElectron()) { + if ((Registry.getInstance().get('platform').api.isDesktop())) { const status = await this.call('isogit', 'status', cmd) return status @@ -132,7 +132,7 @@ class DGitProvider extends Plugin { async add(cmd) { - if (isElectron()) { + if ((Registry.getInstance().get('platform').api.isDesktop())) { await this.call('isogit', 'add', cmd) } else { await git.add({ @@ -146,7 +146,7 @@ class DGitProvider extends Plugin { async rm(cmd) { - if (isElectron()) { + if ((Registry.getInstance().get('platform').api.isDesktop())) { await this.call('isogit', 'rm', cmd) } else { await git.remove({ @@ -160,7 +160,7 @@ class DGitProvider extends Plugin { async reset(cmd) { - if (isElectron()) { + if ((Registry.getInstance().get('platform').api.isDesktop())) { await this.call('isogit', 'reset', cmd) } else { await git.resetIndex({ @@ -174,7 +174,7 @@ class DGitProvider extends Plugin { async checkout(cmd, refresh = true) { - if (isElectron()) { + if ((Registry.getInstance().get('platform').api.isDesktop())) { await this.call('isogit', 'checkout', cmd) } else { await git.checkout({ @@ -192,7 +192,7 @@ class DGitProvider extends Plugin { async log(cmd) { - if (isElectron()) { + if ((Registry.getInstance().get('platform').api.isDesktop())) { const status = await this.call('isogit', 'log', { ...cmd, depth: 10 @@ -211,7 +211,7 @@ class DGitProvider extends Plugin { } async remotes(config) { - if (isElectron()) { + if ((Registry.getInstance().get('platform').api.isDesktop())) { return await this.call('isogit', 'remotes', config) } @@ -227,7 +227,7 @@ class DGitProvider extends Plugin { async branch(cmd, refresh = true) { let status - if (isElectron()) { + if ((Registry.getInstance().get('platform').api.isDesktop())) { status = await this.call('isogit', 'branch', cmd) } else { status = await git.branch({ @@ -248,7 +248,7 @@ class DGitProvider extends Plugin { - if (isElectron()) { + if ((Registry.getInstance().get('platform').api.isDesktop())) { return await this.call('isogit', 'currentbranch') } @@ -265,7 +265,7 @@ class DGitProvider extends Plugin { async branches(config) { - if (isElectron()) { + if ((Registry.getInstance().get('platform').api.isDesktop())) { return await this.call('isogit', 'branches') } @@ -288,7 +288,7 @@ class DGitProvider extends Plugin { async commit(cmd) { - if (isElectron()) { + if ((Registry.getInstance().get('platform').api.isDesktop())) { try { await this.call('isogit', 'init') const sha = await this.call('isogit', 'commit', cmd) @@ -315,7 +315,7 @@ class DGitProvider extends Plugin { async lsfiles(cmd) { - if (isElectron()) { + if ((Registry.getInstance().get('platform').api.isDesktop())) { return await this.call('isogit', 'lsfiles', cmd) } @@ -328,7 +328,7 @@ class DGitProvider extends Plugin { async resolveref(cmd) { - if (isElectron()) { + if ((Registry.getInstance().get('platform').api.isDesktop())) { return await this.call('isogit', 'resolveref', cmd) } @@ -340,7 +340,7 @@ class DGitProvider extends Plugin { } async readblob(cmd) { - if (isElectron()) { + if ((Registry.getInstance().get('platform').api.isDesktop())) { const readBlobResult = await this.call('isogit', 'readblob', cmd) return readBlobResult } @@ -370,7 +370,7 @@ class DGitProvider extends Plugin { } async addremote(input) { - if (isElectron()) { + if ((Registry.getInstance().get('platform').api.isDesktop())) { await this.call('isogit', 'addremote', { url: input.url, remote: input.remote }) return } @@ -378,7 +378,7 @@ class DGitProvider extends Plugin { } async delremote(input) { - if (isElectron()) { + if ((Registry.getInstance().get('platform').api.isDesktop())) { await this.call('isogit', 'delremote', { remote: input.remote }) return } @@ -391,7 +391,7 @@ class DGitProvider extends Plugin { async clone(input, workspaceName, workspaceExists = false) { - if (isElectron()) { + if ((Registry.getInstance().get('platform').api.isDesktop())) { const folder = await this.call('fs', 'selectFolder') if (!folder) return false const cmd = { @@ -442,7 +442,7 @@ class DGitProvider extends Plugin { }, input, } - if (isElectron()) { + if ((Registry.getInstance().get('platform').api.isDesktop())) { return await this.call('isogit', 'push', cmd) } else { @@ -470,7 +470,7 @@ class DGitProvider extends Plugin { input, } let result - if (isElectron()) { + if ((Registry.getInstance().get('platform').api.isDesktop())) { result = await this.call('isogit', 'pull', cmd) } else { @@ -501,7 +501,7 @@ class DGitProvider extends Plugin { input } let result - if (isElectron()) { + if ((Registry.getInstance().get('platform').api.isDesktop())) { result = await this.call('isogit', 'fetch', cmd) } else { const cmd2 = { diff --git a/apps/remix-ide/src/app/files/fileManager.ts b/apps/remix-ide/src/app/files/fileManager.ts index 073dec3c87..9ddac154d0 100644 --- a/apps/remix-ide/src/app/files/fileManager.ts +++ b/apps/remix-ide/src/app/files/fileManager.ts @@ -10,8 +10,6 @@ import { fileChangedToastMsg, recursivePasteToastMsg, storageFullMessage } from import helper from '../../lib/helper.js' import { RemixAppManager } from '../../remixAppManager' -import isElectron from 'is-electron' - /* attach to files event (removed renamed) trigger: currentFileChanged @@ -157,7 +155,7 @@ class FileManager extends Plugin { refresh() { const provider = this.fileProviderOf('/') // emit rootFolderChanged so that File Explorer reloads the file tree - if(isElectron()){ + if(Registry.getInstance().get('platform').api.isDesktop()){ provider.event.emit('refresh') }else{ provider.event.emit('rootFolderChanged', provider.workspace || '/') @@ -791,7 +789,7 @@ class FileManager extends Plugin { return this._deps.filesProviders.localhost } - if(isElectron()){ + if(Registry.getInstance().get('platform').api.isDesktop()){ return this._deps.filesProviders.electron } return this._deps.filesProviders.workspace @@ -916,7 +914,7 @@ class FileManager extends Plugin { } currentWorkspace() { - if(isElectron()){ + if(Registry.getInstance().get('platform').api.isDesktop()){ return '' } diff --git a/apps/remix-ide/src/app/panels/terminal.js b/apps/remix-ide/src/app/panels/terminal.js index f2decd4b88..c786fbef24 100644 --- a/apps/remix-ide/src/app/panels/terminal.js +++ b/apps/remix-ide/src/app/panels/terminal.js @@ -6,7 +6,6 @@ import * as packageJson from '../../../../../package.json' import Registry from '../state/registry' import { PluginViewWrapper } from '@remix-ui/helper' import vm from 'vm' -import isElectron from 'is-electron' const EventManager = require('../../lib/events') import { CompilerImports } from '@remix-project/core-plugin' // eslint-disable-line @@ -115,7 +114,7 @@ class Terminal extends Plugin { } updateComponent(state) { - return isElectron() ? + return (Registry.getInstance().get('platform').api.isDesktop()) ? : { - if (isElectron()) { + if (Registry.getInstance().get('platform').api.isDesktop()) { const files = await this.plugin.call('ripgrep', 'glob', '/', '**/*.sol') // only get path property of files this.data.files = files.map((x) => x.path) diff --git a/apps/remix-ide/src/app/plugins/remixd-handle.tsx b/apps/remix-ide/src/app/plugins/remixd-handle.tsx index eb3d9242e4..a082e2968b 100644 --- a/apps/remix-ide/src/app/plugins/remixd-handle.tsx +++ b/apps/remix-ide/src/app/plugins/remixd-handle.tsx @@ -1,12 +1,12 @@ /* eslint-disable no-unused-vars */ import React, {useRef, useState, useEffect} from 'react' // eslint-disable-line -import isElectron from 'is-electron' import {WebsocketPlugin} from '@remixproject/engine-web' import * as packageJson from '../../../../../package.json' // eslint-disable-next-line @nrwl/nx/enforce-module-boundaries import {version as remixdVersion} from '../../../../../libs/remixd/package.json' import {PluginManager} from '@remixproject/engine' -import {AppModal, AlertModal} from '@remix-ui/app' +import {AppModal, AlertModal, appPlatformTypes} from '@remix-ui/app' +import Registry from '../state/registry' const LOCALHOST = ' - connect to localhost - ' @@ -112,7 +112,7 @@ export class RemixdHandle extends WebsocketPlugin { } if (this.localhostProvider.isConnected()) { this.deactivate() - } else if (!isElectron()) { + } else if (!(Registry.getInstance().get('platform').api.isDektop())) { // warn the user only if he/she is in the browser context const mod: AppModal = { id: 'remixdConnect', diff --git a/apps/remix-ide/src/app/state/registry.ts b/apps/remix-ide/src/app/state/registry.ts index dc3655293f..7cf378db29 100644 --- a/apps/remix-ide/src/app/state/registry.ts +++ b/apps/remix-ide/src/app/state/registry.ts @@ -29,7 +29,7 @@ export default class Registry { return server } - public get (name: string) { + public get (name: string): registryEntry { const state = this.state[name] if (!state) return const server = state.server diff --git a/apps/remix-ide/src/remixAppManager.js b/apps/remix-ide/src/remixAppManager.js index be57adcd4e..61178b1207 100644 --- a/apps/remix-ide/src/remixAppManager.js +++ b/apps/remix-ide/src/remixAppManager.js @@ -2,7 +2,8 @@ import {PluginManager} from '@remixproject/engine' import {EventEmitter} from 'events' import {QueryParams} from '@remix-project/remix-lib' import {IframePlugin} from '@remixproject/engine-web' -const isElectron = require('is-electron') +import Registry from './app/state/registry' + const _paq = (window._paq = window._paq || []) // requiredModule removes the plugin from the plugin manager list on UI @@ -78,9 +79,6 @@ let requiredModules = [ // services + layout views + system views 'home' ] -if (isElectron()) { - requiredModules = [...requiredModules, 'fs', 'electronTemplates', 'isogit', 'remix-templates', 'electronconfig'] -} // dependentModules shouldn't be manually activated (e.g hardhat is activated by remixd) @@ -146,6 +144,10 @@ export class RemixAppManager extends PluginManager { this.event = new EventEmitter() this.pluginsDirectory = 'https://raw.githubusercontent.com/ethereum/remix-plugins-directory/master/build/metadata.json' this.pluginLoader = new PluginLoader() + if (Registry.getInstance().get('platform').api.isDesktop()) { + requiredModules = [...requiredModules, 'fs', 'electronTemplates', 'isogit', 'remix-templates', 'electronconfig'] + } + } async canActivatePlugin(from, to) { diff --git a/libs/remix-ui/app/src/index.ts b/libs/remix-ui/app/src/index.ts index 2bf8054edb..7b6fb7e2d5 100644 --- a/libs/remix-ui/app/src/index.ts +++ b/libs/remix-ui/app/src/index.ts @@ -1,5 +1,5 @@ export { default as RemixApp } from './lib/remix-app/remix-app' -export { dispatchModalContext, dispatchModalInterface, AppContext } from './lib/remix-app/context/context' +export { dispatchModalContext, dispatchModalInterface, AppContext, appProviderContextType, appPlatformTypes } from './lib/remix-app/context/context' export { ModalProvider, useDialogDispatchers } from './lib/remix-app/context/provider' export { AppModal } from './lib/remix-app/interface/index' export { AlertModal } from './lib/remix-app/interface/index' diff --git a/libs/remix-ui/app/src/lib/remix-app/context/context.tsx b/libs/remix-ui/app/src/lib/remix-app/context/context.tsx index 56792ad370..2d624fcefa 100644 --- a/libs/remix-ui/app/src/lib/remix-app/context/context.tsx +++ b/libs/remix-ui/app/src/lib/remix-app/context/context.tsx @@ -1,7 +1,6 @@ import React from 'react' import {AlertModal, AppModal} from '../interface' import {ModalInitialState} from '../state/modals' -import { Plugin } from '@remixproject/engine' export type appProviderContextType = { settings: any, @@ -9,10 +8,13 @@ export type appProviderContextType = { appManager: any modal: any layout: any - platform: appPlatformType + platform: appPlatformTypes } -export type appPlatformType = 'web' | 'desktop' +export enum appPlatformTypes { + web = 'web', + desktop = 'desktop' +} export const AppContext = React.createContext(null) diff --git a/libs/remix-ui/home-tab/src/lib/components/homeTabGetStarted.tsx b/libs/remix-ui/home-tab/src/lib/components/homeTabGetStarted.tsx index 4265b95316..bf736529db 100644 --- a/libs/remix-ui/home-tab/src/lib/components/homeTabGetStarted.tsx +++ b/libs/remix-ui/home-tab/src/lib/components/homeTabGetStarted.tsx @@ -7,7 +7,7 @@ import Carousel from 'react-multi-carousel' import WorkspaceTemplate from './workspaceTemplate' import 'react-multi-carousel/lib/styles.css' import CustomNavButtons from './customNavButtons' -import isElectron from 'is-electron' +import { AppContext, appPlatformTypes } from '@remix-ui/app' declare global { interface Window { _paq: any @@ -19,6 +19,7 @@ interface HomeTabGetStartedProps { } function HomeTabGetStarted({plugin}: HomeTabGetStartedProps) { + const {platform} = useContext(AppContext) const themeFilter = useContext(ThemeContext) const carouselRef = useRef({}) const carouselRefDiv = useRef(null) @@ -59,7 +60,7 @@ function HomeTabGetStarted({plugin}: HomeTabGetStartedProps) { } const createWorkspace = async (templateName) => { - if(isElectron()){ + if(platform === appPlatformTypes.desktop){ await plugin.call('remix-templates', 'loadTemplateInNewWindow', templateName) return } diff --git a/libs/remix-ui/home-tab/src/lib/remix-ui-home-tab.tsx b/libs/remix-ui/home-tab/src/lib/remix-ui-home-tab.tsx index 116e724ab6..0750d61e90 100644 --- a/libs/remix-ui/home-tab/src/lib/remix-ui-home-tab.tsx +++ b/libs/remix-ui/home-tab/src/lib/remix-ui-home-tab.tsx @@ -1,4 +1,4 @@ -import React, {useState, useEffect} from 'react' // eslint-disable-line +import React, {useState, useEffect, useContext} from 'react' // eslint-disable-line import './remix-ui-home-tab.css' import {ThemeContext, themes} from './themeContext' @@ -9,7 +9,7 @@ import HomeTabScamAlert from './components/homeTabScamAlert' import HomeTabGetStarted from './components/homeTabGetStarted' import HomeTabFeatured from './components/homeTabFeatured' import HomeTabFeaturedPlugins from './components/homeTabFeaturedPlugins' -import isElectron from 'is-electron' +import { AppContext, appPlatformTypes } from '@remix-ui/app' import { HomeTabFileElectron } from './components/homeTabFileElectron' import { LanguageOptions } from './components/homeTablangOptions' @@ -24,6 +24,7 @@ export interface RemixUiHomeTabProps { } export const RemixUiHomeTab = (props: RemixUiHomeTabProps) => { + const {platform} = useContext(AppContext) const {plugin} = props const [state, setState] = useState<{ @@ -59,7 +60,7 @@ export const RemixUiHomeTab = (props: RemixUiHomeTabProps) => {
- {!isElectron()? + {!(platform === appPlatformTypes.desktop) ? : } diff --git a/libs/remix-ui/panel/src/lib/main/main-panel.tsx b/libs/remix-ui/panel/src/lib/main/main-panel.tsx index 5b7200c8eb..ff9b395007 100644 --- a/libs/remix-ui/panel/src/lib/main/main-panel.tsx +++ b/libs/remix-ui/panel/src/lib/main/main-panel.tsx @@ -1,9 +1,9 @@ /* eslint-disable no-unused-expressions */ -import isElectron from 'is-electron' import React, {useContext, useEffect, useRef, useState} from 'react' // eslint-disable-line import DragBar from '../dragbar/dragbar' import RemixUIPanelPlugin from '../plugins/panel-plugin' import {PluginRecord} from '../types' +import { AppContext, appPlatformTypes } from '@remix-ui/app' import './main-panel.css' @@ -12,6 +12,7 @@ export type RemixUIMainPanelProps = { } const RemixUIMainPanel = (props: RemixUIMainPanelProps) => { + const {platform} = useContext(AppContext) const appContext = useContext(props.Context) const [plugins, setPlugins] = useState([]) const editorRef = useRef(null) @@ -29,7 +30,7 @@ const RemixUIMainPanel = (props: RemixUIMainPanelProps) => { profile: panel.plugin.profile, active: panel.active, view: panel.plugin.profile.name === 'tabs' ? panel.plugin.renderTabsbar() : panel.plugin.render(), - class: panel.plugin.profile.name + '-wrap ' + (panel.minimized ? 'minimized ' : ' ') + (isElectron()? 'desktop' : ''), + class: panel.plugin.profile.name + '-wrap ' + (panel.minimized ? 'minimized ' : ' ') + ((platform === appPlatformTypes.desktop)? 'desktop' : ''), minimized: panel.minimized }) }) diff --git a/libs/remix-ui/search/src/lib/components/results/SearchHelper.ts b/libs/remix-ui/search/src/lib/components/results/SearchHelper.ts index 22e94e05f7..09900607ef 100644 --- a/libs/remix-ui/search/src/lib/components/results/SearchHelper.ts +++ b/libs/remix-ui/search/src/lib/components/results/SearchHelper.ts @@ -1,12 +1,12 @@ import { EOL } from 'os' import { SearchResultLineLine } from '../../types' -import isElectron from 'is-electron' +import Registry from 'apps/remix-ide/src/app/state/registry' export const getDirectory = async (dir: string, plugin: any) => { let result = [] - if (isElectron()) { + if (Registry.getInstance().get('platform').api.isDesktop()) { const files = await plugin.call('ripgrep', 'glob', dir, '**/*') // only get path property of files diff --git a/libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx b/libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx index e28d5a2962..86987b39c9 100644 --- a/libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx +++ b/libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx @@ -1,4 +1,4 @@ -import React, {useEffect, useState, useRef, useReducer} from 'react' // eslint-disable-line +import React, {useEffect, useState, useRef, useReducer, useContext} from 'react' // eslint-disable-line import {FormattedMessage, useIntl} from 'react-intl' import semver from 'semver' import {CompilerContainerProps} from './types' @@ -11,9 +11,9 @@ import {getValidLanguage} from '@remix-project/remix-solidity' import {CopyToClipboard} from '@remix-ui/clipboard' import {configFileContent} from './compilerConfiguration' import axios, {AxiosResponse} from 'axios' +import { AppContext, appPlatformTypes } from '@remix-ui/app' import './css/style.css' -import isElectron from 'is-electron' const defaultPath = 'compiler_config.json' declare global { @@ -25,6 +25,7 @@ declare global { const _paq = (window._paq = window._paq || []) //eslint-disable-line export const CompilerContainer = (props: CompilerContainerProps) => { + const {platform} = useContext(AppContext) const { api, compileTabLogic, @@ -576,7 +577,7 @@ export const CompilerContainer = (props: CompilerContainerProps) => { // "Uncaught RangeError: Maximum call stack size exceeded" error on Chromium, // resort to non-worker version in that case. if (selectedVersion === 'builtin') selectedVersion = state.defaultVersion - if (selectedVersion !== 'builtin' && (canUseWorker(selectedVersion) || isElectron())) { + if (selectedVersion !== 'builtin' && (canUseWorker(selectedVersion) || platform === appPlatformTypes.desktop)) { compileTabLogic.compiler.loadVersion(true, url) } else { compileTabLogic.compiler.loadVersion(false, url) diff --git a/libs/remix-ui/solidity-unit-testing/src/lib/solidity-unit-testing.tsx b/libs/remix-ui/solidity-unit-testing/src/lib/solidity-unit-testing.tsx index a03903f1a6..f4f943dd1c 100644 --- a/libs/remix-ui/solidity-unit-testing/src/lib/solidity-unit-testing.tsx +++ b/libs/remix-ui/solidity-unit-testing/src/lib/solidity-unit-testing.tsx @@ -1,4 +1,4 @@ -import React, { useState, useRef, useEffect, ReactElement } from 'react' // eslint-disable-line +import React, { useState, useRef, useEffect, ReactElement, useContext } from 'react' // eslint-disable-line import { FormattedMessage, useIntl } from 'react-intl' import * as semver from 'semver' import { eachOfSeries } from 'async' // eslint-disable-line @@ -9,7 +9,7 @@ import { Toaster } from '@remix-ui/toaster' // eslint-disable-line import { format } from 'util' import './css/style.css' import { CustomTooltip } from '@remix-ui/helper' -import isElectron from 'is-electron' +import { AppContext, appPlatformTypes } from '@remix-ui/app' const _paq = ((window as any)._paq = (window as any)._paq || []) // eslint-disable-line @typescript-eslint/no-explicit-any @@ -44,7 +44,7 @@ interface FinalResult { export const SolidityUnitTesting = (props: Record) => { // eslint-disable-line @typescript-eslint/no-explicit-any - + const {platform} = useContext(AppContext) const { helper, testTab, initialPath } = props const { testTabLogic } = testTab @@ -608,7 +608,7 @@ export const SolidityUnitTesting = (props: Record) => { currentCompilerUrl, evmVersion, optimize, - usingWorker: canUseWorker(currentVersion) || isElectron(), + usingWorker: canUseWorker(currentVersion) || platform === appPlatformTypes.desktop, runs, } const deployCb = async (file: string, contractAddress: string) => { diff --git a/libs/remix-ui/workspace/src/lib/actions/index.ts b/libs/remix-ui/workspace/src/lib/actions/index.ts index 5524304cab..635e5c371d 100644 --- a/libs/remix-ui/workspace/src/lib/actions/index.ts +++ b/libs/remix-ui/workspace/src/lib/actions/index.ts @@ -8,8 +8,8 @@ import { createWorkspaceTemplate, getWorkspaces, loadWorkspacePreset, setPlugin, import { QueryParams } from '@remix-project/remix-lib' import { fetchContractFromEtherscan } from '@remix-project/core-plugin' // eslint-disable-line import JSZip from 'jszip' -import isElectron from 'is-electron' import { Actions, FileTree } from '../types' +import Registry from 'apps/remix-ide/src/app/state/registry' export * from './events' export * from './workspace' @@ -55,7 +55,7 @@ export const initWorkspace = (filePanelPlugin) => async (reducerDispatch: React. const electrOnProvider = filePanelPlugin.fileProviders.electron const params = queryParams.get() as UrlParametersType let workspaces = [] - if (!isElectron()) { + if (!(Registry.getInstance().get('platform').api.isDesktop())) { workspaces = await getWorkspaces() || [] dispatch(setWorkspaces(workspaces)) } @@ -118,7 +118,7 @@ export const initWorkspace = (filePanelPlugin) => async (reducerDispatch: React. await basicWorkspaceInit(workspaces, workspaceProvider) } } else await basicWorkspaceInit(workspaces, workspaceProvider) - } else if (isElectron()) { + } else if (Registry.getInstance().get('platform').api.isDesktop()) { if (params.opendir) { params.opendir = decodeURIComponent(params.opendir) plugin.call('notification', 'toast', `opening ${params.opendir}...`) @@ -154,7 +154,7 @@ export const initWorkspace = (filePanelPlugin) => async (reducerDispatch: React. listenOnProviderEvents(workspaceProvider)(dispatch) listenOnProviderEvents(localhostProvider)(dispatch) listenOnProviderEvents(electrOnProvider)(dispatch) - if (isElectron()) { + if (Registry.getInstance().get('platform').api.isDesktop()) { dispatch(setMode('browser')) } else { dispatch(setMode('browser')) diff --git a/libs/remix-ui/workspace/src/lib/actions/workspace.ts b/libs/remix-ui/workspace/src/lib/actions/workspace.ts index 7830c108b4..9b2baf385a 100644 --- a/libs/remix-ui/workspace/src/lib/actions/workspace.ts +++ b/libs/remix-ui/workspace/src/lib/actions/workspace.ts @@ -38,7 +38,6 @@ import { IndexedDBStorage } from '../../../../../../apps/remix-ide/src/app/files import { getUncommittedFiles } from '../utils/gitStatusFilter' import { AppModal, ModalTypes } from '@remix-ui/app' import { contractDeployerScripts, etherscanScripts } from '@remix-project/remix-ws-templates' -import isElectron from 'is-electron' declare global { interface Window { @@ -120,7 +119,7 @@ export const createWorkspace = async ( isGitRepo: boolean = false, createCommit: boolean = true ) => { - if (isElectron()) { + if (plugin.registry.get('platform').api.isDesktop()) { if (workspaceTemplateName) { await plugin.call('remix-templates', 'loadTemplateInNewWindow', workspaceTemplateName, opts) } @@ -577,7 +576,7 @@ export const cloneRepository = async (url: string) => { const token = config.get('settings/gist-access-token') const repoConfig = { url, token } - if (isElectron()) { + if (plugin.registry.get('platform').api.isDesktop()) { try { await plugin.call('dGitProvider', 'clone', repoConfig) } catch (e) { diff --git a/libs/remix-ui/workspace/src/lib/components/electron-menu.tsx b/libs/remix-ui/workspace/src/lib/components/electron-menu.tsx index 832caba679..455ef906bf 100644 --- a/libs/remix-ui/workspace/src/lib/components/electron-menu.tsx +++ b/libs/remix-ui/workspace/src/lib/components/electron-menu.tsx @@ -1,15 +1,16 @@ import React, { MouseEventHandler, useContext, useEffect, useState } from "react" import { FileSystemContext } from "../contexts" -import isElectron from 'is-electron' +import { AppContext, appPlatformTypes } from '@remix-ui/app' import { FormattedMessage } from "react-intl" import '../css/electron-menu.css' import { CustomTooltip } from '@remix-ui/helper' export const ElectronMenu = () => { + const {platform} = useContext(AppContext) const global = useContext(FileSystemContext) useEffect(() => { - if (isElectron()) { + if (platform === appPlatformTypes.desktop) { global.dispatchGetElectronRecentFolders() } }, []) @@ -24,7 +25,7 @@ export const ElectronMenu = () => { } return ( - !isElectron() ? null : + (platform !== appPlatformTypes.desktop) ? null : (global.fs.browser.isSuccessfulWorkspace ? null : <>
{ await openFolderElectron(null) }} className='btn btn-primary'>
diff --git a/libs/remix-ui/workspace/src/lib/components/file-explorer-context-menu.tsx b/libs/remix-ui/workspace/src/lib/components/file-explorer-context-menu.tsx index 9084d3acae..4da93ddcce 100644 --- a/libs/remix-ui/workspace/src/lib/components/file-explorer-context-menu.tsx +++ b/libs/remix-ui/workspace/src/lib/components/file-explorer-context-menu.tsx @@ -1,11 +1,11 @@ -import React, {useRef, useEffect, useState} from 'react' // eslint-disable-line +import React, {useRef, useEffect, useState, useContext} from 'react' // eslint-disable-line import {useIntl} from 'react-intl' import {action, FileExplorerContextMenuProps} from '../types' import '../css/file-explorer-context-menu.css' import {customAction} from '@remixproject/plugin-api' import UploadFile from './upload-file' -import isElectron from 'is-electron' +import { AppContext, appPlatformTypes } from '@remix-ui/app' declare global { interface Window { @@ -15,6 +15,7 @@ declare global { const _paq = (window._paq = window._paq || []) //eslint-disable-line export const FileExplorerContextMenu = (props: FileExplorerContextMenuProps) => { + const {platform} = useContext(AppContext) const { actions, createNewFile, @@ -83,7 +84,7 @@ export const FileExplorerContextMenu = (props: FileExplorerContextMenuProps) => } const itemMatchesCondition = (item: action, itemType: string, itemPath: string) => { - if( isElectron() && item.platform && item.platform === 'browser') return false + if( platform === appPlatformTypes.desktop && item.platform && item.platform === appPlatformTypes.web) return false else if (item.type && Array.isArray(item.type) && (item.type.findIndex(name => name === itemType) !== -1)) return true else if (item.path && Array.isArray(item.path) && (item.path.findIndex(key => key === itemPath) !== -1)) return true else if (item.extension && Array.isArray(item.extension) && (item.extension.findIndex(ext => itemPath.endsWith(ext)) !== -1)) return true diff --git a/libs/remix-ui/workspace/src/lib/components/workspace-hamburger-item.tsx b/libs/remix-ui/workspace/src/lib/components/workspace-hamburger-item.tsx index ed2820669a..d66959a1bb 100644 --- a/libs/remix-ui/workspace/src/lib/components/workspace-hamburger-item.tsx +++ b/libs/remix-ui/workspace/src/lib/components/workspace-hamburger-item.tsx @@ -2,8 +2,7 @@ import React, { useContext } from 'react' import {CustomTooltip, CustomMenu, CustomIconsToggle} from '@remix-ui/helper' import {Dropdown, NavDropdown} from 'react-bootstrap' import {FormattedMessage} from 'react-intl' -import { AppContext, appPlatformType } from 'libs/remix-ui/app/src/lib/remix-app/context/context' - +import { AppContext, appPlatformTypes } from '@remix-ui/app' const _paq = (window._paq = window._paq || []) export interface HamburgerMenuItemProps { @@ -11,7 +10,7 @@ export interface HamburgerMenuItemProps { kind: string actionOnClick: () => void fa: string - platforms: appPlatformType[] + platforms: appPlatformTypes[] } export function HamburgerMenuItem(props: HamburgerMenuItemProps) { @@ -73,7 +72,7 @@ export interface HamburgerSubMenuItemProps { id: string title: string subMenus: Array - platforms: appPlatformType[] + platforms: appPlatformTypes[] } export function HamburgerSubMenuItem(props: HamburgerSubMenuItemProps) { diff --git a/libs/remix-ui/workspace/src/lib/components/workspace-hamburger.tsx b/libs/remix-ui/workspace/src/lib/components/workspace-hamburger.tsx index c4c79fbc55..909dc59d56 100644 --- a/libs/remix-ui/workspace/src/lib/components/workspace-hamburger.tsx +++ b/libs/remix-ui/workspace/src/lib/components/workspace-hamburger.tsx @@ -1,3 +1,4 @@ +import { appPlatformTypes } from 'libs/remix-ui/app/src/lib/remix-app/context/context' import React from 'react' import {Dropdown} from 'react-bootstrap' import {HamburgerMenuItem, HamburgerSubMenuItem} from './workspace-hamburger-item' @@ -33,7 +34,7 @@ export function HamburgerMenu(props: HamburgerMenuProps) { props.createWorkspace() props.hideIconsMenu(!showIconsMenu) }} - platforms={['web', 'desktop']} + platforms={[appPlatformTypes.web, appPlatformTypes.desktop]} > ) diff --git a/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx b/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx index a217347909..30c160a7f7 100644 --- a/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx +++ b/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx @@ -12,7 +12,7 @@ import {MenuItems, WorkSpaceState} from './types' import {contextMenuActions} from './utils' import FileExplorerContextMenu from './components/file-explorer-context-menu' import { customAction } from '@remixproject/plugin-api' -import isElectron from 'is-electron' +import { AppContext, appPlatformTypes } from '@remix-ui/app' import { ElectronMenu } from './components/electron-menu' const _paq = (window._paq = window._paq || []) @@ -20,6 +20,7 @@ const _paq = (window._paq = window._paq || []) const canUpload = window.File || window.FileReader || window.FileList || window.Blob export function Workspace() { + const {platform} = useContext(AppContext) const LOCALHOST = ' - connect to localhost - ' const NO_WORKSPACE = ' - none - ' const ELECTRON = 'electron' @@ -229,7 +230,6 @@ export function Workspace() { } const cloneGitRepository = () => { - console.log('clone from workspace modal') global.modal( intl.formatMessage({id: 'filePanel.workspace.clone'}), cloneModalMessage(), @@ -935,7 +935,7 @@ export function Workspace() {
- {!isElectron() ? ( + {(platform !== appPlatformTypes.desktop) ? ( , path?: string[], extension?: string[], pattern?: string[], id: string, multiselect: boolean, label: string, sticky?: boolean, group: number, platform?: 'electron' | 'browser' } +export type action = { name: string, type?: Array, path?: string[], extension?: string[], pattern?: string[], id: string, multiselect: boolean, label: string, sticky?: boolean, group: number, platform?: appPlatformTypes } export interface JSONStandardInput { language: 'Solidity' settings?: any diff --git a/libs/remix-ui/workspace/src/lib/utils/index.ts b/libs/remix-ui/workspace/src/lib/utils/index.ts index 0302c0fbd2..726abbcfa8 100644 --- a/libs/remix-ui/workspace/src/lib/utils/index.ts +++ b/libs/remix-ui/workspace/src/lib/utils/index.ts @@ -1,3 +1,4 @@ +import { appPlatformTypes } from '@remix-ui/app' import { FileType } from '@remix-ui/file-decorators' import { WorkspaceProps, MenuItems } from '../types' @@ -64,7 +65,7 @@ export const contextMenuActions: MenuItems = [{ multiselect: false, label: '', group: 2, - platform: 'browser' + platform: appPlatformTypes.web }, { id: 'run', name: 'Run', @@ -79,7 +80,7 @@ export const contextMenuActions: MenuItems = [{ multiselect: false, label: '', group: 4, - platform: 'browser' + platform: appPlatformTypes.web }, { id: 'publishFolderToGist', name: 'Publish folder to gist', @@ -87,7 +88,7 @@ export const contextMenuActions: MenuItems = [{ multiselect: false, label: '', group: 4, - platform: 'browser' + platform: appPlatformTypes.web }, { id: 'publishFileToGist', name: 'Publish file to gist', @@ -95,7 +96,7 @@ export const contextMenuActions: MenuItems = [{ multiselect: false, label: '', group: 4, - platform: 'browser' + platform: appPlatformTypes.web }, { id: 'uploadFile', name: 'Load a Local File', @@ -103,7 +104,7 @@ export const contextMenuActions: MenuItems = [{ multiselect: false, label: 'Load a Local File', group: 4, - platform: 'browser' + platform: appPlatformTypes.web }, { id: 'publishToGist', name: 'Push changes to gist', @@ -111,7 +112,7 @@ export const contextMenuActions: MenuItems = [{ multiselect: false, label: 'Publish all to Gist', group: 4, - platform: 'browser' + platform: appPlatformTypes.web }, { id: 'publishWorkspace', @@ -120,7 +121,7 @@ export const contextMenuActions: MenuItems = [{ multiselect: false, label: '', group: 4, - platform: 'browser' + platform: appPlatformTypes.web }] export const fileKeySort = (children: FileType[]): string[] => {