pull/5370/head
bunsenstraat 3 years ago
parent 857ad199af
commit c96f3cdcbd
  1. 14
      apps/remix-ide/src/app/files/dgitProvider.js
  2. 42
      apps/remix-ide/src/app/files/fileProvider.js
  3. 13
      apps/remix-ide/src/app/panels/file-panel.js
  4. 1
      apps/remix-ide/src/assets/js/workspace_1632313874650
  5. 11
      apps/remix-ide/src/index.html

@ -52,7 +52,7 @@ class DGitProvider extends Plugin {
const workspace = await this.call('filePanel', 'getCurrentWorkspace') const workspace = await this.call('filePanel', 'getCurrentWorkspace')
return { return {
fs: window.remixFileSystemCallback, fs: window.remixFileSystemCallback,
dir: addSlash(workspace.absolutePath) + '/' dir: addSlash(workspace.absolutePath)
} }
} }
@ -82,7 +82,6 @@ class DGitProvider extends Plugin {
...await this.getGitConfig(), ...await this.getGitConfig(),
...cmd ...cmd
}) })
console.log("STATUS", status, await this.getGitConfig())
return status return status
} }
@ -573,3 +572,14 @@ const normalize = (filesList) => {
} }
module.exports = DGitProvider module.exports = DGitProvider
/*
if (navigator.storage && navigator.storage.estimate) {
const quota = await navigator.storage.estimate();
// quota.usage -> Number of bytes used.
// quota.quota -> Maximum number of bytes available.
const percentageUsed = (quota.usage / quota.quota) * 100;
console.log(`You've used ${percentageUsed}% of the available storage.`);
const remaining = quota.quota - quota.usage;
console.log(`You can write up to ${(remaining/ 1048576).toFixed(2)} more MB.`);
} */

@ -80,7 +80,6 @@ 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) var unprefixedpath = this.removePrefix(path)
console.log(unprefixedpath)
return path === this.type ? true : await window.remixFileSystem.exists(this.addSlash(unprefixedpath)) return path === this.type ? true : await window.remixFileSystem.exists(this.addSlash(unprefixedpath))
} }
@ -91,7 +90,6 @@ class FileProvider {
async get (path, cb) { async get (path, cb) {
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) var unprefixedpath = this.removePrefix(path)
console.log('getting ', unprefixedpath, await window.remixFileSystem.readFile(this.addSlash(unprefixedpath), 'utf8'))
try { try {
const content = await window.remixFileSystem.readFile(this.addSlash(unprefixedpath), 'utf8') const content = await window.remixFileSystem.readFile(this.addSlash(unprefixedpath), 'utf8')
if (cb) cb(null, content) if (cb) cb(null, content)
@ -111,7 +109,6 @@ class FileProvider {
} }
await this.createDir(path.substr(0, path.lastIndexOf('/'))) await this.createDir(path.substr(0, path.lastIndexOf('/')))
console.log('set file', path, unprefixedpath)
try { try {
await window.remixFileSystem.writeFile(this.addSlash(unprefixedpath), content, 'utf8') await window.remixFileSystem.writeFile(this.addSlash(unprefixedpath), content, 'utf8')
} catch (e) { } catch (e) {
@ -158,13 +155,13 @@ class FileProvider {
async isDirectory (path) { async isDirectory (path) {
const unprefixedpath = this.removePrefix(path) const unprefixedpath = this.removePrefix(path)
return path === this.type ? true : (await window.remixFileSystem.stat(this.addSlash(unprefixedpath))).isDirectory() return path === this.type ? true : (await window.remixFileSystem.statExtended(this.addSlash(unprefixedpath))).isDirectory()
} }
async isFile (path) { async isFile (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
path = this.removePrefix(path) path = this.removePrefix(path)
return (await window.remixFileSystem.stat(this.addSlash(path))).isFile() return (await window.remixFileSystem.statExtended(this.addSlash(path))).isFile()
} }
/** /**
@ -173,26 +170,26 @@ class FileProvider {
*/ */
async remove (path) { async remove (path) {
path = this.removePrefix(path) path = this.removePrefix(path)
if (await window.remixFileSystem.exists(path)) { if (await window.remixFileSystem.exists(this.addSlash(path))) {
const stat = await window.remixFileSystem.stat(path) const stat = await window.remixFileSystem.statExtended(this.addSlash(path))
try { try {
if (!stat.isDirectory()) { if (!stat.isDirectory()) {
return (this.removeFile(path)) return (this.removeFile(path))
} else { } else {
const items = await window.remixFileSystem.readdir(path) const items = await window.remixFileSystem.readdir(this.addSlash(path))
if (items.length !== 0) { if (items.length !== 0) {
for (const item of items) { for (const item of items) {
const curPath = `${path}${path.endsWith('/') ? '' : '/'}${item}` const curPath = `${path}${path.endsWith('/') ? '' : '/'}${item}`
if ((await window.remixFileSystem.stat(curPath)).isDirectory()) { // delete folder if ((await window.remixFileSystem.statExtended(curPath)).isDirectory()) { // delete folder
this.remove(curPath) await this.remove(curPath)
} else { // delete file } else { // delete file
this.removeFile(curPath) await this.removeFile(curPath)
} }
} }
if (await window.remixFileSystem.readdir(path).length === 0) await window.remixFileSystem.rmdir(path) if (await window.remixFileSystem.readdir(this.addSlash(path)).length === 0) await window.remixFileSystem.rmdir(path)
} else { } else {
// folder is empty // folder is empty
await window.remixFileSystem.rmdirSync(path) await window.remixFileSystem.rmdir(this.addSlash(path))
} }
this.event.emit('fileRemoved', this._normalizePath(path)) this.event.emit('fileRemoved', this._normalizePath(path))
} }
@ -215,15 +212,15 @@ class FileProvider {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const json = {} const json = {}
path = this.removePrefix(path) path = this.removePrefix(path)
if (window.remixFileSystem.exists(path)) { if (window.remixFileSystem.exists(this.addSlash(path))) {
try { try {
const items = await window.remixFileSystem.readdir(path) const items = await window.remixFileSystem.readdir(this.addSlash(path))
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 = {}
const curPath = `${path}${path.endsWith('/') ? '' : '/'}${item}` const curPath = `${path}${path.endsWith('/') ? '' : '/'}${item}`
if (await window.remixFileSystem.stat(curPath).isDirectory()) { if (await window.remixFileSystem.statExtended(curPath).isDirectory()) {
file.children = await this._copyFolderToJsonInternal(curPath, visitFile, visitFolder) file.children = await this._copyFolderToJsonInternal(curPath, visitFile, visitFolder)
} else { } else {
file.content = window.remixFileSystem.readFileSync(curPath, 'utf8') file.content = window.remixFileSystem.readFileSync(curPath, 'utf8')
@ -255,8 +252,8 @@ class FileProvider {
async removeFile (path) { async removeFile (path) {
path = this.removePrefix(path) path = this.removePrefix(path)
if (await window.remixFileSystem.exists(path) && !(await window.remixFileSystem.stat(path)).isDirectory()) { if (await window.remixFileSystem.exists(this.addSlash(path)) && !(await window.remixFileSystem.statExtended(this.addSlash(path))).isDirectory()) {
await window.remixFileSystem.unlink(path) await window.remixFileSystem.unlink(this.addSlash(path))
this.event.emit('fileRemoved', this._normalizePath(path)) this.event.emit('fileRemoved', this._normalizePath(path))
return true return true
} else return false } else return false
@ -266,7 +263,7 @@ class FileProvider {
var unprefixedoldPath = this.removePrefix(oldPath) var unprefixedoldPath = this.removePrefix(oldPath)
var unprefixednewPath = this.removePrefix(newPath) var unprefixednewPath = this.removePrefix(newPath)
if (await this._exists(unprefixedoldPath)) { if (await this._exists(unprefixedoldPath)) {
await window.remixFileSystem.rename(unprefixedoldPath, unprefixednewPath) await window.remixFileSystem.rename(this.addSlash(unprefixedoldPath), this.addSlash(unprefixednewPath))
this.event.emit('fileRenamed', this.event.emit('fileRenamed',
this._normalizePath(unprefixedoldPath), this._normalizePath(unprefixedoldPath),
this._normalizePath(unprefixednewPath), this._normalizePath(unprefixednewPath),
@ -279,24 +276,21 @@ class FileProvider {
async resolveDirectory (path, cb) { async resolveDirectory (path, cb) {
path = this.removePrefix(path) path = this.removePrefix(path)
console.log('resolve', path)
if (path.indexOf('/') !== 0) path = '/' + path if (path.indexOf('/') !== 0) path = '/' + path
try { try {
const files = await window.remixFileSystem.readdir(path) const files = await window.remixFileSystem.readdir(this.addSlash(path))
const ret = {} const ret = {}
if (files) { if (files) {
for (let element of files) { for (let element of files) {
console.log(path, element)
path = path.replace(/^\/|\/$/g, '') // remove first and last slash path = path.replace(/^\/|\/$/g, '') // remove first and last slash
element = element.replace(/^\/|\/$/g, '') // remove first and last slash element = element.replace(/^\/|\/$/g, '') // remove first and last slash
const absPath = (path === '/' ? '' : path) + '/' + element const absPath = (path === '/' ? '' : path) + '/' + element
ret[absPath.indexOf('/') === 0 ? absPath.substr(1, absPath.length) : absPath] = { isDirectory: (await window.remixFileSystem.stat(this.addSlash(absPath))).isDirectory() } ret[absPath.indexOf('/') === 0 ? absPath.substr(1, absPath.length) : absPath] = { isDirectory: (await window.remixFileSystem.statExtended(this.addSlash(absPath))).isDirectory() }
// ^ ret does not accept path starting with '/' // ^ ret does not accept path starting with '/'
console.log(ret) console.log(ret)
} }
} }
console.log('FILES', ret, files)
if (cb) cb(null, ret) if (cb) cb(null, ret)
return ret return ret
} catch (error) { } catch (error) {

@ -230,19 +230,19 @@ module.exports = class Filepanel extends ViewPlugin {
async processCreateWorkspace (name) { async processCreateWorkspace (name) {
const workspaceProvider = this._deps.fileProviders.workspace const workspaceProvider = this._deps.fileProviders.workspace
const browserProvider = this._deps.fileProviders.browser const browserProvider = this._deps.fileProviders.browser
const workspacePath = 'browser/' + workspaceProvider.workspacesPath + '/' + name const workspacePath = '/' + workspaceProvider.workspacesPath + '/' + name
const workspaceRootPath = 'browser/' + workspaceProvider.workspacesPath const workspaceRootPath = '/' + workspaceProvider.workspacesPath
const workspaceRootPathExists = await browserProvider.exists(workspaceRootPath) const workspaceRootPathExists = await browserProvider.exists(workspaceRootPath)
const workspacePathExists = await browserProvider.exists(workspacePath) const workspacePathExists = await browserProvider.exists(workspacePath)
console.log('CRS', workspacePath, workspaceRootPath, workspacePathExists, workspaceRootPathExists)
if (!workspaceRootPathExists) browserProvider.createDir(workspaceRootPath) if (!workspaceRootPathExists) await browserProvider.createDir(workspaceRootPath)
if (!workspacePathExists) browserProvider.createDir(workspacePath) if (!workspacePathExists) await browserProvider.createDir(workspacePath)
} }
async workspaceExists (name) { async workspaceExists (name) {
const workspaceProvider = this._deps.fileProviders.workspace const workspaceProvider = this._deps.fileProviders.workspace
const browserProvider = this._deps.fileProviders.browser const browserProvider = this._deps.fileProviders.browser
const workspacePath = 'browser/' + workspaceProvider.workspacesPath + '/' + name const workspacePath = '/' + workspaceProvider.workspacesPath + '/' + name
return browserProvider.exists(workspacePath) return browserProvider.exists(workspacePath)
} }
@ -252,6 +252,7 @@ module.exports = class Filepanel extends ViewPlugin {
if (await this.workspaceExists(workspaceName)) throw new Error('workspace already exists') if (await this.workspaceExists(workspaceName)) throw new Error('workspace already exists')
else { else {
const workspaceProvider = this._deps.fileProviders.workspace const workspaceProvider = this._deps.fileProviders.workspace
console.log('create WS', workspaceName)
await this.processCreateWorkspace(workspaceName) await this.processCreateWorkspace(workspaceName)
workspaceProvider.setWorkspace(workspaceName) workspaceProvider.setWorkspace(workspaceName)
await this.request.setWorkspace(workspaceName) // tells the react component to switch to that workspace await this.request.setWorkspace(workspaceName) // tells the react component to switch to that workspace

@ -0,0 +1 @@
Subproject commit 6af4ed6169ee4165ce86457f98c0a568bd9d7491

@ -113,20 +113,16 @@
class remixFileSystem extends LightningFS { class remixFileSystem extends LightningFS {
constructor(...t) { constructor(...t) {
super(...t) super(...t)
this.superStat = this.promises.stat
this.promises = { this.promises = {
...this.promises, ...this.promises,
exists: async (path) => { exists: async (path) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this.superStat(path).then(() => resolve(true)).catch(() => resolve(false)) this.promises.stat(path).then(() => resolve(true)).catch(() => resolve(false))
}) })
}, },
stat: async (path) => { statExtended: async (path) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
console.log("stat", path, this) this.promises.stat(path).then((stat) => {
//return
this.superStat(path).then((stat) => {
console.log("stat", stat)
resolve({ resolve({
isDirectory: () => { isDirectory: () => {
return stat.type === 'dir' return stat.type === 'dir'
@ -143,7 +139,6 @@
} }
window.remixFileSystemCallback = new remixFileSystem('RemixFileSystem') window.remixFileSystemCallback = new remixFileSystem('RemixFileSystem')
window.remixFileSystem = window.remixFileSystemCallback.promises window.remixFileSystem = window.remixFileSystemCallback.promises
console.log(window.remixFileSystem)
let app = document.createElement('script') let app = document.createElement('script')
app.setAttribute('src', versions[versionToLoad]) app.setAttribute('src', versions[versionToLoad])
document.body.appendChild(app) document.body.appendChild(app)

Loading…
Cancel
Save