update watch type

This commit is contained in:
Abhinav 2022-06-15 14:29:17 +05:30
parent 8775b1f181
commit bf21d8391a
2 changed files with 9 additions and 9 deletions

View file

@ -6,14 +6,14 @@ import { removeFromCollection, syncCollections } from './collectionService';
import { syncFiles } from './fileService'; import { syncFiles } from './fileService';
import debounce from 'debounce-promise'; import debounce from 'debounce-promise';
import { logError } from 'utils/sentry'; import { logError } from 'utils/sentry';
import { EventQueueType, WatchMapping } from 'types/watch'; import { EventQueueItem, WatchMapping } from 'types/watch';
import { ElectronAPIsInterface } from 'types/electron'; import { ElectronAPIsInterface } from 'types/electron';
export class WatchService { export class WatchService {
ElectronAPIs: ElectronAPIsInterface; ElectronAPIs: ElectronAPIsInterface;
allElectronAPIsExist: boolean = false; allElectronAPIsExist: boolean = false;
eventQueue: EventQueueType[] = []; eventQueue: EventQueueItem[] = [];
currentEvent: EventQueueType; currentEvent: EventQueueItem;
trashingDirQueue: string[] = []; trashingDirQueue: string[] = [];
isEventRunning: boolean = false; isEventRunning: boolean = false;
uploadRunning: boolean = false; uploadRunning: boolean = false;
@ -86,7 +86,7 @@ export class WatchService {
}); });
if (filesToUpload.length > 0) { if (filesToUpload.length > 0) {
const event: EventQueueType = { const event: EventQueueItem = {
type: 'upload', type: 'upload',
collectionName: mapping.collectionName, collectionName: mapping.collectionName,
files: filesToUpload, files: filesToUpload,
@ -106,7 +106,7 @@ export class WatchService {
}); });
if (filesToRemove.length > 0) { if (filesToRemove.length > 0) {
const event: EventQueueType = { const event: EventQueueItem = {
type: 'trash', type: 'trash',
collectionName: mapping.collectionName, collectionName: mapping.collectionName,
paths: filesToRemove.map((file) => file.path), paths: filesToRemove.map((file) => file.path),
@ -431,7 +431,7 @@ export class WatchService {
// Batches all the files to be uploaded (or trashed) from the // Batches all the files to be uploaded (or trashed) from the
// event queue of same collection as the next event // event queue of same collection as the next event
private clubSameCollectionEvents(): EventQueueType { private clubSameCollectionEvents(): EventQueueItem {
const event = this.eventQueue.shift(); const event = this.eventQueue.shift();
while ( while (
this.eventQueue.length > 0 && this.eventQueue.length > 0 &&
@ -469,7 +469,7 @@ async function diskFileAddedCallback(
console.log('added (upload) to event queue', collectionName, file); console.log('added (upload) to event queue', collectionName, file);
const event: EventQueueType = { const event: EventQueueItem = {
type: 'upload', type: 'upload',
collectionName, collectionName,
files: [file], files: [file],
@ -494,7 +494,7 @@ async function diskFileRemovedCallback(
return; return;
} }
const event: EventQueueType = { const event: EventQueueItem = {
type: 'trash', type: 'trash',
collectionName, collectionName,
paths: [filePath], paths: [filePath],

View file

@ -9,7 +9,7 @@ export interface WatchMapping {
}[]; }[];
} }
export interface EventQueueType { export interface EventQueueItem {
type: 'upload' | 'trash'; type: 'upload' | 'trash';
collectionName: string; collectionName: string;
paths?: string[]; paths?: string[];