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) this.event.emit('fileRemoved', path)
break break
case 'change': case 'change':
this.event.emit('fileChanged', path) this.get(path, (_error, content) => {
this.event.emit('fileExternallyChanged', path, content, false)
})
break break
case 'rename': case 'rename':
this.event.emit('fileRenamed', path) this.event.emit('fileRenamed', path)

@ -78,6 +78,7 @@ const clientProfile: Profile = {
class FSPluginClient extends ElectronBasePluginClient { class FSPluginClient extends ElectronBasePluginClient {
watcher: chokidar.FSWatcher watcher: chokidar.FSWatcher
workingDir: string = '' workingDir: string = ''
trackDownStreamUpdate: Record<string, string> = {}
constructor(webContentsId: number, profile: Profile) { constructor(webContentsId: number, profile: Profile) {
super(webContentsId, profile) super(webContentsId, profile)
@ -155,6 +156,7 @@ class FSPluginClient extends ElectronBasePluginClient {
async writeFile(path: string, content: string, options: any): Promise<void> { async writeFile(path: string, content: string, options: any): Promise<void> {
//console.log('writeFile', path, content, options) //console.log('writeFile', path, content, options)
this.trackDownStreamUpdate[path] = content
return (fs as any).writeFile(this.fixPath(path), content, options) return (fs as any).writeFile(this.fixPath(path), content, options)
} }
@ -226,14 +228,34 @@ class FSPluginClient extends ElectronBasePluginClient {
'**/node_modules/**', '**/node_modules/**',
'**/.git/**', '**/.git/**',
] ]
}).on('all', (eventName, path, stats) => { }).on('all', async (eventName, path, stats) => {
console.log('change', eventName, path, stats) console.log('change', eventName, path, stats)
// remove workingDir from path
path = path.replace(this.workingDir, '') let pathWithoutPrefix = path.replace(this.workingDir, '')
try { if (pathWithoutPrefix.startsWith('/')) pathWithoutPrefix = pathWithoutPrefix.slice(1)
this.emit('change', eventName, path)
} catch (e) { if (eventName === 'change') {
console.log('error emitting change', e) // 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()) 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 config = plugin.registry.get('config').api
const editor = plugin.registry.get('editor').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 (config.get('currentFile') === path) {
// if it's the current file and the content is different: // if it's the current file and the content is different:
if(showAlert){
dispatch(displayNotification( dispatch(displayNotification(
path + ' changed', path + ' changed',
'This file has been changed outside of Remix IDE.', 'This file has been changed outside of Remix IDE.',
@ -129,7 +130,9 @@ export const listenOnProviderEvents = (provider) => (reducerDispatch: React.Disp
() => { () => {
editor.setText(path, content) editor.setText(path, content)
} }
)) ))}else{
editor.setText(path, content)
}
} else { } else {
// this isn't the current file, we can silently update the model // this isn't the current file, we can silently update the model
editor.setText(path, content) editor.setText(path, content)

Loading…
Cancel
Save