rename watchService to watchFolderService
This commit is contained in:
parent
1117534cc8
commit
99b5cce1c9
|
@ -13,7 +13,7 @@ import {
|
||||||
InProgressUpload,
|
InProgressUpload,
|
||||||
} from 'types/upload/ui';
|
} from 'types/upload/ui';
|
||||||
import UploadProgressContext from 'contexts/uploadProgress';
|
import UploadProgressContext from 'contexts/uploadProgress';
|
||||||
import watchService from 'services/watchFolderService';
|
import watchFolderService from 'services/watchFolderService';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
open: boolean;
|
open: boolean;
|
||||||
|
@ -45,7 +45,10 @@ export default function UploadProgress({
|
||||||
const [expanded, setExpanded] = useState(true);
|
const [expanded, setExpanded] = useState(true);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (appContext.isFolderSyncRunning && watchService.isUploadRunning()) {
|
if (
|
||||||
|
appContext.isFolderSyncRunning &&
|
||||||
|
watchFolderService.isUploadRunning()
|
||||||
|
) {
|
||||||
setExpanded(false);
|
setExpanded(false);
|
||||||
}
|
}
|
||||||
}, [appContext.isFolderSyncRunning]);
|
}, [appContext.isFolderSyncRunning]);
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { MappingList } from './mappingList';
|
||||||
import { NoMappingsContent } from './noMappingsContent';
|
import { NoMappingsContent } from './noMappingsContent';
|
||||||
import React, { useContext, useEffect, useState } from 'react';
|
import React, { useContext, useEffect, useState } from 'react';
|
||||||
import { Button, DialogActions, DialogContent } from '@mui/material';
|
import { Button, DialogActions, DialogContent } from '@mui/material';
|
||||||
import watchService from 'services/watchFolderService';
|
import watchFolderService from 'services/watchFolderService';
|
||||||
import { WatchMapping } from 'types/watchFolder';
|
import { WatchMapping } from 'types/watchFolder';
|
||||||
import { AppContext } from 'pages/_app';
|
import { AppContext } from 'pages/_app';
|
||||||
import constants from 'utils/strings/constants';
|
import constants from 'utils/strings/constants';
|
||||||
|
@ -19,7 +19,7 @@ export default function WatchFolder({ open, onClose }: Iprops) {
|
||||||
const appContext = useContext(AppContext);
|
const appContext = useContext(AppContext);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setMappings(watchService.getWatchMappings());
|
setMappings(watchFolderService.getWatchMappings());
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -35,7 +35,7 @@ export default function WatchFolder({ open, onClose }: Iprops) {
|
||||||
for (let i = 0; i < folders.length; i++) {
|
for (let i = 0; i < folders.length; i++) {
|
||||||
const folder: any = folders[i];
|
const folder: any = folders[i];
|
||||||
const path = (folder.path as string).replace(/\\/g, '/');
|
const path = (folder.path as string).replace(/\\/g, '/');
|
||||||
if (await watchService.isFolder(path)) {
|
if (await watchFolderService.isFolder(path)) {
|
||||||
await handleAddWatchMapping(path);
|
await handleAddWatchMapping(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,23 +46,23 @@ export default function WatchFolder({ open, onClose }: Iprops) {
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleFolderSelection = async () => {
|
const handleFolderSelection = async () => {
|
||||||
const folderPath = await watchService.selectFolder();
|
const folderPath = await watchFolderService.selectFolder();
|
||||||
await handleAddWatchMapping(folderPath);
|
await handleAddWatchMapping(folderPath);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleAddWatchMapping = async (inputFolderPath: string) => {
|
const handleAddWatchMapping = async (inputFolderPath: string) => {
|
||||||
if (inputFolderPath?.length > 0) {
|
if (inputFolderPath?.length > 0) {
|
||||||
await watchService.addWatchMapping(
|
await watchFolderService.addWatchMapping(
|
||||||
inputFolderPath.substring(inputFolderPath.lastIndexOf('/') + 1),
|
inputFolderPath.substring(inputFolderPath.lastIndexOf('/') + 1),
|
||||||
inputFolderPath
|
inputFolderPath
|
||||||
);
|
);
|
||||||
setMappings(watchService.getWatchMappings());
|
setMappings(watchFolderService.getWatchMappings());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleRemoveWatchMapping = async (mapping: WatchMapping) => {
|
const handleRemoveWatchMapping = async (mapping: WatchMapping) => {
|
||||||
await watchService.removeWatchMapping(mapping.collectionName);
|
await watchFolderService.removeWatchMapping(mapping.collectionName);
|
||||||
setMappings(watchService.getWatchMappings());
|
setMappings(watchFolderService.getWatchMappings());
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import React, { useContext } from 'react';
|
import React, { useContext } from 'react';
|
||||||
import { Typography } from '@mui/material';
|
import { Typography } from '@mui/material';
|
||||||
import watchService from 'services/watchFolderService';
|
import watchFolderService from 'services/watchFolderService';
|
||||||
import { AppContext } from 'pages/_app';
|
import { AppContext } from 'pages/_app';
|
||||||
import { SyncProgressIcon } from './syncProgressIcon';
|
import { SyncProgressIcon } from './syncProgressIcon';
|
||||||
import { FlexWrapper } from 'components/Container';
|
import { FlexWrapper } from 'components/Container';
|
||||||
|
@ -22,7 +22,7 @@ export function EntryHeading({ mapping }: Iprops) {
|
||||||
{mapping.collectionName}
|
{mapping.collectionName}
|
||||||
</Typography>
|
</Typography>
|
||||||
{appContext.isFolderSyncRunning &&
|
{appContext.isFolderSyncRunning &&
|
||||||
watchService.currentEvent?.collectionName ===
|
watchFolderService.currentEvent?.collectionName ===
|
||||||
mapping.collectionName && <SyncProgressIcon />}
|
mapping.collectionName && <SyncProgressIcon />}
|
||||||
</FlexWrapper>
|
</FlexWrapper>
|
||||||
);
|
);
|
||||||
|
|
|
@ -24,7 +24,7 @@ import UploadTypeSelector from '../../UploadTypeSelector';
|
||||||
import Router from 'next/router';
|
import Router from 'next/router';
|
||||||
import { isCanvasBlocked } from 'utils/upload/isCanvasBlocked';
|
import { isCanvasBlocked } from 'utils/upload/isCanvasBlocked';
|
||||||
import { downloadApp } from 'utils/common';
|
import { downloadApp } from 'utils/common';
|
||||||
import watchService from 'services/watchFolderService';
|
import watchFolderService from 'services/watchFolderService';
|
||||||
import DiscFullIcon from '@mui/icons-material/DiscFull';
|
import DiscFullIcon from '@mui/icons-material/DiscFull';
|
||||||
import { NotificationAttributes } from 'types/Notification';
|
import { NotificationAttributes } from 'types/Notification';
|
||||||
import {
|
import {
|
||||||
|
@ -128,7 +128,7 @@ export default function Upload(props: Props) {
|
||||||
resumeDesktopUpload(type, electronFiles, collectionName);
|
resumeDesktopUpload(type, electronFiles, collectionName);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
watchService.init(
|
watchFolderService.init(
|
||||||
props.setElectronFiles,
|
props.setElectronFiles,
|
||||||
setCollectionName,
|
setCollectionName,
|
||||||
props.syncWithRemote,
|
props.syncWithRemote,
|
||||||
|
@ -380,7 +380,7 @@ export default function Upload(props: Props) {
|
||||||
props.setUploadInProgress(false);
|
props.setUploadInProgress(false);
|
||||||
props.syncWithRemote();
|
props.syncWithRemote();
|
||||||
if (isElectron()) {
|
if (isElectron()) {
|
||||||
await watchService.allFileUploadsDone(
|
await watchFolderService.allFileUploadsDone(
|
||||||
filesWithCollectionToUpload,
|
filesWithCollectionToUpload,
|
||||||
collections
|
collections
|
||||||
);
|
);
|
||||||
|
|
|
@ -38,7 +38,7 @@ import uiService from './uiService';
|
||||||
import { logUploadInfo } from 'utils/upload';
|
import { logUploadInfo } from 'utils/upload';
|
||||||
import isElectron from 'is-electron';
|
import isElectron from 'is-electron';
|
||||||
import ImportService from 'services/importService';
|
import ImportService from 'services/importService';
|
||||||
import watchService from 'services/watchFolderService';
|
import watchFolderService from 'services/watchFolderService';
|
||||||
import { ProgressUpdater } from 'types/upload/ui';
|
import { ProgressUpdater } from 'types/upload/ui';
|
||||||
|
|
||||||
const MAX_CONCURRENT_UPLOADS = 4;
|
const MAX_CONCURRENT_UPLOADS = 4;
|
||||||
|
@ -407,7 +407,7 @@ class UploadManager {
|
||||||
UPLOAD_RESULT.UPLOADED_WITH_STATIC_THUMBNAIL ||
|
UPLOAD_RESULT.UPLOADED_WITH_STATIC_THUMBNAIL ||
|
||||||
fileUploadResult === UPLOAD_RESULT.ALREADY_UPLOADED
|
fileUploadResult === UPLOAD_RESULT.ALREADY_UPLOADED
|
||||||
) {
|
) {
|
||||||
await watchService.onFileUpload(
|
await watchFolderService.onFileUpload(
|
||||||
fileWithCollection,
|
fileWithCollection,
|
||||||
uploadedFile
|
uploadedFile
|
||||||
);
|
);
|
||||||
|
|
|
@ -9,7 +9,7 @@ import { logError } from 'utils/sentry';
|
||||||
import { EventQueueItem, WatchMapping } from 'types/watchFolder';
|
import { EventQueueItem, WatchMapping } from 'types/watchFolder';
|
||||||
import { ElectronAPIsInterface } from 'types/electron';
|
import { ElectronAPIsInterface } from 'types/electron';
|
||||||
|
|
||||||
export class WatchService {
|
export class watchFolderService {
|
||||||
ElectronAPIs: ElectronAPIsInterface;
|
ElectronAPIs: ElectronAPIsInterface;
|
||||||
allElectronAPIsExist: boolean = false;
|
allElectronAPIsExist: boolean = false;
|
||||||
eventQueue: EventQueueItem[] = [];
|
eventQueue: EventQueueItem[] = [];
|
||||||
|
@ -22,7 +22,7 @@ export class WatchService {
|
||||||
setCollectionName: (collectionName: string) => void;
|
setCollectionName: (collectionName: string) => void;
|
||||||
syncWithRemote: () => void;
|
syncWithRemote: () => void;
|
||||||
showProgressView: () => void;
|
showProgressView: () => void;
|
||||||
setWatchServiceIsRunning: (isRunning: boolean) => void;
|
setwatchFolderServiceIsRunning: (isRunning: boolean) => void;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.ElectronAPIs = (runningInBrowser() &&
|
this.ElectronAPIs = (runningInBrowser() &&
|
||||||
|
@ -38,14 +38,15 @@ export class WatchService {
|
||||||
setElectronFiles: (files: ElectronFile[]) => void,
|
setElectronFiles: (files: ElectronFile[]) => void,
|
||||||
setCollectionName: (collectionName: string) => void,
|
setCollectionName: (collectionName: string) => void,
|
||||||
syncWithRemote: () => void,
|
syncWithRemote: () => void,
|
||||||
setWatchServiceIsRunning: (isRunning: boolean) => void
|
setwatchFolderServiceIsRunning: (isRunning: boolean) => void
|
||||||
) {
|
) {
|
||||||
if (this.allElectronAPIsExist) {
|
if (this.allElectronAPIsExist) {
|
||||||
try {
|
try {
|
||||||
this.setElectronFiles = setElectronFiles;
|
this.setElectronFiles = setElectronFiles;
|
||||||
this.setCollectionName = setCollectionName;
|
this.setCollectionName = setCollectionName;
|
||||||
this.syncWithRemote = syncWithRemote;
|
this.syncWithRemote = syncWithRemote;
|
||||||
this.setWatchServiceIsRunning = setWatchServiceIsRunning;
|
this.setwatchFolderServiceIsRunning =
|
||||||
|
setwatchFolderServiceIsRunning;
|
||||||
|
|
||||||
let mappings = this.getWatchMappings();
|
let mappings = this.getWatchMappings();
|
||||||
|
|
||||||
|
@ -179,7 +180,7 @@ export class WatchService {
|
||||||
|
|
||||||
setIsEventRunning(isEventRunning: boolean) {
|
setIsEventRunning(isEventRunning: boolean) {
|
||||||
this.isEventRunning = isEventRunning;
|
this.isEventRunning = isEventRunning;
|
||||||
this.setWatchServiceIsRunning(isEventRunning);
|
this.setwatchFolderServiceIsRunning(isEventRunning);
|
||||||
}
|
}
|
||||||
|
|
||||||
async runNextEvent() {
|
async runNextEvent() {
|
||||||
|
@ -462,7 +463,7 @@ export class WatchService {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function diskFileAddedCallback(
|
async function diskFileAddedCallback(
|
||||||
instance: WatchService,
|
instance: watchFolderService,
|
||||||
file: ElectronFile
|
file: ElectronFile
|
||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
|
@ -487,7 +488,7 @@ async function diskFileAddedCallback(
|
||||||
}
|
}
|
||||||
|
|
||||||
async function diskFileRemovedCallback(
|
async function diskFileRemovedCallback(
|
||||||
instance: WatchService,
|
instance: watchFolderService,
|
||||||
filePath: string
|
filePath: string
|
||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
|
@ -512,7 +513,7 @@ async function diskFileRemovedCallback(
|
||||||
}
|
}
|
||||||
|
|
||||||
async function diskFolderRemovedCallback(
|
async function diskFolderRemovedCallback(
|
||||||
instance: WatchService,
|
instance: watchFolderService,
|
||||||
folderPath: string
|
folderPath: string
|
||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
|
@ -529,12 +530,12 @@ async function diskFolderRemovedCallback(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const runNextEventByInstance = async (w: WatchService) => {
|
const runNextEventByInstance = async (w: watchFolderService) => {
|
||||||
await w.runNextEvent();
|
await w.runNextEvent();
|
||||||
};
|
};
|
||||||
|
|
||||||
const hasMappingSameFolderPath = (
|
const hasMappingSameFolderPath = (
|
||||||
w: WatchService,
|
w: watchFolderService,
|
||||||
collectionName: string,
|
collectionName: string,
|
||||||
folderPath: string
|
folderPath: string
|
||||||
) => {
|
) => {
|
||||||
|
@ -545,4 +546,4 @@ const hasMappingSameFolderPath = (
|
||||||
return mapping.folderPath === folderPath;
|
return mapping.folderPath === folderPath;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default new WatchService();
|
export default new watchFolderService();
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { WatchService } from 'services/watchFolderService';
|
import { watchFolderService } from 'services/watchFolderService';
|
||||||
import { ElectronFile } from 'types/upload';
|
import { ElectronFile } from 'types/upload';
|
||||||
import { WatchMapping } from 'types/watchFolder';
|
import { WatchMapping } from 'types/watchFolder';
|
||||||
|
|
||||||
|
@ -47,17 +47,17 @@ export interface ElectronAPIsInterface {
|
||||||
) => Promise<void>;
|
) => Promise<void>;
|
||||||
removeWatchMapping: (collectionName: string) => Promise<void>;
|
removeWatchMapping: (collectionName: string) => Promise<void>;
|
||||||
registerWatcherFunctions: (
|
registerWatcherFunctions: (
|
||||||
WatchServiceInstance: WatchService,
|
watchFolderServiceInstance: watchFolderService,
|
||||||
addFile: (
|
addFile: (
|
||||||
WatchServiceInstance: WatchService,
|
watchFolderServiceInstance: watchFolderService,
|
||||||
file: ElectronFile
|
file: ElectronFile
|
||||||
) => Promise<void>,
|
) => Promise<void>,
|
||||||
removeFile: (
|
removeFile: (
|
||||||
WatchServiceInstance: WatchService,
|
watchFolderServiceInstance: watchFolderService,
|
||||||
path: string
|
path: string
|
||||||
) => Promise<void>,
|
) => Promise<void>,
|
||||||
removeFolder: (
|
removeFolder: (
|
||||||
WatchServiceInstance: WatchService,
|
watchFolderServiceInstance: watchFolderService,
|
||||||
folderPath: string
|
folderPath: string
|
||||||
) => Promise<void>
|
) => Promise<void>
|
||||||
) => void;
|
) => void;
|
||||||
|
|
Loading…
Reference in a new issue