|
|
@ -46,9 +46,9 @@ export const createWorkspace = async (workspaceName: string, isEmpty = false, cb |
|
|
|
dispatch(createWorkspaceRequest(promise)) |
|
|
|
dispatch(createWorkspaceRequest(promise)) |
|
|
|
promise.then(async () => { |
|
|
|
promise.then(async () => { |
|
|
|
dispatch(createWorkspaceSuccess(workspaceName)) |
|
|
|
dispatch(createWorkspaceSuccess(workspaceName)) |
|
|
|
plugin.setWorkspace({ name: workspaceName, isLocalhost: false }) |
|
|
|
await plugin.setWorkspace({ name: workspaceName, isLocalhost: false }) |
|
|
|
plugin.setWorkspaces(await getWorkspaces()) |
|
|
|
await plugin.setWorkspaces(await getWorkspaces()) |
|
|
|
plugin.workspaceCreated(workspaceName) |
|
|
|
await plugin.workspaceCreated(workspaceName) |
|
|
|
if (!isEmpty) await loadWorkspacePreset('default-template') |
|
|
|
if (!isEmpty) await loadWorkspacePreset('default-template') |
|
|
|
cb && cb(null, workspaceName) |
|
|
|
cb && cb(null, workspaceName) |
|
|
|
}).catch((error) => { |
|
|
|
}).catch((error) => { |
|
|
@ -84,14 +84,14 @@ export const loadWorkspacePreset = async (template: 'gist-template' | 'code-temp |
|
|
|
|
|
|
|
|
|
|
|
path = 'contract-' + hash.replace('0x', '').substring(0, 10) + '.sol' |
|
|
|
path = 'contract-' + hash.replace('0x', '').substring(0, 10) + '.sol' |
|
|
|
content = atob(params.code) |
|
|
|
content = atob(params.code) |
|
|
|
workspaceProvider.set(path, content) |
|
|
|
await workspaceProvider.set(path, content) |
|
|
|
} |
|
|
|
} |
|
|
|
if (params.url) { |
|
|
|
if (params.url) { |
|
|
|
const data = await plugin.call('contentImport', 'resolve', params.url) |
|
|
|
const data = await plugin.call('contentImport', 'resolve', params.url) |
|
|
|
|
|
|
|
|
|
|
|
path = data.cleanUrl |
|
|
|
path = data.cleanUrl |
|
|
|
content = data.content |
|
|
|
content = data.content |
|
|
|
workspaceProvider.set(path, content) |
|
|
|
await workspaceProvider.set(path, content) |
|
|
|
} |
|
|
|
} |
|
|
|
return path |
|
|
|
return path |
|
|
|
} catch (e) { |
|
|
|
} catch (e) { |
|
|
@ -150,7 +150,7 @@ export const workspaceExists = async (name: string) => { |
|
|
|
const browserProvider = plugin.fileProviders.browser |
|
|
|
const browserProvider = plugin.fileProviders.browser |
|
|
|
const workspacePath = 'browser/' + workspaceProvider.workspacesPath + '/' + name |
|
|
|
const workspacePath = 'browser/' + workspaceProvider.workspacesPath + '/' + name |
|
|
|
|
|
|
|
|
|
|
|
return browserProvider.exists(workspacePath) |
|
|
|
return await browserProvider.exists(workspacePath) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export const fetchWorkspaceDirectory = async (path: string) => { |
|
|
|
export const fetchWorkspaceDirectory = async (path: string) => { |
|
|
@ -176,8 +176,8 @@ export const fetchWorkspaceDirectory = async (path: string) => { |
|
|
|
export const renameWorkspace = async (oldName: string, workspaceName: string, cb?: (err: Error, result?: string | number | boolean | Record<string, any>) => void) => { |
|
|
|
export const renameWorkspace = async (oldName: string, workspaceName: string, cb?: (err: Error, result?: string | number | boolean | Record<string, any>) => void) => { |
|
|
|
await renameWorkspaceFromProvider(oldName, workspaceName) |
|
|
|
await renameWorkspaceFromProvider(oldName, workspaceName) |
|
|
|
await dispatch(setRenameWorkspace(oldName, workspaceName)) |
|
|
|
await dispatch(setRenameWorkspace(oldName, workspaceName)) |
|
|
|
plugin.setWorkspace({ name: workspaceName, isLocalhost: false }) |
|
|
|
await plugin.setWorkspace({ name: workspaceName, isLocalhost: false }) |
|
|
|
plugin.workspaceRenamed(oldName, workspaceName) |
|
|
|
await plugin.workspaceRenamed(oldName, workspaceName) |
|
|
|
cb && cb(null, workspaceName) |
|
|
|
cb && cb(null, workspaceName) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -188,9 +188,9 @@ export const renameWorkspaceFromProvider = async (oldName: string, workspaceName |
|
|
|
const browserProvider = plugin.fileProviders.browser |
|
|
|
const browserProvider = plugin.fileProviders.browser |
|
|
|
const workspaceProvider = plugin.fileProviders.workspace |
|
|
|
const workspaceProvider = plugin.fileProviders.workspace |
|
|
|
const workspacesPath = workspaceProvider.workspacesPath |
|
|
|
const workspacesPath = workspaceProvider.workspacesPath |
|
|
|
browserProvider.rename('browser/' + workspacesPath + '/' + oldName, 'browser/' + workspacesPath + '/' + workspaceName, true) |
|
|
|
await browserProvider.rename('browser/' + workspacesPath + '/' + oldName, 'browser/' + workspacesPath + '/' + workspaceName, true) |
|
|
|
workspaceProvider.setWorkspace(workspaceName) |
|
|
|
await workspaceProvider.setWorkspace(workspaceName) |
|
|
|
plugin.setWorkspaces(await getWorkspaces()) |
|
|
|
await plugin.setWorkspaces(await getWorkspaces()) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export const deleteWorkspace = async (workspaceName: string, cb?: (err: Error, result?: string | number | boolean | Record<string, any>) => void) => { |
|
|
|
export const deleteWorkspace = async (workspaceName: string, cb?: (err: Error, result?: string | number | boolean | Record<string, any>) => void) => { |
|
|
@ -204,8 +204,8 @@ const deleteWorkspaceFromProvider = async (workspaceName: string) => { |
|
|
|
const workspacesPath = plugin.fileProviders.workspace.workspacesPath |
|
|
|
const workspacesPath = plugin.fileProviders.workspace.workspacesPath |
|
|
|
|
|
|
|
|
|
|
|
await plugin.fileManager.closeAllFiles() |
|
|
|
await plugin.fileManager.closeAllFiles() |
|
|
|
plugin.fileProviders.browser.remove(workspacesPath + '/' + workspaceName) |
|
|
|
await plugin.fileProviders.browser.remove(workspacesPath + '/' + workspaceName) |
|
|
|
plugin.setWorkspaces(await getWorkspaces()) |
|
|
|
await plugin.setWorkspaces(await getWorkspaces()) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export const switchToWorkspace = async (name: string) => { |
|
|
|
export const switchToWorkspace = async (name: string) => { |
|
|
@ -217,15 +217,15 @@ export const switchToWorkspace = async (name: string) => { |
|
|
|
dispatch(setMode('localhost')) |
|
|
|
dispatch(setMode('localhost')) |
|
|
|
plugin.emit('setWorkspace', { name: null, isLocalhost: true }) |
|
|
|
plugin.emit('setWorkspace', { name: null, isLocalhost: true }) |
|
|
|
} else if (name === NO_WORKSPACE) { |
|
|
|
} else if (name === NO_WORKSPACE) { |
|
|
|
plugin.fileProviders.workspace.clearWorkspace() |
|
|
|
await plugin.fileProviders.workspace.clearWorkspace() |
|
|
|
plugin.setWorkspace({ name: null, isLocalhost: false }) |
|
|
|
await plugin.setWorkspace({ name: null, isLocalhost: false }) |
|
|
|
dispatch(setCurrentWorkspace(null)) |
|
|
|
dispatch(setCurrentWorkspace(null)) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
const isActive = await plugin.call('manager', 'isActive', 'remixd') |
|
|
|
const isActive = await plugin.call('manager', 'isActive', 'remixd') |
|
|
|
|
|
|
|
|
|
|
|
if (isActive) plugin.call('manager', 'deactivatePlugin', 'remixd') |
|
|
|
if (isActive) plugin.call('manager', 'deactivatePlugin', 'remixd') |
|
|
|
await plugin.fileProviders.workspace.setWorkspace(name) |
|
|
|
await plugin.fileProviders.workspace.setWorkspace(name) |
|
|
|
plugin.setWorkspace({ name, isLocalhost: false }) |
|
|
|
await plugin.setWorkspace({ name, isLocalhost: false }) |
|
|
|
dispatch(setMode('browser')) |
|
|
|
dispatch(setMode('browser')) |
|
|
|
dispatch(setCurrentWorkspace(name)) |
|
|
|
dispatch(setCurrentWorkspace(name)) |
|
|
|
dispatch(setReadOnlyMode(false)) |
|
|
|
dispatch(setReadOnlyMode(false)) |
|
|
@ -237,7 +237,7 @@ export const uploadFile = async (target, targetFolder: string, cb?: (err: Error, |
|
|
|
// the files module. Please ask the user here if they want to overwrite
|
|
|
|
// the files module. Please ask the user here if they want to overwrite
|
|
|
|
// a file and then just use `files.add`. The file explorer will
|
|
|
|
// a file and then just use `files.add`. The file explorer will
|
|
|
|
// pick that up via the 'fileAdded' event from the files module.
|
|
|
|
// pick that up via the 'fileAdded' event from the files module.
|
|
|
|
[...target.files].forEach((file) => { |
|
|
|
[...target.files].forEach(async (file) => { |
|
|
|
const workspaceProvider = plugin.fileProviders.workspace |
|
|
|
const workspaceProvider = plugin.fileProviders.workspace |
|
|
|
const loadFile = (name: string): void => { |
|
|
|
const loadFile = (name: string): void => { |
|
|
|
const fileReader = new FileReader() |
|
|
|
const fileReader = new FileReader() |
|
|
@ -263,18 +263,13 @@ export const uploadFile = async (target, targetFolder: string, cb?: (err: Error, |
|
|
|
} |
|
|
|
} |
|
|
|
const name = `${targetFolder}/${file.name}` |
|
|
|
const name = `${targetFolder}/${file.name}` |
|
|
|
|
|
|
|
|
|
|
|
workspaceProvider.exists(name).then(exist => { |
|
|
|
if (await workspaceProvider.exists(name)) { |
|
|
|
if (!exist) { |
|
|
|
loadFile(name) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
dispatch(displayNotification('Confirm overwrite', `The file ${name} already exists! Would you like to overwrite it?`, 'OK', null, () => { |
|
|
|
loadFile(name) |
|
|
|
loadFile(name) |
|
|
|
} else { |
|
|
|
}, () => {})) |
|
|
|
dispatch(displayNotification('Confirm overwrite', `The file ${name} already exists! Would you like to overwrite it?`, 'OK', null, () => { |
|
|
|
} |
|
|
|
loadFile(name) |
|
|
|
|
|
|
|
}, () => {})) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}).catch(error => { |
|
|
|
|
|
|
|
cb && cb(error) |
|
|
|
|
|
|
|
if (error) console.log(error) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -293,7 +288,7 @@ export const getWorkspaces = async (): Promise<string[]> | undefined => { |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
plugin.setWorkspaces(workspaces) |
|
|
|
await plugin.setWorkspaces(workspaces) |
|
|
|
return workspaces |
|
|
|
return workspaces |
|
|
|
} catch (e) {} |
|
|
|
} catch (e) {} |
|
|
|
} |
|
|
|
} |
|
|
|