|
|
|
@ -45,9 +45,10 @@ export const createWorkspace = async (workspaceName: string, isEmpty = false, cb |
|
|
|
|
|
|
|
|
|
dispatch(createWorkspaceRequest(promise)) |
|
|
|
|
promise.then(async () => { |
|
|
|
|
dispatch(createWorkspaceSuccess(workspaceName)) |
|
|
|
|
dispatch(createWorkspaceSuccess(workspaceName, plugin)) |
|
|
|
|
if (!isEmpty) await loadWorkspacePreset('default-template') |
|
|
|
|
plugin.emit('setWorkspace', { name: workspaceName, isLocalhost: false }) |
|
|
|
|
plugin.setWorkspaces(await getWorkspaces()) |
|
|
|
|
cb && cb(null, workspaceName) |
|
|
|
|
}).catch((error) => { |
|
|
|
|
dispatch(createWorkspaceError({ error })) |
|
|
|
@ -172,7 +173,7 @@ export const fetchWorkspaceDirectory = async (path: string) => { |
|
|
|
|
|
|
|
|
|
export const renameWorkspace = async (oldName: string, workspaceName: string) => { |
|
|
|
|
await renameWorkspaceFromProvider(oldName, workspaceName) |
|
|
|
|
await dispatch(setRenameWorkspace(oldName, workspaceName)) |
|
|
|
|
await dispatch(setRenameWorkspace(oldName, workspaceName, plugin)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export const renameWorkspaceFromProvider = async (oldName: string, workspaceName: string) => { |
|
|
|
@ -185,6 +186,7 @@ export const renameWorkspaceFromProvider = async (oldName: string, workspaceName |
|
|
|
|
browserProvider.rename('browser/' + workspacesPath + '/' + oldName, 'browser/' + workspacesPath + '/' + workspaceName, true) |
|
|
|
|
workspaceProvider.setWorkspace(workspaceName) |
|
|
|
|
plugin.emit('renameWorkspace', { name: workspaceName }) |
|
|
|
|
plugin.setWorkspaces(await getWorkspaces()) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export const switchToWorkspace = async (name: string) => { |
|
|
|
@ -197,14 +199,14 @@ export const switchToWorkspace = async (name: string) => { |
|
|
|
|
plugin.emit('setWorkspace', { name: LOCALHOST, isLocalhost: true }) |
|
|
|
|
} else if (name === NO_WORKSPACE) { |
|
|
|
|
plugin.fileProviders.workspace.clearWorkspace() |
|
|
|
|
dispatch(setCurrentWorkspace(null)) |
|
|
|
|
dispatch(setCurrentWorkspace(null, plugin)) |
|
|
|
|
} else { |
|
|
|
|
const isActive = await plugin.call('manager', 'isActive', 'remixd') |
|
|
|
|
|
|
|
|
|
if (isActive) plugin.call('manager', 'deactivatePlugin', 'remixd') |
|
|
|
|
await plugin.fileProviders.workspace.setWorkspace(name) |
|
|
|
|
dispatch(setMode('browser')) |
|
|
|
|
dispatch(setCurrentWorkspace(name)) |
|
|
|
|
dispatch(setCurrentWorkspace(name, plugin)) |
|
|
|
|
dispatch(setReadOnlyMode(false)) |
|
|
|
|
plugin.emit('setWorkspace', { name, isLocalhost: false }) |
|
|
|
|
} |
|
|
|
@ -255,3 +257,26 @@ export const uploadFile = async (target, targetFolder: string, cb?: (err: Error, |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export const getWorkspaces = async (): Promise<string[]> | undefined => { |
|
|
|
|
try { |
|
|
|
|
const workspaces: string[] = await new Promise((resolve, reject) => { |
|
|
|
|
const workspacesPath = plugin.fileProviders.workspace.workspacesPath |
|
|
|
|
|
|
|
|
|
plugin.fileProviders.browser.resolveDirectory('/' + workspacesPath, (error, items) => { |
|
|
|
|
if (error) { |
|
|
|
|
console.error(error) |
|
|
|
|
return reject(error) |
|
|
|
|
} |
|
|
|
|
resolve(Object.keys(items) |
|
|
|
|
.filter((item) => items[item].isDirectory) |
|
|
|
|
.map((folder) => folder.replace(workspacesPath + '/', ''))) |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
plugin.setWorkspaces(workspaces) |
|
|
|
|
return workspaces |
|
|
|
|
} catch (e) { |
|
|
|
|
console.log(e) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|