From 99b5cce1c9f44a200353368743bd3162b247d510 Mon Sep 17 00:00:00 2001 From: Abhinav Date: Sun, 19 Jun 2022 18:07:55 +0530 Subject: [PATCH] rename watchService to watchFolderService --- src/components/UploadProgress/index.tsx | 7 ++++-- src/components/WatchFolder/index.tsx | 16 ++++++------- .../WatchFolder/mappingEntry/entryHeading.tsx | 4 ++-- src/components/pages/gallery/Upload.tsx | 6 ++--- src/services/upload/uploadManager.ts | 4 ++-- src/services/watchFolderService.ts | 23 ++++++++++--------- src/types/electron/index.ts | 10 ++++---- 7 files changed, 37 insertions(+), 33 deletions(-) diff --git a/src/components/UploadProgress/index.tsx b/src/components/UploadProgress/index.tsx index 71d839a7f..2de22f302 100644 --- a/src/components/UploadProgress/index.tsx +++ b/src/components/UploadProgress/index.tsx @@ -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]); diff --git a/src/components/WatchFolder/index.tsx b/src/components/WatchFolder/index.tsx index 996c7e2e2..a504a5d4a 100644 --- a/src/components/WatchFolder/index.tsx +++ b/src/components/WatchFolder/index.tsx @@ -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 ( diff --git a/src/components/WatchFolder/mappingEntry/entryHeading.tsx b/src/components/WatchFolder/mappingEntry/entryHeading.tsx index 1c9ce028d..fa8c52b46 100644 --- a/src/components/WatchFolder/mappingEntry/entryHeading.tsx +++ b/src/components/WatchFolder/mappingEntry/entryHeading.tsx @@ -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} {appContext.isFolderSyncRunning && - watchService.currentEvent?.collectionName === + watchFolderService.currentEvent?.collectionName === mapping.collectionName && } ); diff --git a/src/components/pages/gallery/Upload.tsx b/src/components/pages/gallery/Upload.tsx index 96e166a7b..8e8674d49 100644 --- a/src/components/pages/gallery/Upload.tsx +++ b/src/components/pages/gallery/Upload.tsx @@ -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 ); diff --git a/src/services/upload/uploadManager.ts b/src/services/upload/uploadManager.ts index 121faf885..94ddf3778 100644 --- a/src/services/upload/uploadManager.ts +++ b/src/services/upload/uploadManager.ts @@ -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 ); diff --git a/src/services/watchFolderService.ts b/src/services/watchFolderService.ts index 16816cb7d..8ec0c2109 100644 --- a/src/services/watchFolderService.ts +++ b/src/services/watchFolderService.ts @@ -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(); diff --git a/src/types/electron/index.ts b/src/types/electron/index.ts index 9851b4334..e33dee0e5 100644 --- a/src/types/electron/index.ts +++ b/src/types/electron/index.ts @@ -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; removeWatchMapping: (collectionName: string) => Promise; registerWatcherFunctions: ( - WatchServiceInstance: WatchService, + watchFolderServiceInstance: watchFolderService, addFile: ( - WatchServiceInstance: WatchService, + watchFolderServiceInstance: watchFolderService, file: ElectronFile ) => Promise, removeFile: ( - WatchServiceInstance: WatchService, + watchFolderServiceInstance: watchFolderService, path: string ) => Promise, removeFolder: ( - WatchServiceInstance: WatchService, + watchFolderServiceInstance: watchFolderService, folderPath: string ) => Promise ) => void;