rename watchService to watchFolderService

This commit is contained in:
Abhinav 2022-06-19 18:07:55 +05:30
parent 1117534cc8
commit 99b5cce1c9
7 changed files with 37 additions and 33 deletions

View file

@ -13,7 +13,7 @@ import {
InProgressUpload,
} from 'types/upload/ui';
import UploadProgressContext from 'contexts/uploadProgress';
import watchService from 'services/watchFolderService';
import watchFolderService from 'services/watchFolderService';
interface Props {
open: boolean;
@ -45,7 +45,10 @@ export default function UploadProgress({
const [expanded, setExpanded] = useState(true);
useEffect(() => {
if (appContext.isFolderSyncRunning && watchService.isUploadRunning()) {
if (
appContext.isFolderSyncRunning &&
watchFolderService.isUploadRunning()
) {
setExpanded(false);
}
}, [appContext.isFolderSyncRunning]);

View file

@ -2,7 +2,7 @@ import { MappingList } from './mappingList';
import { NoMappingsContent } from './noMappingsContent';
import React, { useContext, useEffect, useState } from 'react';
import { Button, DialogActions, DialogContent } from '@mui/material';
import watchService from 'services/watchFolderService';
import watchFolderService from 'services/watchFolderService';
import { WatchMapping } from 'types/watchFolder';
import { AppContext } from 'pages/_app';
import constants from 'utils/strings/constants';
@ -19,7 +19,7 @@ export default function WatchFolder({ open, onClose }: Iprops) {
const appContext = useContext(AppContext);
useEffect(() => {
setMappings(watchService.getWatchMappings());
setMappings(watchFolderService.getWatchMappings());
}, []);
useEffect(() => {
@ -35,7 +35,7 @@ export default function WatchFolder({ open, onClose }: Iprops) {
for (let i = 0; i < folders.length; i++) {
const folder: any = folders[i];
const path = (folder.path as string).replace(/\\/g, '/');
if (await watchService.isFolder(path)) {
if (await watchFolderService.isFolder(path)) {
await handleAddWatchMapping(path);
}
}
@ -46,23 +46,23 @@ export default function WatchFolder({ open, onClose }: Iprops) {
};
const handleFolderSelection = async () => {
const folderPath = await watchService.selectFolder();
const folderPath = await watchFolderService.selectFolder();
await handleAddWatchMapping(folderPath);
};
const handleAddWatchMapping = async (inputFolderPath: string) => {
if (inputFolderPath?.length > 0) {
await watchService.addWatchMapping(
await watchFolderService.addWatchMapping(
inputFolderPath.substring(inputFolderPath.lastIndexOf('/') + 1),
inputFolderPath
);
setMappings(watchService.getWatchMappings());
setMappings(watchFolderService.getWatchMappings());
}
};
const handleRemoveWatchMapping = async (mapping: WatchMapping) => {
await watchService.removeWatchMapping(mapping.collectionName);
setMappings(watchService.getWatchMappings());
await watchFolderService.removeWatchMapping(mapping.collectionName);
setMappings(watchFolderService.getWatchMappings());
};
return (

View file

@ -1,6 +1,6 @@
import React, { useContext } from 'react';
import { Typography } from '@mui/material';
import watchService from 'services/watchFolderService';
import watchFolderService from 'services/watchFolderService';
import { AppContext } from 'pages/_app';
import { SyncProgressIcon } from './syncProgressIcon';
import { FlexWrapper } from 'components/Container';
@ -22,7 +22,7 @@ export function EntryHeading({ mapping }: Iprops) {
{mapping.collectionName}
</Typography>
{appContext.isFolderSyncRunning &&
watchService.currentEvent?.collectionName ===
watchFolderService.currentEvent?.collectionName ===
mapping.collectionName && <SyncProgressIcon />}
</FlexWrapper>
);

View file

@ -24,7 +24,7 @@ import UploadTypeSelector from '../../UploadTypeSelector';
import Router from 'next/router';
import { isCanvasBlocked } from 'utils/upload/isCanvasBlocked';
import { downloadApp } from 'utils/common';
import watchService from 'services/watchFolderService';
import watchFolderService from 'services/watchFolderService';
import DiscFullIcon from '@mui/icons-material/DiscFull';
import { NotificationAttributes } from 'types/Notification';
import {
@ -128,7 +128,7 @@ export default function Upload(props: Props) {
resumeDesktopUpload(type, electronFiles, collectionName);
}
);
watchService.init(
watchFolderService.init(
props.setElectronFiles,
setCollectionName,
props.syncWithRemote,
@ -380,7 +380,7 @@ export default function Upload(props: Props) {
props.setUploadInProgress(false);
props.syncWithRemote();
if (isElectron()) {
await watchService.allFileUploadsDone(
await watchFolderService.allFileUploadsDone(
filesWithCollectionToUpload,
collections
);

View file

@ -38,7 +38,7 @@ import uiService from './uiService';
import { logUploadInfo } from 'utils/upload';
import isElectron from 'is-electron';
import ImportService from 'services/importService';
import watchService from 'services/watchFolderService';
import watchFolderService from 'services/watchFolderService';
import { ProgressUpdater } from 'types/upload/ui';
const MAX_CONCURRENT_UPLOADS = 4;
@ -407,7 +407,7 @@ class UploadManager {
UPLOAD_RESULT.UPLOADED_WITH_STATIC_THUMBNAIL ||
fileUploadResult === UPLOAD_RESULT.ALREADY_UPLOADED
) {
await watchService.onFileUpload(
await watchFolderService.onFileUpload(
fileWithCollection,
uploadedFile
);

View file

@ -9,7 +9,7 @@ import { logError } from 'utils/sentry';
import { EventQueueItem, WatchMapping } from 'types/watchFolder';
import { ElectronAPIsInterface } from 'types/electron';
export class WatchService {
export class watchFolderService {
ElectronAPIs: ElectronAPIsInterface;
allElectronAPIsExist: boolean = false;
eventQueue: EventQueueItem[] = [];
@ -22,7 +22,7 @@ export class WatchService {
setCollectionName: (collectionName: string) => void;
syncWithRemote: () => void;
showProgressView: () => void;
setWatchServiceIsRunning: (isRunning: boolean) => void;
setwatchFolderServiceIsRunning: (isRunning: boolean) => void;
constructor() {
this.ElectronAPIs = (runningInBrowser() &&
@ -38,14 +38,15 @@ export class WatchService {
setElectronFiles: (files: ElectronFile[]) => void,
setCollectionName: (collectionName: string) => void,
syncWithRemote: () => void,
setWatchServiceIsRunning: (isRunning: boolean) => void
setwatchFolderServiceIsRunning: (isRunning: boolean) => void
) {
if (this.allElectronAPIsExist) {
try {
this.setElectronFiles = setElectronFiles;
this.setCollectionName = setCollectionName;
this.syncWithRemote = syncWithRemote;
this.setWatchServiceIsRunning = setWatchServiceIsRunning;
this.setwatchFolderServiceIsRunning =
setwatchFolderServiceIsRunning;
let mappings = this.getWatchMappings();
@ -179,7 +180,7 @@ export class WatchService {
setIsEventRunning(isEventRunning: boolean) {
this.isEventRunning = isEventRunning;
this.setWatchServiceIsRunning(isEventRunning);
this.setwatchFolderServiceIsRunning(isEventRunning);
}
async runNextEvent() {
@ -462,7 +463,7 @@ export class WatchService {
}
async function diskFileAddedCallback(
instance: WatchService,
instance: watchFolderService,
file: ElectronFile
) {
try {
@ -487,7 +488,7 @@ async function diskFileAddedCallback(
}
async function diskFileRemovedCallback(
instance: WatchService,
instance: watchFolderService,
filePath: string
) {
try {
@ -512,7 +513,7 @@ async function diskFileRemovedCallback(
}
async function diskFolderRemovedCallback(
instance: WatchService,
instance: watchFolderService,
folderPath: string
) {
try {
@ -529,12 +530,12 @@ async function diskFolderRemovedCallback(
}
}
const runNextEventByInstance = async (w: WatchService) => {
const runNextEventByInstance = async (w: watchFolderService) => {
await w.runNextEvent();
};
const hasMappingSameFolderPath = (
w: WatchService,
w: watchFolderService,
collectionName: string,
folderPath: string
) => {
@ -545,4 +546,4 @@ const hasMappingSameFolderPath = (
return mapping.folderPath === folderPath;
};
export default new WatchService();
export default new watchFolderService();

View file

@ -1,4 +1,4 @@
import { WatchService } from 'services/watchFolderService';
import { watchFolderService } from 'services/watchFolderService';
import { ElectronFile } from 'types/upload';
import { WatchMapping } from 'types/watchFolder';
@ -47,17 +47,17 @@ export interface ElectronAPIsInterface {
) => Promise<void>;
removeWatchMapping: (collectionName: string) => Promise<void>;
registerWatcherFunctions: (
WatchServiceInstance: WatchService,
watchFolderServiceInstance: watchFolderService,
addFile: (
WatchServiceInstance: WatchService,
watchFolderServiceInstance: watchFolderService,
file: ElectronFile
) => Promise<void>,
removeFile: (
WatchServiceInstance: WatchService,
watchFolderServiceInstance: watchFolderService,
path: string
) => Promise<void>,
removeFolder: (
WatchServiceInstance: WatchService,
watchFolderServiceInstance: watchFolderService,
folderPath: string
) => Promise<void>
) => void;