|
|
|
@ -4,8 +4,6 @@ import { action } from '../types' |
|
|
|
|
import { displayNotification, displayPopUp, fileAddedSuccess, fileRemovedSuccess, fileRenamedSuccess, folderAddedSuccess, loadLocalhostError, loadLocalhostRequest, loadLocalhostSuccess, removeContextMenuItem, rootFolderChangedSuccess, setContextMenuItem, setMode, setReadOnlyMode } from './payload' |
|
|
|
|
import { addInputField, createWorkspace, fetchWorkspaceDirectory, renameWorkspace, switchToWorkspace, uploadFile } from './workspace' |
|
|
|
|
|
|
|
|
|
const queuedEvents = [] |
|
|
|
|
const pendingEvents = {} |
|
|
|
|
const LOCALHOST = ' - connect to localhost - ' |
|
|
|
|
let plugin, dispatch: React.Dispatch<any> |
|
|
|
|
|
|
|
|
@ -37,52 +35,59 @@ export const listenOnPluginEvents = (filePanelPlugin) => { |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
plugin.on('remixd', 'rootFolderChanged', async (path: string) => { |
|
|
|
|
await executeEvent('rootFolderChanged', path) |
|
|
|
|
setTimeout(() => rootFolderChanged(path), 0) |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export const listenOnProviderEvents = (provider) => async (reducerDispatch: React.Dispatch<any>) => { |
|
|
|
|
dispatch = reducerDispatch |
|
|
|
|
|
|
|
|
|
provider.event.on('fileAdded', async (filePath: string) => { |
|
|
|
|
await executeEvent('fileAdded', filePath) |
|
|
|
|
provider.event.on('fileAdded', (filePath: string) => { |
|
|
|
|
setTimeout(() => fileAdded(filePath), 0) |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
provider.event.on('folderAdded', async (folderPath: string) => { |
|
|
|
|
provider.event.on('folderAdded', (folderPath: string) => { |
|
|
|
|
if (folderPath.indexOf('/.workspaces') === 0) return |
|
|
|
|
await executeEvent('folderAdded', folderPath) |
|
|
|
|
setTimeout(() => folderAdded(folderPath), 0) |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
provider.event.on('fileRemoved', async (removePath: string) => { |
|
|
|
|
await executeEvent('fileRemoved', removePath) |
|
|
|
|
provider.event.on('fileRemoved', (removePath: string) => { |
|
|
|
|
setTimeout(() => fileRemoved(removePath), 0) |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
provider.event.on('fileRenamed', async (oldPath: string, newPath: string) => { |
|
|
|
|
await executeEvent('fileRenamed', oldPath, newPath) |
|
|
|
|
provider.event.on('fileRenamed', (oldPath: string) => { |
|
|
|
|
setTimeout(() => fileRenamed(oldPath), 0) |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
provider.event.on('disconnected', async () => { |
|
|
|
|
provider.event.on('disconnected', () => { |
|
|
|
|
setTimeout(async () => { |
|
|
|
|
plugin.fileManager.setMode('browser') |
|
|
|
|
dispatch(setMode('browser')) |
|
|
|
|
dispatch(loadLocalhostError('Remixd disconnected!')) |
|
|
|
|
const workspaceProvider = plugin.fileProviders.workspace |
|
|
|
|
|
|
|
|
|
await switchToWorkspace(workspaceProvider.workspace) |
|
|
|
|
}, 0) |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
provider.event.on('connected', async () => { |
|
|
|
|
setTimeout(() => { |
|
|
|
|
plugin.fileManager.setMode('localhost') |
|
|
|
|
dispatch(setMode('localhost')) |
|
|
|
|
fetchWorkspaceDirectory('/') |
|
|
|
|
dispatch(loadLocalhostSuccess()) |
|
|
|
|
}, 0) |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
provider.event.on('loadingLocalhost', async () => { |
|
|
|
|
setTimeout(async () => { |
|
|
|
|
await switchToWorkspace(LOCALHOST) |
|
|
|
|
dispatch(loadLocalhostRequest()) |
|
|
|
|
}, 0) |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
provider.event.on('fileExternallyChanged', async (path: string, file: { content: string }) => { |
|
|
|
|
setTimeout(() => { |
|
|
|
|
const config = plugin.registry.get('config').api |
|
|
|
|
const editor = plugin.registry.get('editor').api |
|
|
|
|
|
|
|
|
@ -97,14 +102,15 @@ export const listenOnProviderEvents = (provider) => async (reducerDispatch: Reac |
|
|
|
|
} |
|
|
|
|
)) |
|
|
|
|
} |
|
|
|
|
}, 0) |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
provider.event.on('fileRenamedError', async () => { |
|
|
|
|
dispatch(displayNotification('File Renamed Failed', '', 'Ok', 'Cancel')) |
|
|
|
|
setTimeout(() => dispatch(displayNotification('File Renamed Failed', '', 'Ok', 'Cancel')), 0) |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
provider.event.on('readOnlyModeChanged', (mode: boolean) => { |
|
|
|
|
dispatch(setReadOnlyMode(mode)) |
|
|
|
|
setTimeout(() => dispatch(setReadOnlyMode(mode)), 0) |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -172,71 +178,3 @@ const fileRenamed = async (oldPath: string) => { |
|
|
|
|
const rootFolderChanged = async (path) => { |
|
|
|
|
await dispatch(rootFolderChangedSuccess(path)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const executeEvent = async (eventName: 'fileAdded' | 'folderAdded' | 'fileRemoved' | 'fileRenamed' | 'rootFolderChanged', ...args) => { |
|
|
|
|
if (Object.keys(pendingEvents).length) { |
|
|
|
|
return queuedEvents.push({ eventName, path: args[0] }) |
|
|
|
|
} |
|
|
|
|
pendingEvents[eventName + args[0]] = { eventName, path: args[0] } |
|
|
|
|
switch (eventName) { |
|
|
|
|
case 'fileAdded': |
|
|
|
|
setTimeout(() => { |
|
|
|
|
fileAdded(args[0]) |
|
|
|
|
}, 0) |
|
|
|
|
delete pendingEvents[eventName + args[0]] |
|
|
|
|
if (queuedEvents.length) { |
|
|
|
|
const next = queuedEvents.pop() |
|
|
|
|
|
|
|
|
|
await executeEvent(next.eventName, next.path) |
|
|
|
|
} |
|
|
|
|
break |
|
|
|
|
|
|
|
|
|
case 'folderAdded': |
|
|
|
|
setTimeout(() => { |
|
|
|
|
folderAdded(args[0]) |
|
|
|
|
}, 0) |
|
|
|
|
delete pendingEvents[eventName + args[0]] |
|
|
|
|
if (queuedEvents.length) { |
|
|
|
|
const next = queuedEvents.pop() |
|
|
|
|
|
|
|
|
|
await executeEvent(next.eventName, next.path) |
|
|
|
|
} |
|
|
|
|
break |
|
|
|
|
|
|
|
|
|
case 'fileRemoved': |
|
|
|
|
setTimeout(() => { |
|
|
|
|
fileRemoved(args[0]) |
|
|
|
|
}, 0) |
|
|
|
|
delete pendingEvents[eventName + args[0]] |
|
|
|
|
if (queuedEvents.length) { |
|
|
|
|
const next = queuedEvents.pop() |
|
|
|
|
|
|
|
|
|
await executeEvent(next.eventName, next.path) |
|
|
|
|
} |
|
|
|
|
break |
|
|
|
|
|
|
|
|
|
case 'fileRenamed': |
|
|
|
|
setTimeout(() => { |
|
|
|
|
fileRenamed(args[0]) |
|
|
|
|
}, 0) |
|
|
|
|
delete pendingEvents[eventName + args[0]] |
|
|
|
|
if (queuedEvents.length) { |
|
|
|
|
const next = queuedEvents.pop() |
|
|
|
|
|
|
|
|
|
await executeEvent(next.eventName, next.path) |
|
|
|
|
} |
|
|
|
|
break |
|
|
|
|
|
|
|
|
|
case 'rootFolderChanged': |
|
|
|
|
setTimeout(() => { |
|
|
|
|
rootFolderChanged(args[0]) |
|
|
|
|
}, 0) |
|
|
|
|
delete pendingEvents[eventName + args[0]] |
|
|
|
|
if (queuedEvents.length) { |
|
|
|
|
const next = queuedEvents.pop() |
|
|
|
|
|
|
|
|
|
await executeEvent(next.eventName, next.path) |
|
|
|
|
} |
|
|
|
|
break |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|