From 687914dcf7c7e2a0e90647a33fb25fcce4998ab0 Mon Sep 17 00:00:00 2001 From: joan vicens Date: Wed, 17 Jan 2024 12:42:18 +0100 Subject: [PATCH 1/3] chore: ts lint fixes --- src/apps/fuse/FuseApp.ts | 1 - .../fuse/callbacks/MakeDirectoryCallback.ts | 2 +- src/apps/fuse/callbacks/StatFsCallback.ts | 7 +---- .../user/usage/builder.ts | 1 + .../virtual-drive/files/builder.ts | 9 ++++++- src/apps/fuse/index.ts | 2 +- src/apps/main/remote-sync/handlers.ts | 1 - .../dependency-injection/common/traverser.ts | 7 +---- .../folders/domain/ManagedFolderRepository.ts | 7 ----- .../folders/domain/OldFolderRepository.ts | 27 ------------------- .../infrastructure/HttpRemoteFileSystem.ts | 2 +- .../MainProcessSyncFolderMessenger.ts | 1 - .../application/AllWebdavItemsSearcher.ts | 27 ------------------- .../WebdavUnknownItemTypeSearcher.ts | 20 -------------- .../FolderCreatorFromOfflineFolder.test.ts | 1 - 15 files changed, 14 insertions(+), 101 deletions(-) delete mode 100644 src/context/virtual-drive/folders/domain/ManagedFolderRepository.ts delete mode 100644 src/context/virtual-drive/folders/domain/OldFolderRepository.ts delete mode 100644 src/context/virtual-drive/shared/application/AllWebdavItemsSearcher.ts delete mode 100644 src/context/virtual-drive/shared/application/WebdavUnknownItemTypeSearcher.ts diff --git a/src/apps/fuse/FuseApp.ts b/src/apps/fuse/FuseApp.ts index 44d8e047c..03cecbd24 100644 --- a/src/apps/fuse/FuseApp.ts +++ b/src/apps/fuse/FuseApp.ts @@ -18,7 +18,6 @@ import { FuseDependencyContainer } from './dependency-injection/FuseDependencyCo const fuse = require('@gcas/fuse'); export class FuseApp { - private static readonly SID = 41033; private _fuse: any; constructor( diff --git a/src/apps/fuse/callbacks/MakeDirectoryCallback.ts b/src/apps/fuse/callbacks/MakeDirectoryCallback.ts index f30dcb631..55c520052 100644 --- a/src/apps/fuse/callbacks/MakeDirectoryCallback.ts +++ b/src/apps/fuse/callbacks/MakeDirectoryCallback.ts @@ -42,7 +42,7 @@ export class MakeDirectoryCallback extends NotifyFuseCallback { } catch (err: unknown) { const error = this.resolveError({ path, mode }, err); - this.container.syncFolderMessenger.error(); + this.container.syncFolderMessenger.error(path, 'unknown error'); return this.left(error); } diff --git a/src/apps/fuse/callbacks/StatFsCallback.ts b/src/apps/fuse/callbacks/StatFsCallback.ts index 6a02eada7..332764beb 100644 --- a/src/apps/fuse/callbacks/StatFsCallback.ts +++ b/src/apps/fuse/callbacks/StatFsCallback.ts @@ -1,4 +1,3 @@ -import { UserDependencyContainer } from '../dependency-injection/user/UserDependencyContainer'; import { FuseCallback } from './FuseCallback'; import Logger from 'electron-log'; @@ -17,11 +16,7 @@ type StatFsCallbackData = { }; export class StatFsCallback extends FuseCallback> { - constructor( - private readonly _userContainer: UserDependencyContainer, - private readonly localStats: Partial, - private readonly sid: number - ) { + constructor(private readonly localStats: Partial) { super('Stat FS'); } diff --git a/src/apps/fuse/dependency-injection/user/usage/builder.ts b/src/apps/fuse/dependency-injection/user/usage/builder.ts index 6fc96a491..d28b90c59 100644 --- a/src/apps/fuse/dependency-injection/user/usage/builder.ts +++ b/src/apps/fuse/dependency-injection/user/usage/builder.ts @@ -15,6 +15,7 @@ export async function buildUsageContainer(): Promise { const { photos } = Photos; const repository = new CachedHttpUserUsageRepository( + // @ts-ignore clients.newDrive, photos ); diff --git a/src/apps/fuse/dependency-injection/virtual-drive/files/builder.ts b/src/apps/fuse/dependency-injection/virtual-drive/files/builder.ts index 7370ce51b..f9c746779 100644 --- a/src/apps/fuse/dependency-injection/virtual-drive/files/builder.ts +++ b/src/apps/fuse/dependency-injection/virtual-drive/files/builder.ts @@ -13,6 +13,7 @@ import { FuseLocalFileSystem } from '../../../../../context/virtual-drive/files/ import { InMemoryFileRepository } from '../../../../../context/virtual-drive/files/infrastructure/InMemoryFileRepository'; import { MainProcessSyncFileMessenger } from '../../../../../context/virtual-drive/files/infrastructure/MainProcessSyncFileMessenger'; import { SDKRemoteFileSystem } from '../../../../../context/virtual-drive/files/infrastructure/SDKRemoteFileSystem'; +import { DependencyInjectionHttpClientsProvider } from '../../common/clients'; import { DependencyInjectionEventBus } from '../../common/eventBus'; import { DependencyInjectionEventRepository } from '../../common/eventRepository'; import { DependencyInjectionStorageSdk } from '../../common/sdk'; @@ -31,6 +32,7 @@ export async function buildFilesContainer( const user = DependencyInjectionUserProvider.get(); const sdk = await DependencyInjectionStorageSdk.get(); const { bus: eventBus } = DependencyInjectionEventBus; + const clients = DependencyInjectionHttpClientsProvider.get(); const repositoryPopulator = new RepositoryPopulator(repository); @@ -45,7 +47,12 @@ export async function buildFilesContainer( const filesSearcher = new FilesSearcher(repository); - const remoteFileSystem = new SDKRemoteFileSystem(sdk, crypt, user.bucket); + const remoteFileSystem = new SDKRemoteFileSystem( + sdk, + clients, + crypt, + user.bucket + ); const localFileSystem = new FuseLocalFileSystem( sharedContainer.relativePathToAbsoluteConverter ); diff --git a/src/apps/fuse/index.ts b/src/apps/fuse/index.ts index 101f2fc07..54fed8d9c 100644 --- a/src/apps/fuse/index.ts +++ b/src/apps/fuse/index.ts @@ -1,12 +1,12 @@ import Logger from 'electron-log'; import { app } from 'electron'; -import { getRootVirtualDrive } from '../main/virutal-root-folder/service'; import eventBus from '../main/event-bus'; import { FuseApp } from './FuseApp'; import path from 'path'; import { FuseDependencyContainerFactory } from './dependency-injection/FuseDependencyContainerFactory'; import { HydrationApi } from '../hydration-api/HydrationApi'; +import { getRootVirtualDrive } from '../main/virtual-root-folder/service'; let fuseApp: FuseApp; diff --git a/src/apps/main/remote-sync/handlers.ts b/src/apps/main/remote-sync/handlers.ts index a03f8ef2a..6741bb16a 100644 --- a/src/apps/main/remote-sync/handlers.ts +++ b/src/apps/main/remote-sync/handlers.ts @@ -9,7 +9,6 @@ import { ipcMain } from 'electron'; import { reportError } from '../bug-report/service'; import { sleep } from '../util'; import { broadcastToWindows } from '../windows'; -import { updateSyncEngine } from '../background-processes/sync-engine'; let initialSyncReady = false; const driveFilesCollection = new DriveFilesCollection(); diff --git a/src/apps/sync-engine/dependency-injection/common/traverser.ts b/src/apps/sync-engine/dependency-injection/common/traverser.ts index be17a4e0c..b25de6491 100644 --- a/src/apps/sync-engine/dependency-injection/common/traverser.ts +++ b/src/apps/sync-engine/dependency-injection/common/traverser.ts @@ -1,7 +1,6 @@ import crypt from '../../../../context/shared/infrastructure/crypt'; import { Traverser } from '../../../../context/virtual-drive/items/application/Traverser'; import { DependencyInjectionUserProvider } from './user'; -import { ipcRendererSyncEngine } from '../../ipcRendererSyncEngine'; export class DependencyInjectionTraverserProvider { private static traverser: Traverser; @@ -13,11 +12,7 @@ export class DependencyInjectionTraverserProvider { const user = DependencyInjectionUserProvider.get(); - const traverser = Traverser.existingItems( - crypt, - ipcRendererSyncEngine, - user.root_folder_id - ); + const traverser = Traverser.existingItems(crypt, user.root_folder_id); DependencyInjectionTraverserProvider.traverser = traverser; diff --git a/src/context/virtual-drive/folders/domain/ManagedFolderRepository.ts b/src/context/virtual-drive/folders/domain/ManagedFolderRepository.ts deleted file mode 100644 index cbc06f16a..000000000 --- a/src/context/virtual-drive/folders/domain/ManagedFolderRepository.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { Folder } from './Folder'; - -// TODO: Find a better name -export interface ManagedFolderRepository { - insert(folder: Folder): Promise; - overwrite(oldFolder: Folder, newFolder: Folder): Promise; -} diff --git a/src/context/virtual-drive/folders/domain/OldFolderRepository.ts b/src/context/virtual-drive/folders/domain/OldFolderRepository.ts deleted file mode 100644 index 1563e2499..000000000 --- a/src/context/virtual-drive/folders/domain/OldFolderRepository.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { Folder, FolderAttributes } from './Folder'; -import { FolderPath } from './FolderPath'; - -export interface OldFolderRepository { - all(): Promise>; - - search(path: string): Folder | undefined; - - searchByPartial(partial: Partial): Folder | undefined; - - create( - name: FolderPath, - parentId: FolderAttributes['parentId'], - uuid: Folder['uuid'] - ): Promise; - - updateName(folder: Folder): Promise; - - updateParentDir(folder: Folder): Promise; - - searchOn(folder: Folder): Promise>; - - trash(folder: Folder): Promise; - - /** @deprecated */ - clear(): void; -} diff --git a/src/context/virtual-drive/folders/infrastructure/HttpRemoteFileSystem.ts b/src/context/virtual-drive/folders/infrastructure/HttpRemoteFileSystem.ts index befdb4214..fa0c09637 100644 --- a/src/context/virtual-drive/folders/infrastructure/HttpRemoteFileSystem.ts +++ b/src/context/virtual-drive/folders/infrastructure/HttpRemoteFileSystem.ts @@ -1,4 +1,4 @@ -import axios, { Axios } from 'axios'; +import { Axios } from 'axios'; import Logger from 'electron-log'; import * as uuid from 'uuid'; import { Folder } from '../domain/Folder'; diff --git a/src/context/virtual-drive/folders/infrastructure/MainProcessSyncFolderMessenger.ts b/src/context/virtual-drive/folders/infrastructure/MainProcessSyncFolderMessenger.ts index e627298ad..a1c019dcc 100644 --- a/src/context/virtual-drive/folders/infrastructure/MainProcessSyncFolderMessenger.ts +++ b/src/context/virtual-drive/folders/infrastructure/MainProcessSyncFolderMessenger.ts @@ -1,6 +1,5 @@ import { trackError } from '../../../../apps/main/analytics/service'; import { setTrayStatus } from '../../../../apps/main/tray/tray'; -import { broadcastToWindows } from '../../../../apps/main/windows'; import { SyncFolderMessenger } from '../domain/SyncFolderMessenger'; export class MainProcessSyncFolderMessenger implements SyncFolderMessenger { diff --git a/src/context/virtual-drive/shared/application/AllWebdavItemsSearcher.ts b/src/context/virtual-drive/shared/application/AllWebdavItemsSearcher.ts deleted file mode 100644 index 8ab4113af..000000000 --- a/src/context/virtual-drive/shared/application/AllWebdavItemsSearcher.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { OldFileRepository } from '../../files/domain/OldFileRepository'; -import { FolderFinder } from '../../folders/application/FolderFinder'; -import { OldFolderRepository } from '../../folders/domain/OldFolderRepository'; - -export class AllWebdavItemsNameLister { - constructor( - private readonly filesRepository: OldFileRepository, - private readonly folderRepository: OldFolderRepository, - private readonly folderfinder: FolderFinder - ) {} - - async run(path: string): Promise> { - const folder = this.folderfinder.run(path); - - const names: Array = []; - - const files = await this.filesRepository.searchOnFolder(folder.id); - - files.forEach((file) => names.push(file.nameWithExtension)); - - const folders = await this.folderRepository.searchOn(folder); - - folders.forEach((folder) => names.push(folder.name)); - - return names; - } -} diff --git a/src/context/virtual-drive/shared/application/WebdavUnknownItemTypeSearcher.ts b/src/context/virtual-drive/shared/application/WebdavUnknownItemTypeSearcher.ts deleted file mode 100644 index 790a29f47..000000000 --- a/src/context/virtual-drive/shared/application/WebdavUnknownItemTypeSearcher.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { FilePath } from '../../files/domain/FilePath'; -import { File } from '../../files/domain/File'; -import { OldFileRepository } from '../../files/domain/OldFileRepository'; -import { Folder } from '../../folders/domain/Folder'; -import { OldFolderRepository } from '../../folders/domain/OldFolderRepository'; - -export class WebdavUnknownItemTypeSearcher { - constructor( - private readonly filesRepository: OldFileRepository, - private readonly folderRepository: OldFolderRepository - ) {} - - run(path: string): File | Folder | undefined { - const file = this.filesRepository.search(new FilePath(path)); - - if (file) return file; - - return this.folderRepository.search(path); - } -} diff --git a/tests/context/virtual-drive/folders/application/FolderCreatorFromOfflineFolder.test.ts b/tests/context/virtual-drive/folders/application/FolderCreatorFromOfflineFolder.test.ts index 0851d0e97..c16a6fb4d 100644 --- a/tests/context/virtual-drive/folders/application/FolderCreatorFromOfflineFolder.test.ts +++ b/tests/context/virtual-drive/folders/application/FolderCreatorFromOfflineFolder.test.ts @@ -1,5 +1,4 @@ import { FolderCreatorFromOfflineFolder } from '../../../../../src/context/virtual-drive/folders/application/FolderCreatorFromOfflineFolder'; -import { Folder } from '../../../../../src/context/virtual-drive/folders/domain/Folder'; import { EventBusMock } from '../../shared/__mock__/EventBusMock'; import { FolderRemoteFileSystemMock } from '../__mocks__/FolderRemoteFileSystemMock'; import { FolderRepositoryMock } from '../__mocks__/FolderRepositoryMock'; From e936ff681d81f09f621ded21481bb3f37706a649 Mon Sep 17 00:00:00 2001 From: joan vicens Date: Wed, 17 Jan 2024 13:09:28 +0100 Subject: [PATCH 2/3] feat: create backgorund process messenger --- .../fuse/callbacks/MakeDirectoryCallback.ts | 5 +- .../virtual-drive/files/builder.ts | 2 +- .../virtual-drive/folders/builder.ts | 2 +- src/apps/shared/IPC/events/sync-engine.ts | 6 ++ .../dependency-injection/files/builder.ts | 26 ++++---- .../dependency-injection/folders/builder.ts | 9 ++- .../files/application/FileCreator.ts | 6 +- .../files/domain/SyncFileMessenger.ts | 12 ++-- .../BackgroundProcessSyncFileMessenger.ts | 64 +++++++++++++++++++ .../MainProcessSyncFileMessenger.ts | 20 +++--- .../folders/domain/SyncFolderMessenger.ts | 16 +++-- .../BackgroundProcessSyncFolderMessenger.ts | 56 ++++++++++++++++ .../MainProcessSyncFolderMessenger.ts | 27 ++++++-- .../files/__mocks__/FileSyncNotifierMock.ts | 6 +- .../__mocks__/FolderSyncManagerMock.ts | 2 +- 15 files changed, 218 insertions(+), 41 deletions(-) create mode 100644 src/context/virtual-drive/files/infrastructure/SyncFileMessengers/BackgroundProcessSyncFileMessenger.ts rename src/context/virtual-drive/files/infrastructure/{ => SyncFileMessengers}/MainProcessSyncFileMessenger.ts (75%) create mode 100644 src/context/virtual-drive/folders/infrastructure/SyncMessengers/BackgroundProcessSyncFolderMessenger.ts rename src/context/virtual-drive/folders/infrastructure/{ => SyncMessengers}/MainProcessSyncFolderMessenger.ts (50%) diff --git a/src/apps/fuse/callbacks/MakeDirectoryCallback.ts b/src/apps/fuse/callbacks/MakeDirectoryCallback.ts index 55c520052..e543ce5cf 100644 --- a/src/apps/fuse/callbacks/MakeDirectoryCallback.ts +++ b/src/apps/fuse/callbacks/MakeDirectoryCallback.ts @@ -42,7 +42,10 @@ export class MakeDirectoryCallback extends NotifyFuseCallback { } catch (err: unknown) { const error = this.resolveError({ path, mode }, err); - this.container.syncFolderMessenger.error(path, 'unknown error'); + this.container.syncFolderMessenger.errorWhileCreating( + path, + 'unknown error' + ); return this.left(error); } diff --git a/src/apps/fuse/dependency-injection/virtual-drive/files/builder.ts b/src/apps/fuse/dependency-injection/virtual-drive/files/builder.ts index f9c746779..385f883fa 100644 --- a/src/apps/fuse/dependency-injection/virtual-drive/files/builder.ts +++ b/src/apps/fuse/dependency-injection/virtual-drive/files/builder.ts @@ -11,7 +11,7 @@ import { SameFileWasMoved } from '../../../../../context/virtual-drive/files/app import { File } from '../../../../../context/virtual-drive/files/domain/File'; import { FuseLocalFileSystem } from '../../../../../context/virtual-drive/files/infrastructure/FuseLocalFileSystem'; import { InMemoryFileRepository } from '../../../../../context/virtual-drive/files/infrastructure/InMemoryFileRepository'; -import { MainProcessSyncFileMessenger } from '../../../../../context/virtual-drive/files/infrastructure/MainProcessSyncFileMessenger'; +import { MainProcessSyncFileMessenger } from '../../../../../context/virtual-drive/files/infrastructure/SyncFileMessengers/MainProcessSyncFileMessenger'; import { SDKRemoteFileSystem } from '../../../../../context/virtual-drive/files/infrastructure/SDKRemoteFileSystem'; import { DependencyInjectionHttpClientsProvider } from '../../common/clients'; import { DependencyInjectionEventBus } from '../../common/eventBus'; diff --git a/src/apps/fuse/dependency-injection/virtual-drive/folders/builder.ts b/src/apps/fuse/dependency-injection/virtual-drive/folders/builder.ts index e340cdd4f..f5c3a0e53 100644 --- a/src/apps/fuse/dependency-injection/virtual-drive/folders/builder.ts +++ b/src/apps/fuse/dependency-injection/virtual-drive/folders/builder.ts @@ -13,7 +13,7 @@ import { Folder } from '../../../../../context/virtual-drive/folders/domain/Fold import { FuseLocalFileSystem } from '../../../../../context/virtual-drive/folders/infrastructure/FuseLocalFileSystem'; import { HttpRemoteFileSystem } from '../../../../../context/virtual-drive/folders/infrastructure/HttpRemoteFileSystem'; import { InMemoryFolderRepository } from '../../../../../context/virtual-drive/folders/infrastructure/InMemoryFolderRepository'; -import { MainProcessSyncFolderMessenger } from '../../../../../context/virtual-drive/folders/infrastructure/MainProcessSyncFolderMessenger'; +import { MainProcessSyncFolderMessenger } from '../../../../../context/virtual-drive/folders/infrastructure/SyncMessengers/MainProcessSyncFolderMessenger'; import { DependencyInjectionHttpClientsProvider } from '../../common/clients'; import { DependencyInjectionEventBus } from '../../common/eventBus'; diff --git a/src/apps/shared/IPC/events/sync-engine.ts b/src/apps/shared/IPC/events/sync-engine.ts index 2b9494796..9cbf931bb 100644 --- a/src/apps/shared/IPC/events/sync-engine.ts +++ b/src/apps/shared/IPC/events/sync-engine.ts @@ -45,9 +45,15 @@ type FileUpdatePayload = { export type FolderEvents = { FOLDER_CREATING: (payload: { name: string }) => void; FOLDER_CREATED: (payload: { name: string }) => void; + FOLDER_CREATION_ERROR: (payload: { name: string; error: string }) => void; FOLDER_RENAMING: (payload: { oldName: string; newName: string }) => void; FOLDER_RENAMED: (payload: { oldName: string; newName: string }) => void; + FOLDER_RENAME_ERROR: (payload: { + oldName: string; + newName: string; + error: string; + }) => void; }; export type FilesEvents = { diff --git a/src/apps/sync-engine/dependency-injection/files/builder.ts b/src/apps/sync-engine/dependency-injection/files/builder.ts index 9061c6760..455faa89f 100644 --- a/src/apps/sync-engine/dependency-injection/files/builder.ts +++ b/src/apps/sync-engine/dependency-injection/files/builder.ts @@ -1,12 +1,4 @@ import crypt from '../../../../context/shared/infrastructure/crypt'; -import { DependencyInjectionEventBus } from '../common/eventBus'; -import { DependencyInjectionEventRepository } from '../common/eventRepository'; -import { DependencyInjectionUserProvider } from '../common/user'; -import { DependencyInjectionVirtualDrive } from '../common/virtualDrive'; -import { FoldersContainer } from '../folders/FoldersContainer'; -import { SharedContainer } from '../shared/SharedContainer'; -import { FilesContainer } from './FilesContainer'; -import { DependencyInjectionStorageSdk } from '../common/sdk'; import { CreateFilePlaceholderOnDeletionFailed } from '../../../../context/virtual-drive/files/application/CreateFilePlaceholderOnDeletionFailed'; import { FileCreator } from '../../../../context/virtual-drive/files/application/FileCreator'; import { FileDeleter } from '../../../../context/virtual-drive/files/application/FileDeleter'; @@ -19,11 +11,20 @@ import { RepositoryPopulator } from '../../../../context/virtual-drive/files/app import { RetrieveAllFiles } from '../../../../context/virtual-drive/files/application/RetrieveAllFiles'; import { SameFileWasMoved } from '../../../../context/virtual-drive/files/application/SameFileWasMoved'; import { InMemoryFileRepository } from '../../../../context/virtual-drive/files/infrastructure/InMemoryFileRepository'; -import { SDKRemoteFileSystem } from '../../../../context/virtual-drive/files/infrastructure/SDKRemoteFileSystem'; import { NodeWinLocalFileSystem } from '../../../../context/virtual-drive/files/infrastructure/NodeWinLocalFileSystem'; +import { SDKRemoteFileSystem } from '../../../../context/virtual-drive/files/infrastructure/SDKRemoteFileSystem'; +import { BackgroundProcessSyncFileMessenger } from '../../../../context/virtual-drive/files/infrastructure/SyncFileMessengers/BackgroundProcessSyncFileMessenger'; import { LocalFileIdProvider } from '../../../../context/virtual-drive/shared/application/LocalFileIdProvider'; -import { MainProcessSyncFileMessenger } from '../../../../context/virtual-drive/files/infrastructure/MainProcessSyncFileMessenger'; +import { ipcRendererSyncEngine } from '../../ipcRendererSyncEngine'; import { DependencyInjectionHttpClientsProvider } from '../common/clients'; +import { DependencyInjectionEventBus } from '../common/eventBus'; +import { DependencyInjectionEventRepository } from '../common/eventRepository'; +import { DependencyInjectionStorageSdk } from '../common/sdk'; +import { DependencyInjectionUserProvider } from '../common/user'; +import { DependencyInjectionVirtualDrive } from '../common/virtualDrive'; +import { FoldersContainer } from '../folders/FoldersContainer'; +import { SharedContainer } from '../shared/SharedContainer'; +import { FilesContainer } from './FilesContainer'; export async function buildFilesContainer( folderContainer: FoldersContainer, @@ -50,7 +51,10 @@ export async function buildFilesContainer( virtualDrive, sharedContainer.relativePathToAbsoluteConverter ); - const syncFileMessenger = new MainProcessSyncFileMessenger(); + + const syncFileMessenger = new BackgroundProcessSyncFileMessenger( + ipcRendererSyncEngine + ); const repository = new InMemoryFileRepository(); diff --git a/src/apps/sync-engine/dependency-injection/folders/builder.ts b/src/apps/sync-engine/dependency-injection/folders/builder.ts index 5f0c1d84d..051d1bd99 100644 --- a/src/apps/sync-engine/dependency-injection/folders/builder.ts +++ b/src/apps/sync-engine/dependency-injection/folders/builder.ts @@ -1,4 +1,3 @@ -import { NodeWinLocalFileSystem } from '../../../../context/virtual-drive/folders/infrastructure/NodeWinLocalFileSystem'; import { AllParentFoldersStatusIsExists } from '../../../../context/virtual-drive/folders/application/AllParentFoldersStatusIsExists'; import { FolderByPartialSearcher } from '../../../../context/virtual-drive/folders/application/FolderByPartialSearcher'; import { FolderCreatorFromOfflineFolder } from '../../../../context/virtual-drive/folders/application/FolderCreatorFromOfflineFolder'; @@ -20,13 +19,15 @@ import { FolderPlaceholderUpdater } from '../../../../context/virtual-drive/fold import { HttpRemoteFileSystem } from '../../../../context/virtual-drive/folders/infrastructure/HttpRemoteFileSystem'; import { InMemoryFolderRepository } from '../../../../context/virtual-drive/folders/infrastructure/InMemoryFolderRepository'; import { InMemoryOfflineFolderRepository } from '../../../../context/virtual-drive/folders/infrastructure/InMemoryOfflineFolderRepository'; +import { NodeWinLocalFileSystem } from '../../../../context/virtual-drive/folders/infrastructure/NodeWinLocalFileSystem'; +import { BackgroundProcessSyncFolderMessenger } from '../../../../context/virtual-drive/folders/infrastructure/SyncMessengers/BackgroundProcessSyncFolderMessenger'; +import { ipcRendererSyncEngine } from '../../ipcRendererSyncEngine'; import { DependencyInjectionHttpClientsProvider } from '../common/clients'; import { DependencyInjectionEventBus } from '../common/eventBus'; import { DependencyInjectionEventRepository } from '../common/eventRepository'; import { DependencyInjectionVirtualDrive } from '../common/virtualDrive'; import { SharedContainer } from '../shared/SharedContainer'; import { FoldersContainer } from './FoldersContainer'; -import { MainProcessSyncFolderMessenger } from '../../../../context/virtual-drive/folders/infrastructure/MainProcessSyncFolderMessenger'; export async function buildFoldersContainer( shredContainer: SharedContainer @@ -38,7 +39,9 @@ export async function buildFoldersContainer( const repository = new InMemoryFolderRepository(); - const syncFolderMessenger = new MainProcessSyncFolderMessenger(); + const syncFolderMessenger = new BackgroundProcessSyncFolderMessenger( + ipcRendererSyncEngine + ); const localFileSystem = new NodeWinLocalFileSystem(virtualDrive); const remoteFileSystem = new HttpRemoteFileSystem( diff --git a/src/context/virtual-drive/files/application/FileCreator.ts b/src/context/virtual-drive/files/application/FileCreator.ts index 0cc7cf51b..cde683228 100644 --- a/src/context/virtual-drive/files/application/FileCreator.ts +++ b/src/context/virtual-drive/files/application/FileCreator.ts @@ -60,7 +60,11 @@ export class FileCreator { const filePath = new FilePath(path); - await this.notifier.error(filePath.name(), filePath.extension(), message); + await this.notifier.errorWhileCreating( + filePath.name(), + filePath.extension(), + message + ); throw error; } diff --git a/src/context/virtual-drive/files/domain/SyncFileMessenger.ts b/src/context/virtual-drive/files/domain/SyncFileMessenger.ts index 0693af0ea..f7f577581 100644 --- a/src/context/virtual-drive/files/domain/SyncFileMessenger.ts +++ b/src/context/virtual-drive/files/domain/SyncFileMessenger.ts @@ -1,11 +1,15 @@ export interface SyncFileMessenger { created(name: string, extension: string): Promise; - error(name: string, extension: string, message: string): Promise; - trashing(name: string, type: string, size: number): Promise; - trashed(name: string, type: string, size: number): Promise; + errorWhileCreating( + name: string, + extension: string, + message: string + ): Promise; + trashing(name: string, extension: string, size: number): Promise; + trashed(name: string, extension: string, size: number): Promise; errorWhileTrashing( name: string, - type: string, + extension: string, message: string ): Promise; } diff --git a/src/context/virtual-drive/files/infrastructure/SyncFileMessengers/BackgroundProcessSyncFileMessenger.ts b/src/context/virtual-drive/files/infrastructure/SyncFileMessengers/BackgroundProcessSyncFileMessenger.ts new file mode 100644 index 000000000..f4110a66d --- /dev/null +++ b/src/context/virtual-drive/files/infrastructure/SyncFileMessengers/BackgroundProcessSyncFileMessenger.ts @@ -0,0 +1,64 @@ +import { SyncEngineIpc } from '../../../../../apps/sync-engine/ipcRendererSyncEngine'; +import { SyncMessenger } from '../../../../shared/domain/SyncMessenger'; +import { SyncFileMessenger } from '../../domain/SyncFileMessenger'; + +export class BackgroundProcessSyncFileMessenger + extends SyncMessenger + implements SyncFileMessenger +{ + constructor(private readonly ipc: SyncEngineIpc) { + super(); + } + + async created(name: string, extension: string): Promise { + this.ipc.send('FILE_CREATED', { + name, + extension, + nameWithExtension: this.nameWithExtension(name, extension), + }); + } + + async errorWhileCreating( + name: string, + extension: string, + message: string + ): Promise { + this.ipc.send('FILE_UPLOAD_ERROR', { + name, + extension, + nameWithExtension: this.nameWithExtension(name, extension), + error: message, + }); + } + + async trashing(name: string, extension: string, size: number): Promise { + this.ipc.send('FILE_DELETING', { + name, + extension, + nameWithExtension: this.nameWithExtension(name, extension), + size, + }); + } + + async trashed(name: string, extension: string, size: number): Promise { + this.ipc.send('FILE_DELETED', { + name, + extension, + nameWithExtension: this.nameWithExtension(name, extension), + size, + }); + } + + async errorWhileTrashing( + name: string, + extension: string, + message: string + ): Promise { + this.ipc.send('FILE_DELETION_ERROR', { + name, + extension, + nameWithExtension: this.nameWithExtension(name, extension), + error: message, + }); + } +} diff --git a/src/context/virtual-drive/files/infrastructure/MainProcessSyncFileMessenger.ts b/src/context/virtual-drive/files/infrastructure/SyncFileMessengers/MainProcessSyncFileMessenger.ts similarity index 75% rename from src/context/virtual-drive/files/infrastructure/MainProcessSyncFileMessenger.ts rename to src/context/virtual-drive/files/infrastructure/SyncFileMessengers/MainProcessSyncFileMessenger.ts index bedf39351..93ab2b7e0 100644 --- a/src/context/virtual-drive/files/infrastructure/MainProcessSyncFileMessenger.ts +++ b/src/context/virtual-drive/files/infrastructure/SyncFileMessengers/MainProcessSyncFileMessenger.ts @@ -1,13 +1,13 @@ import { trackError, trackEvent, -} from '../../../../apps/main/analytics/service'; -import { addProcessIssue } from '../../../../apps/main/background-processes/process-issues'; -import { setTrayStatus } from '../../../../apps/main/tray/tray'; -import { broadcastToWindows } from '../../../../apps/main/windows'; -import { ProcessIssue } from '../../../../apps/shared/types'; -import { SyncMessenger } from '../../../shared/domain/SyncMessenger'; -import { SyncFileMessenger } from '../domain/SyncFileMessenger'; +} from '../../../../../apps/main/analytics/service'; +import { addProcessIssue } from '../../../../../apps/main/background-processes/process-issues'; +import { setTrayStatus } from '../../../../../apps/main/tray/tray'; +import { broadcastToWindows } from '../../../../../apps/main/windows'; +import { ProcessIssue } from '../../../../../apps/shared/types'; +import { SyncMessenger } from '../../../../shared/domain/SyncMessenger'; +import { SyncFileMessenger } from '../../domain/SyncFileMessenger'; export class MainProcessSyncFileMessenger extends SyncMessenger @@ -22,7 +22,11 @@ export class MainProcessSyncFileMessenger }); } - async error(name: string, extension: string, message: string): Promise { + async errorWhileCreating( + name: string, + extension: string, + message: string + ): Promise { const nameWithExtension = this.nameWithExtension(name, extension); setTrayStatus('ALERT'); diff --git a/src/context/virtual-drive/folders/domain/SyncFolderMessenger.ts b/src/context/virtual-drive/folders/domain/SyncFolderMessenger.ts index 7a8650016..c5ab1e607 100644 --- a/src/context/virtual-drive/folders/domain/SyncFolderMessenger.ts +++ b/src/context/virtual-drive/folders/domain/SyncFolderMessenger.ts @@ -1,7 +1,13 @@ export interface SyncFolderMessenger { - creating(name: string): Promise; - created(name: string): Promise; - rename(name: string, newName: string): Promise; - renamed(name: string, newName: string): Promise; - error(name: string, message: string): Promise; + creating(desiredName: string): Promise; + created(desiredName: string): Promise; + errorWhileCreating(desiredName: string, message: string): Promise; + + rename(currentName: string, desiredName: string): Promise; + renamed(currentName: string, desiredName: string): Promise; + errorWhileRenaming( + currentName: string, + desiredName: string, + message: string + ): Promise; } diff --git a/src/context/virtual-drive/folders/infrastructure/SyncMessengers/BackgroundProcessSyncFolderMessenger.ts b/src/context/virtual-drive/folders/infrastructure/SyncMessengers/BackgroundProcessSyncFolderMessenger.ts new file mode 100644 index 000000000..f56f3657f --- /dev/null +++ b/src/context/virtual-drive/folders/infrastructure/SyncMessengers/BackgroundProcessSyncFolderMessenger.ts @@ -0,0 +1,56 @@ +import { SyncEngineIpc } from '../../../../../apps/sync-engine/ipcRendererSyncEngine'; +import { SyncMessenger } from '../../../../shared/domain/SyncMessenger'; +import { SyncFolderMessenger } from '../../domain/SyncFolderMessenger'; + +export class BackgroundProcessSyncFolderMessenger + extends SyncMessenger + implements SyncFolderMessenger +{ + constructor(private readonly ipc: SyncEngineIpc) { + super(); + } + + async creating(currentName: string): Promise { + this.ipc.send('FOLDER_CREATING', { name: currentName }); + } + + async created(currentName: string): Promise { + this.ipc.send('FOLDER_CREATED', { name: currentName }); + } + + async errorWhileCreating( + currentName: string, + message: string + ): Promise { + this.ipc.send('FOLDER_CREATION_ERROR', { + name: currentName, + error: message, + }); + } + + async rename(currentName: string, desiredName: string): Promise { + this.ipc.send('FOLDER_RENAMING', { + oldName: currentName, + newName: desiredName, + }); + } + + async renamed(currentName: string, desiredName: string): Promise { + this.ipc.send('FOLDER_RENAMED', { + oldName: currentName, + newName: desiredName, + }); + } + + async errorWhileRenaming( + currentName: string, + desiredName: string, + message: string + ): Promise { + this.ipc.send('FOLDER_RENAME_ERROR', { + oldName: currentName, + newName: desiredName, + error: message, + }); + } +} diff --git a/src/context/virtual-drive/folders/infrastructure/MainProcessSyncFolderMessenger.ts b/src/context/virtual-drive/folders/infrastructure/SyncMessengers/MainProcessSyncFolderMessenger.ts similarity index 50% rename from src/context/virtual-drive/folders/infrastructure/MainProcessSyncFolderMessenger.ts rename to src/context/virtual-drive/folders/infrastructure/SyncMessengers/MainProcessSyncFolderMessenger.ts index a1c019dcc..2fbba1950 100644 --- a/src/context/virtual-drive/folders/infrastructure/MainProcessSyncFolderMessenger.ts +++ b/src/context/virtual-drive/folders/infrastructure/SyncMessengers/MainProcessSyncFolderMessenger.ts @@ -1,21 +1,40 @@ -import { trackError } from '../../../../apps/main/analytics/service'; -import { setTrayStatus } from '../../../../apps/main/tray/tray'; -import { SyncFolderMessenger } from '../domain/SyncFolderMessenger'; +import { trackError } from '../../../../../apps/main/analytics/service'; +import { setTrayStatus } from '../../../../../apps/main/tray/tray'; +import { SyncFolderMessenger } from '../../domain/SyncFolderMessenger'; export class MainProcessSyncFolderMessenger implements SyncFolderMessenger { async rename(_name: string, _newName: string): Promise { setTrayStatus('SYNCING'); } + async renamed(_name: string, _newName: string): Promise { setTrayStatus('IDLE'); } + + async errorWhileRenaming( + currentName: string, + _desiredName: string, + message: string + ): Promise { + setTrayStatus('ALERT'); + + trackError('Rename Error', new Error(message), { + itemType: 'Folder', + root: '', + from: currentName, + action: 'Rename', + }); + } + async creating(_name: string): Promise { setTrayStatus('SYNCING'); } + async created(_name: string): Promise { setTrayStatus('IDLE'); } - async error(name: string, message: string): Promise { + + async errorWhileCreating(name: string, message: string): Promise { setTrayStatus('ALERT'); trackError('Upload Error', new Error(message), { diff --git a/tests/context/virtual-drive/files/__mocks__/FileSyncNotifierMock.ts b/tests/context/virtual-drive/files/__mocks__/FileSyncNotifierMock.ts index a9b860c72..9c4e61c0d 100644 --- a/tests/context/virtual-drive/files/__mocks__/FileSyncNotifierMock.ts +++ b/tests/context/virtual-drive/files/__mocks__/FileSyncNotifierMock.ts @@ -10,7 +10,11 @@ export class FileSyncNotifierMock implements SyncFileMessenger { created(name: string, extension: string): Promise { return this.createdMock(name, extension); } - error(name: string, extension: string, message: string): Promise { + errorWhileCreating( + name: string, + extension: string, + message: string + ): Promise { return this.errorMock(name, extension, message); } trashing(name: string, type: string, size: number): Promise { diff --git a/tests/context/virtual-drive/folders/__mocks__/FolderSyncManagerMock.ts b/tests/context/virtual-drive/folders/__mocks__/FolderSyncManagerMock.ts index 2777968e3..0a8af5985 100644 --- a/tests/context/virtual-drive/folders/__mocks__/FolderSyncManagerMock.ts +++ b/tests/context/virtual-drive/folders/__mocks__/FolderSyncManagerMock.ts @@ -19,7 +19,7 @@ export class FolderSyncNotifierMock implements SyncFolderMessenger { renamed(name: string, newName: string): Promise { return this.renamedMock(name, newName); } - error(): Promise { + errorWhileCreating(): Promise { return this.errorMock(); } } From e0148131212f4702cc011fdeb0fae67eb7eb8f5b Mon Sep 17 00:00:00 2001 From: joan vicens Date: Wed, 17 Jan 2024 13:39:36 +0100 Subject: [PATCH 3/3] chore: platform dependant process --- release/app/package.json | 1 - release/app/yarn.lock | 27 +-------------------------- src/apps/main/main.ts | 2 -- src/apps/main/virtual-drive.ts | 7 +++++++ 4 files changed, 8 insertions(+), 29 deletions(-) create mode 100644 src/apps/main/virtual-drive.ts diff --git a/release/app/package.json b/release/app/package.json index 056ce0864..7f31c2a10 100644 --- a/release/app/package.json +++ b/release/app/package.json @@ -11,7 +11,6 @@ "reload-virtual-drive": "yarn add --ignore-scripts ../../../node-win && npm run link-modules" }, "dependencies": { - "@gcas/fuse": "^2.4.2", "@rudderstack/rudder-sdk-node": "^1.1.4", "better-sqlite3": "^8.3.0", "typeorm": "^0.3.16", diff --git a/release/app/yarn.lock b/release/app/yarn.lock index 752800d3f..8b0c5b3c3 100644 --- a/release/app/yarn.lock +++ b/release/app/yarn.lock @@ -30,14 +30,6 @@ enabled "2.0.x" kuler "^2.0.0" -"@gcas/fuse@^2.4.2": - version "2.4.2" - resolved "https://registry.yarnpkg.com/@gcas/fuse/-/fuse-2.4.2.tgz#149bd97ec8a60988f4868bacd719c7e8a1c41876" - integrity sha512-l/vVd2eXAuzKG4QilN1VRa8za5glndSK+jxcLrzMiXRrvbbCJthwqcBZUE3VzoRL0T/l7197tW+MKR9YeQCtZQ== - dependencies: - nanoresource "^1.3.0" - napi-macros "^2.0.0" - "@ioredis/commands@^1.1.1": version "1.2.0" resolved "https://registry.npmjs.org/@ioredis/commands/-/commands-1.2.0.tgz" @@ -622,12 +614,7 @@ minimatch@^5.0.1: dependencies: brace-expansion "^2.0.1" -minimist@^1.2.0, minimist@^1.2.3: - version "1.2.8" - resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.8.tgz#c1a464e7693302e082a075cee0c057741ac4772c" - integrity sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA== - -minimist@^1.2.6: +minimist@^1.2.0, minimist@^1.2.3, minimist@^1.2.6: version "1.2.8" resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.8.tgz#c1a464e7693302e082a075cee0c057741ac4772c" integrity sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA== @@ -682,23 +669,11 @@ mz@^2.4.0: object-assign "^4.0.1" thenify-all "^1.0.0" -nanoresource@^1.3.0: - version "1.3.0" - resolved "https://registry.yarnpkg.com/nanoresource/-/nanoresource-1.3.0.tgz#823945d9667ab3e81a8b2591ab8d734552878cd0" - integrity sha512-OI5dswqipmlYfyL3k/YMm7mbERlh4Bd1KuKdMHpeoVD1iVxqxaTMKleB4qaA2mbQZ6/zMNSxCXv9M9P/YbqTuQ== - dependencies: - inherits "^2.0.4" - napi-build-utils@^1.0.1: version "1.0.2" resolved "https://registry.yarnpkg.com/napi-build-utils/-/napi-build-utils-1.0.2.tgz#b1fddc0b2c46e380a0b7a76f984dd47c41a13806" integrity sha512-ONmRUqK7zj7DWX0D9ADe03wbwOBZxNAfF20PlGfCWQcD3+/MakShIHrMqx9YwPTfxDdF1zLeL+RGZiR9kGMLdg== -napi-macros@^2.0.0: - version "2.2.2" - resolved "https://registry.yarnpkg.com/napi-macros/-/napi-macros-2.2.2.tgz#817fef20c3e0e40a963fbf7b37d1600bd0201044" - integrity sha512-hmEVtAGYzVQpCKdbQea4skABsdXW4RUh5t5mJ2zzqowJS2OyXZTU1KhDVFhx+NlWZ4ap9mqR9TcDO3LTTttd+g== - node-abi@^3.3.0: version "3.51.0" resolved "https://registry.yarnpkg.com/node-abi/-/node-abi-3.51.0.tgz#970bf595ef5a26a271307f8a4befa02823d4e87d" diff --git a/src/apps/main/main.ts b/src/apps/main/main.ts index 7881316ee..3d0082c16 100644 --- a/src/apps/main/main.ts +++ b/src/apps/main/main.ts @@ -16,8 +16,6 @@ import './auth/handlers'; import './windows/settings'; import './windows/process-issues'; import './windows'; -import './background-processes/sync-engine'; -import '../fuse/index'; import './background-processes/process-issues'; import './device/handlers'; import './usage/handlers'; diff --git a/src/apps/main/virtual-drive.ts b/src/apps/main/virtual-drive.ts new file mode 100644 index 000000000..b37eff79d --- /dev/null +++ b/src/apps/main/virtual-drive.ts @@ -0,0 +1,7 @@ +if (process.platform === 'win32') { + import('./background-processes/sync-engine'); +} + +if (process.platform === 'linux') { + import('../fuse'); +}