Api: Added ability to watch resource file

orphaned_resource_bug
Laurent Cozic 2020-11-07 16:32:08 +00:00
parent 04bfbec96b
commit 83b175bb5b
1 changed files with 13 additions and 5 deletions

View File

@ -78,6 +78,9 @@ export default class ResourceEditWatcher {
openAndWatch: async ({ resourceId }:any) => { openAndWatch: async ({ resourceId }:any) => {
return this.openAndWatch(resourceId); return this.openAndWatch(resourceId);
}, },
watch: async ({ resourceId }:any) => {
await this.watch(resourceId);
},
stopWatching: async ({ resourceId }:any) => { stopWatching: async ({ resourceId }:any) => {
return this.stopWatching(resourceId); return this.stopWatching(resourceId);
}, },
@ -87,7 +90,7 @@ export default class ResourceEditWatcher {
}; };
} }
private watch(fileToWatch:string) { private watchFile(fileToWatch:string) {
if (!this.chokidar_) return; if (!this.chokidar_) return;
const makeSaveAction = (resourceId:string, path:string) => { const makeSaveAction = (resourceId:string, path:string) => {
@ -194,7 +197,7 @@ export default class ResourceEditWatcher {
return this.watcher_; return this.watcher_;
} }
public async openAndWatch(resourceId:string) { private async watch(resourceId:string):Promise<WatchedItem> {
let watchedItem = this.watchedItemByResourceId(resourceId); let watchedItem = this.watchedItemByResourceId(resourceId);
if (!watchedItem) { if (!watchedItem) {
@ -224,7 +227,7 @@ export default class ResourceEditWatcher {
watchedItem.lastResourceUpdatedTime = resource.updated_time; watchedItem.lastResourceUpdatedTime = resource.updated_time;
watchedItem.size = stat.size; watchedItem.size = stat.size;
this.watch(editFilePath); this.watchFile(editFilePath);
this.dispatch({ this.dispatch({
type: 'RESOURCE_EDIT_WATCHER_SET', type: 'RESOURCE_EDIT_WATCHER_SET',
@ -233,9 +236,14 @@ export default class ResourceEditWatcher {
}); });
} }
bridge().openItem(watchedItem.path);
this.logger().info(`ResourceEditWatcher: Started watching ${watchedItem.path}`); this.logger().info(`ResourceEditWatcher: Started watching ${watchedItem.path}`);
return watchedItem;
}
public async openAndWatch(resourceId:string) {
const watchedItem = await this.watch(resourceId);
bridge().openItem(watchedItem.path);
} }
async stopWatching(resourceId:string) { async stopWatching(resourceId:string) {