rdesktop2
filip mertens 1 year ago
parent 673258ef87
commit d2eea4eea2
  1. 56
      apps/remix-ide/src/app/files/dgitProvider.ts
  2. 10
      apps/remix-ide/src/app/files/electronProvider.ts
  3. 2
      apps/remix-ide/src/app/files/fileManager.ts
  4. 31
      apps/remix-ide/src/app/files/fileProvider.ts
  5. 1
      apps/remix-ide/src/app/panels/terminal.js
  6. 1
      apps/remix-ide/src/app/tabs/theme-module.js
  7. 1
      apps/remix-ide/src/remixAppManager.js

@ -10,10 +10,11 @@ import {
} from 'file-saver' } from 'file-saver'
import http from 'isomorphic-git/http/web' import http from 'isomorphic-git/http/web'
const JSZip = require('jszip') import JSZip from 'jszip'
const path = require('path') import path from 'path'
const FormData = require('form-data') import FormData from 'form-data'
const axios = require('axios') import axios from 'axios'
import isElectron from 'is-electron'
const profile = { const profile = {
name: 'dGitProvider', name: 'dGitProvider',
@ -25,6 +26,12 @@ const profile = {
kind: 'file-system' kind: 'file-system'
} }
class DGitProvider extends Plugin { class DGitProvider extends Plugin {
ipfsconfig: { host: string; port: number; protocol: string; ipfsurl: string }
globalIPFSConfig: { host: string; port: number; protocol: string; ipfsurl: string }
remixIPFS: { host: string; port: number; protocol: string; ipfsurl: string }
ipfsSources: any[]
ipfs: any
filesToSend: any[]
constructor() { constructor() {
super(profile) super(profile)
this.ipfsconfig = { this.ipfsconfig = {
@ -48,9 +55,6 @@ class DGitProvider extends Plugin {
this.ipfsSources = [this.remixIPFS, this.globalIPFSConfig, this.ipfsconfig] this.ipfsSources = [this.remixIPFS, this.globalIPFSConfig, this.ipfsconfig]
} }
async onActivation() {
}
async getGitConfig() { async getGitConfig() {
if (isElectron()) { if (isElectron()) {
@ -84,7 +88,7 @@ class DGitProvider extends Plugin {
} }
} }
async init(input) { async init(input?) {
if (isElectron()) { if (isElectron()) {
await this.call('isogit', 'init', { await this.call('isogit', 'init', {
defaultBranch: (input && input.branch) || 'main' defaultBranch: (input && input.branch) || 'main'
@ -346,7 +350,7 @@ class DGitProvider extends Plugin {
}) })
} }
async checkIpfsConfig(config) { async checkIpfsConfig(config?) {
this.ipfs = IpfsHttpClient(config || this.ipfsconfig) this.ipfs = IpfsHttpClient(config || this.ipfsconfig)
try { try {
await this.ipfs.config.getAll() await this.ipfs.config.getAll()
@ -395,7 +399,7 @@ class DGitProvider extends Plugin {
} else { } else {
const permission = await this.askUserPermission('clone', 'Import multiple files into your workspaces.') const permission = await this.askUserPermission('clone', 'Import multiple files into your workspaces.')
if (!permission) return false if (!permission) return false
if (this.calculateLocalStorage() > 10000) throw new Error('The local storage of the browser is full.') if (parseFloat(this.calculateLocalStorage()) > 10000) throw new Error('The local storage of the browser is full.')
if (!workspaceExists) await this.call('filePanel', 'createWorkspace', workspaceName || `workspace_${Date.now()}`, true) if (!workspaceExists) await this.call('filePanel', 'createWorkspace', workspaceName || `workspace_${Date.now()}`, true)
const cmd = { const cmd = {
url: input.url, url: input.url,
@ -427,19 +431,19 @@ class DGitProvider extends Plugin {
name: input.name, name: input.name,
email: input.email email: input.email
}, },
input input,
} }
if (isElectron()) { if (isElectron()) {
return await this.call('isogit', 'push', cmd) return await this.call('isogit', 'push', cmd)
} else { } else {
cmd = { const cmd2 = {
...cmd, ...cmd,
...await this.parseInput(input), ...await this.parseInput(input),
} }
return await git.push({ return await git.push({
...await this.getGitConfig(), ...await this.getGitConfig(),
...cmd ...cmd2
}) })
} }
@ -454,20 +458,20 @@ class DGitProvider extends Plugin {
email: input.email email: input.email
}, },
remote: input.remote, remote: input.remote,
input input,
} }
let result let result
if (isElectron()) { if (isElectron()) {
result = await this.call('isogit', 'pull', cmd) result = await this.call('isogit', 'pull', cmd)
} }
else { else {
cmd = { const cmd2 = {
...cmd, ...cmd,
...await this.parseInput(input), ...await this.parseInput(input),
} }
result = await git.pull({ result = await git.pull({
...await this.getGitConfig(), ...await this.getGitConfig(),
...cmd ...cmd2
}) })
} }
setTimeout(async () => { setTimeout(async () => {
@ -491,13 +495,13 @@ class DGitProvider extends Plugin {
if (isElectron()) { if (isElectron()) {
result = await this.call('isogit', 'fetch', cmd) result = await this.call('isogit', 'fetch', cmd)
} else { } else {
cmd = { const cmd2 = {
...cmd, ...cmd,
...await this.parseInput(input), ...await this.parseInput(input),
} }
result = await git.fetch({ result = await git.fetch({
...await this.getGitConfig(), ...await this.getGitConfig(),
...cmd ...cmd2
}) })
} }
setTimeout(async () => { setTimeout(async () => {
@ -579,15 +583,15 @@ class DGitProvider extends Plugin {
.post(url, data, { .post(url, data, {
maxBodyLength: 'Infinity', maxBodyLength: 'Infinity',
headers: { headers: {
'Content-Type': `multipart/form-data; boundary=${data._boundary}`, 'Content-Type': `multipart/form-data; boundary=${(data as any)._boundary}`,
pinata_api_key: pinataApiKey, pinata_api_key: pinataApiKey,
pinata_secret_api_key: pinataSecretApiKey pinata_secret_api_key: pinataSecretApiKey
} }
}).catch((e) => { } as any).catch((e) => {
console.log(e) console.log(e)
}) })
// also commit to remix IPFS for availability after pinning to Pinata // also commit to remix IPFS for availability after pinning to Pinata
return await this.export(this.remixIPFS) || result.data.IpfsHash return await this.export(this.remixIPFS) || (result as any).data.IpfsHash
} catch (error) { } catch (error) {
throw new Error(error) throw new Error(error)
} }
@ -603,10 +607,10 @@ class DGitProvider extends Plugin {
pinata_api_key: pinataApiKey, pinata_api_key: pinataApiKey,
pinata_secret_api_key: pinataSecretApiKey pinata_secret_api_key: pinataSecretApiKey
} }
}).catch((e) => { } as any).catch((e) => {
console.log('Pinata unreachable') console.log('Pinata unreachable')
}) })
return result.data return (result as any).data
} catch (error) { } catch (error) {
throw new Error(error) throw new Error(error)
} }
@ -658,8 +662,8 @@ class DGitProvider extends Plugin {
} }
calculateLocalStorage() { calculateLocalStorage() {
var _lsTotal = 0 let _lsTotal = 0
var _xLen; var _x let _xLen; let _x
for (_x in localStorage) { for (_x in localStorage) {
// eslint-disable-next-line no-prototype-builtins // eslint-disable-next-line no-prototype-builtins
if (!localStorage.hasOwnProperty(_x)) { if (!localStorage.hasOwnProperty(_x)) {
@ -674,7 +678,7 @@ class DGitProvider extends Plugin {
async import(cmd) { async import(cmd) {
const permission = await this.askUserPermission('import', 'Import multiple files into your workspaces.') const permission = await this.askUserPermission('import', 'Import multiple files into your workspaces.')
if (!permission) return false if (!permission) return false
if (this.calculateLocalStorage() > 10000) throw new Error('The local storage of the browser is full.') if (parseFloat(this.calculateLocalStorage()) > 10000) throw new Error('The local storage of the browser is full.')
const cid = cmd.cid const cid = cmd.cid
await this.call('filePanel', 'createWorkspace', `workspace_${Date.now()}`, true) await this.call('filePanel', 'createWorkspace', `workspace_${Date.now()}`, true)
const workspace = await this.call('filePanel', 'getCurrentWorkspace') const workspace = await this.call('filePanel', 'getCurrentWorkspace')

@ -1,4 +1,5 @@
const FileProvider = require('./fileProvider') import { FileProvider } from "./fileProvider"
declare global { declare global {
interface Window { interface Window {
@ -7,6 +8,7 @@ declare global {
} }
export class ElectronProvider extends FileProvider { export class ElectronProvider extends FileProvider {
_appManager: any
constructor(appManager) { constructor(appManager) {
super('') super('')
this._appManager = appManager this._appManager = appManager
@ -48,7 +50,7 @@ export class ElectronProvider extends FileProvider {
const files = await window.remixFileSystem.readdir(path) const files = await window.remixFileSystem.readdir(path)
const ret = {} const ret = {}
if (files) { if (files) {
for (let element of files) { for (const element of files) {
path = path.replace(/^\/|\/$/g, '') // remove first and last slash path = path.replace(/^\/|\/$/g, '') // remove first and last slash
const file = element.file.replace(/^\/|\/$/g, '') // remove first and last slash const file = element.file.replace(/^\/|\/$/g, '') // remove first and last slash
const absPath = (path === '/' ? '' : path) + '/' + file const absPath = (path === '/' ? '' : path) + '/' + file
@ -68,12 +70,14 @@ export class ElectronProvider extends FileProvider {
* Removes the folder recursively * Removes the folder recursively
* @param {*} path is the folder to be removed * @param {*} path is the folder to be removed
*/ */
async remove(path) { async remove(path: string) {
console.log('remove', path) console.log('remove', path)
try { try {
await window.remixFileSystem.rmdir(path) await window.remixFileSystem.rmdir(path)
return true
} catch (error) { } catch (error) {
console.log(error) console.log(error)
return false
} }
} }

@ -9,7 +9,7 @@ import { fileChangedToastMsg, recursivePasteToastMsg, storageFullMessage } from
import helper from '../../lib/helper.js' import helper from '../../lib/helper.js'
import { RemixAppManager } from '../../remixAppManager' import { RemixAppManager } from '../../remixAppManager'
const isElectron = require('is-electron') import isElectron from 'is-electron'
/* /*
attach to files event (removed renamed) attach to files event (removed renamed)

@ -1,12 +1,17 @@
'use strict' 'use strict'
import { CompilerImports } from '@remix-project/core-plugin' import { CompilerImports } from '@remix-project/core-plugin'
const EventManager = require('events') import EventManager from 'events'
const remixLib = require('@remix-project/remix-lib') import { Storage } from '@remix-project/remix-lib'
const pathModule = require('path') import pathModule from 'path'
const Storage = remixLib.Storage
export class FileProvider { export class FileProvider {
event: any
type: any
providerExternalsStorage: any
externalFolders: string[]
reverseKey: string
constructor (name) { constructor (name) {
this.event = new EventManager() this.event = new EventManager()
this.type = name this.type = name
@ -79,7 +84,7 @@ export class FileProvider {
async _exists (path) { async _exists (path) {
path = this.getPathFromUrl(path) || path // ensure we actually use the normalized path from here path = this.getPathFromUrl(path) || path // ensure we actually use the normalized path from here
var unprefixedpath = this.removePrefix(path) const unprefixedpath = this.removePrefix(path)
return path === this.type ? true : await window.remixFileSystem.exists(unprefixedpath) return path === this.type ? true : await window.remixFileSystem.exists(unprefixedpath)
} }
@ -90,7 +95,7 @@ export class FileProvider {
async get (path, cb) { async get (path, cb) {
cb = cb || function () { /* do nothing. */ } cb = cb || function () { /* do nothing. */ }
path = this.getPathFromUrl(path) || path // ensure we actually use the normalized path from here path = this.getPathFromUrl(path) || path // ensure we actually use the normalized path from here
var unprefixedpath = this.removePrefix(path) const unprefixedpath = this.removePrefix(path)
try { try {
const content = await window.remixFileSystem.readFile(unprefixedpath, 'utf8') const content = await window.remixFileSystem.readFile(unprefixedpath, 'utf8')
if (cb) cb(null, content) if (cb) cb(null, content)
@ -103,13 +108,13 @@ export class FileProvider {
async set (path, content, cb) { async set (path, content, cb) {
cb = cb || function () { /* do nothing. */ } cb = cb || function () { /* do nothing. */ }
var unprefixedpath = this.removePrefix(path) const unprefixedpath = this.removePrefix(path)
const exists = await window.remixFileSystem.exists(unprefixedpath) const exists = await window.remixFileSystem.exists(unprefixedpath)
if (exists && await window.remixFileSystem.readFile(unprefixedpath, 'utf8') === content) { if (exists && await window.remixFileSystem.readFile(unprefixedpath, 'utf8') === content) {
if (cb) cb() if (cb) cb()
return null return null
} }
await this.createDir(path.substr(0, path.lastIndexOf('/'))) await this.createDir(path.substr(0, path.lastIndexOf('/')), null)
try { try {
await window.remixFileSystem.writeFile(unprefixedpath, content, 'utf8') await window.remixFileSystem.writeFile(unprefixedpath, content, 'utf8')
} catch (e) { } catch (e) {
@ -152,7 +157,7 @@ export class FileProvider {
// this will not add a folder as readonly but keep the original url to be able to restore it later // this will not add a folder as readonly but keep the original url to be able to restore it later
async addExternal (path, content, url) { async addExternal (path, content, url) {
if (url) this.addNormalizedName(path, url) if (url) this.addNormalizedName(path, url)
return await this.set(path, content) return await this.set(path, content, null)
} }
isReadOnly (path) { isReadOnly (path) {
@ -175,7 +180,7 @@ export class FileProvider {
* Removes the folder recursively * Removes the folder recursively
* @param {*} path is the folder to be removed * @param {*} path is the folder to be removed
*/ */
async remove (path) { async remove (path: string) {
path = this.removePrefix(path) path = this.removePrefix(path)
if (await window.remixFileSystem.exists(path)) { if (await window.remixFileSystem.exists(path)) {
const stat = await window.remixFileSystem.stat(path) const stat = await window.remixFileSystem.stat(path)
@ -226,7 +231,7 @@ export class FileProvider {
visitFolder({ path }) visitFolder({ path })
if (items.length !== 0) { if (items.length !== 0) {
for (const item of items) { for (const item of items) {
const file = {} const file: any = {}
const curPath = `${path}${path.endsWith('/') ? '' : '/'}${item}` const curPath = `${path}${path.endsWith('/') ? '' : '/'}${item}`
if ((await window.remixFileSystem.stat(curPath)).isDirectory()) { if ((await window.remixFileSystem.stat(curPath)).isDirectory()) {
file.children = await this._copyFolderToJsonInternal(curPath, visitFile, visitFolder) file.children = await this._copyFolderToJsonInternal(curPath, visitFile, visitFolder)
@ -267,8 +272,8 @@ export class FileProvider {
} }
async rename (oldPath, newPath, isFolder) { async rename (oldPath, newPath, isFolder) {
var unprefixedoldPath = this.removePrefix(oldPath) const unprefixedoldPath = this.removePrefix(oldPath)
var unprefixednewPath = this.removePrefix(newPath) const unprefixednewPath = this.removePrefix(newPath)
if (await this._exists(unprefixedoldPath)) { if (await this._exists(unprefixedoldPath)) {
await window.remixFileSystem.rename(unprefixedoldPath, unprefixednewPath) await window.remixFileSystem.rename(unprefixedoldPath, unprefixednewPath)
this.event.emit('fileRenamed', this.event.emit('fileRenamed',

@ -6,6 +6,7 @@ import * as packageJson from '../../../../../package.json'
import Registry from '../state/registry' import Registry from '../state/registry'
import { PluginViewWrapper } from '@remix-ui/helper' import { PluginViewWrapper } from '@remix-ui/helper'
import vm from 'vm' import vm from 'vm'
import isElectron from 'is-electron'
const EventManager = require('../../lib/events') const EventManager = require('../../lib/events')
import { CompilerImports } from '@remix-project/core-plugin' // eslint-disable-line import { CompilerImports } from '@remix-project/core-plugin' // eslint-disable-line

@ -3,6 +3,7 @@ import { EventEmitter } from 'events'
import { QueryParams } from '@remix-project/remix-lib' import { QueryParams } from '@remix-project/remix-lib'
import * as packageJson from '../../../../../package.json' import * as packageJson from '../../../../../package.json'
import Registry from '../state/registry' import Registry from '../state/registry'
const isElectron = require('is-electron')
const _paq = window._paq = window._paq || [] const _paq = window._paq = window._paq || []
const themes = [ const themes = [

@ -2,6 +2,7 @@ import { PluginManager } from '@remixproject/engine'
import { EventEmitter } from 'events' import { EventEmitter } from 'events'
import { QueryParams } from '@remix-project/remix-lib' import { QueryParams } from '@remix-project/remix-lib'
import { IframePlugin } from '@remixproject/engine-web' import { IframePlugin } from '@remixproject/engine-web'
const isElectron = require('is-electron')
const _paq = window._paq = window._paq || [] const _paq = window._paq = window._paq || []
// requiredModule removes the plugin from the plugin manager list on UI // requiredModule removes the plugin from the plugin manager list on UI

Loading…
Cancel
Save