filechanged

rdesktop^2
filip mertens 1 year ago
parent 68515019a9
commit f170b08344
  1. 4
      apps/remix-ide/src/app/files/electronProvider.ts
  2. 36
      apps/remixdesktop/src/plugins/fsPlugin.ts
  3. 7
      libs/remix-ui/workspace/src/lib/actions/events.ts

@ -24,7 +24,9 @@ export class ElectronProvider extends FileProvider {
this.event.emit('fileRemoved', path)
break
case 'change':
this.event.emit('fileChanged', path)
this.get(path, (_error, content) => {
this.event.emit('fileExternallyChanged', path, content, false)
})
break
case 'rename':
this.event.emit('fileRenamed', path)

@ -78,6 +78,7 @@ const clientProfile: Profile = {
class FSPluginClient extends ElectronBasePluginClient {
watcher: chokidar.FSWatcher
workingDir: string = ''
trackDownStreamUpdate: Record<string, string> = {}
constructor(webContentsId: number, profile: Profile) {
super(webContentsId, profile)
@ -155,6 +156,7 @@ class FSPluginClient extends ElectronBasePluginClient {
async writeFile(path: string, content: string, options: any): Promise<void> {
//console.log('writeFile', path, content, options)
this.trackDownStreamUpdate[path] = content
return (fs as any).writeFile(this.fixPath(path), content, options)
}
@ -226,14 +228,34 @@ class FSPluginClient extends ElectronBasePluginClient {
'**/node_modules/**',
'**/.git/**',
]
}).on('all', (eventName, path, stats) => {
}).on('all', async (eventName, path, stats) => {
console.log('change', eventName, path, stats)
// remove workingDir from path
path = path.replace(this.workingDir, '')
try {
this.emit('change', eventName, path)
} catch (e) {
console.log('error emitting change', e)
let pathWithoutPrefix = path.replace(this.workingDir, '')
if (pathWithoutPrefix.startsWith('/')) pathWithoutPrefix = pathWithoutPrefix.slice(1)
if (eventName === 'change') {
// remove workingDir from path
const newContent = await fs.readFile(path, 'utf-8')
console.log('change', pathWithoutPrefix, this.trackDownStreamUpdate)
const currentContent = this.trackDownStreamUpdate[pathWithoutPrefix]
if (currentContent !== newContent) {
try {
this.emit('change', eventName, pathWithoutPrefix)
} catch (e) {
console.log('error emitting change', e)
}
}
} else {
try {
this.emit('change', eventName, pathWithoutPrefix)
} catch (e) {
console.log('error emitting change', e)
}
}
})
}

@ -113,7 +113,7 @@ export const listenOnProviderEvents = (provider) => (reducerDispatch: React.Disp
dispatch(loadLocalhostRequest())
})
provider.event.on('fileExternallyChanged', (path: string, content: string) => {
provider.event.on('fileExternallyChanged', (path: string, content: string, showAlert: boolean = true) => {
const config = plugin.registry.get('config').api
const editor = plugin.registry.get('editor').api
@ -122,6 +122,7 @@ export const listenOnProviderEvents = (provider) => (reducerDispatch: React.Disp
if (config.get('currentFile') === path) {
// if it's the current file and the content is different:
if(showAlert){
dispatch(displayNotification(
path + ' changed',
'This file has been changed outside of Remix IDE.',
@ -129,7 +130,9 @@ export const listenOnProviderEvents = (provider) => (reducerDispatch: React.Disp
() => {
editor.setText(path, content)
}
))
))}else{
editor.setText(path, content)
}
} else {
// this isn't the current file, we can silently update the model
editor.setText(path, content)

Loading…
Cancel
Save