streamline APIs of chockidar and nsfw

This commit is contained in:
Martin Aeschlimann 2018-10-02 15:44:53 +02:00
parent c706d49539
commit 1faa060037
3 changed files with 30 additions and 1 deletions

View file

@ -215,6 +215,21 @@ export class NsfwWatcherService implements IWatcherService {
return TPromise.join(promises).then(() => void 0);
}
public setVerboseLogging(enabled: boolean): TPromise<void> {
this._verboseLogging = enabled;
return TPromise.as(null);
}
public stop(): TPromise<void> {
for (let path in this._pathWatchers) {
let watcher = this._pathWatchers[path];
watcher.ready.then(watcher => watcher.stop());
delete this._pathWatchers[path];
}
this._pathWatchers = Object.create(null);
return TPromise.as(void 0);
}
/**
* Normalizes a set of root paths by removing any root paths that are
* sub-paths of other roots.

View file

@ -25,4 +25,6 @@ export interface IWatchError {
export interface IWatcherService {
watch(options: IWatcherOptions): Event<IRawFileChange[] | IWatchError>;
setRoots(roots: IWatcherRequest[]): TPromise<void>;
setVerboseLogging(enabled: boolean): TPromise<void>;
stop(): TPromise<void>;
}

View file

@ -16,6 +16,8 @@ export interface IWatcherChannel extends IChannel {
listen<T>(event: string, arg?: any): Event<T>;
call(command: 'setRoots', request: IWatcherRequest[]): TPromise<void>;
call(command: 'setVerboseLogging', enable: boolean): TPromise<void>;
call(command: 'stop'): TPromise<void>;
call<T>(command: string, arg?: any): TPromise<T>;
}
@ -30,9 +32,11 @@ export class WatcherChannel implements IWatcherChannel {
throw new Error('No events');
}
call(command: string, arg: any): TPromise<any> {
call(command: string, arg?: any): TPromise<any> {
switch (command) {
case 'setRoots': return this.service.setRoots(arg);
case 'setVerboseLogging': return this.service.setVerboseLogging(arg);
case 'stop': return this.service.stop();
}
return undefined;
}
@ -46,7 +50,15 @@ export class WatcherChannelClient implements IWatcherService {
return this.channel.listen('watch', options);
}
setVerboseLogging(enable: boolean): TPromise<void> {
return this.channel.call('setVerboseLogging', enable);
}
setRoots(roots: IWatcherRequest[]): TPromise<void> {
return this.channel.call('setRoots', roots);
}
stop(): TPromise<void> {
return this.channel.call('stop');
}
}