Skip to content

Commit

Permalink
Merge branch 'linux' into merge/linux
Browse files Browse the repository at this point in the history
  • Loading branch information
JoanVicens committed Feb 1, 2024
2 parents 5e1dbe6 + 8a8daea commit d1269e5
Show file tree
Hide file tree
Showing 24 changed files with 553 additions and 73 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@
"detect-port": "^1.3.0",
"dotenv": "^10.0.0",
"dotenv-webpack": "^7.0.3",
"electron": "^25.8.4",
"electron": "^19.1.9",
"electron-builder": "^23.6.0",
"electron-devtools-installer": "^3.2.0",
"electron-notarize": "^1.1.1",
Expand Down Expand Up @@ -229,6 +229,7 @@
"jsonwebtoken": "^8.5.1",
"lint-staged": "^12.1.4",
"mini-css-extract-plugin": "^2.4.5",
"mockdate": "^3.0.5",
"ms": "^2.1.3",
"node-loader": "^2.0.0",
"opencollective-postinstall": "^2.0.3",
Expand Down
1 change: 1 addition & 0 deletions release/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"postinstall": "npm run electron-rebuild --sequential && 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"
Expand Down
20 changes: 20 additions & 0 deletions release/app/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@
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"
Expand Down Expand Up @@ -664,11 +672,23 @@ 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"
Expand Down
9 changes: 0 additions & 9 deletions src/apps/fuse/callbacks/OpenCallback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,6 @@ export class OpenCallback extends FuseCallback<number> {
);
}

const alreadyDownloaded = await this.container.localContentChecker.run(
file
);

if (alreadyDownloaded) {
Logger.debug(`"${file.nameWithExtension}" contents are already in local`);
return this.right(file.id);
}

try {
await this.container.downloadContentsToPlainFile.run(file);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { MoveOfflineContentsOnContentsUploaded } from '../../../../../context/vi
import { LocalContentsMover } from '../../../../../context/virtual-drive/contents/application/LocalContentsMover';
import { AllLocalContentsDeleter } from '../../../../../context/virtual-drive/contents/application/AllLocalContentsDeleter';
import { MainProcessUploadProgressTracker } from '../../../../../context/shared/infrastructure/MainProcessUploadProgressTracker';
import { MainProcessDownloadProgressTracker } from '../../../../../context/shared/infrastructure/MainProcessDownloadProgressTracker';

export async function buildContentsContainer(
sharedContainer: SharedContainer
Expand Down Expand Up @@ -44,10 +45,13 @@ export async function buildContentsContainer(
'downloaded'
);

const tracker = new MainProcessDownloadProgressTracker();

const downloadContentsToPlainFile = new DownloadContentsToPlainFile(
contentsManagerFactory,
localFS,
eventBus
eventBus,
tracker
);

const localContentChecker = new LocalContentChecker(localFS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { FSLocalFileSystem } from '../../../../context/virtual-drive/contents/in
import { DependencyInjectionEventBus } from '../common/eventBus';
import { FuseAppDataLocalFileContentsDirectoryProvider } from '../../../../context/virtual-drive/shared/infrastructure/LocalFileContentsDirectoryProviders/FuseAppDataLocalFileContentsDirectoryProvider';
import { LocalContentsDeleter } from '../../../../context/virtual-drive/contents/application/LocalContentsDeleter';
import { MainProcessDownloadProgressTracker } from '../../../../context/shared/infrastructure/MainProcessDownloadProgressTracker';

export async function buildContentsContainer(): Promise<ContentsContainer> {
const user = DependencyInjectionUserProvider.get();
Expand All @@ -32,10 +33,13 @@ export async function buildContentsContainer(): Promise<ContentsContainer> {
'downloaded'
);

const tracker = new MainProcessDownloadProgressTracker();

const downloadContentsToPlainFile = new DownloadContentsToPlainFile(
contentsManagerFactory,
localFS,
eventBus
eventBus,
tracker
);

const localContentsDeleter = new LocalContentsDeleter(localFS);
Expand Down
21 changes: 21 additions & 0 deletions src/context/shared/domain/DownloadProgressTracker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export interface DownloadProgressTracker {
downloadStarted(name: string, extension: string, size: number): Promise<void>;
downloadUpdate(
name: string,
extension: string,
size: number,
progress: {
elapsedTime: number;
percentage: number;
}
): Promise<void>;
downloadFinished(
name: string,
extension: string,
size: number,
progress: {
elapsedTime: number;
}
): Promise<void>;
error(name: string, extension: string): Promise<void>;
}
19 changes: 19 additions & 0 deletions src/context/shared/domain/value-objects/DateValueObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,25 @@ export class DateValueObject extends ValueObject<Date> {
return new DateValueObject(date);
}

isPrevious(than: Date): boolean {
return this.value < than;
}

isAfter(than: Date): boolean {
return this.value > than;
}

same(other: Date): boolean {
return this.value.getTime() === other.getTime();
}

equals(other: DateValueObject): boolean {
return (
other.constructor.name === this.constructor.name &&
other.value.getTime() === this.value.getTime()
);
}

toISOString(): string {
return this.value.toISOString();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import { trackError, trackEvent } from '../../../apps/main/analytics/service';
import { setTrayStatus } from '../../../apps/main/tray/tray';
import { broadcastToWindows } from '../../../apps/main/windows';
import { DownloadProgressTracker } from '../domain/DownloadProgressTracker';
import { SyncMessenger } from '../domain/SyncMessenger';

export class MainProcessDownloadProgressTracker
extends SyncMessenger
implements DownloadProgressTracker
{
async downloadStarted(
name: string,
extension: string,
size: number
): Promise<void> {
setTrayStatus('SYNCING');

trackEvent('Upload Started', {
file_name: name,
file_extension: extension,
file_size: size,
elapsedTimeMs: 0,
});

broadcastToWindows('sync-info-update', {
action: 'DOWNLOADING',
name: this.nameWithExtension(name, extension),
progress: 0,
});
}

async downloadUpdate(
name: string,
extension: string,
size: number,
progress: { elapsedTime: number; percentage: number }
): Promise<void> {
trackEvent('Upload Started', {
file_name: name,
file_extension: extension,
file_size: size,
elapsedTimeMs: progress.elapsedTime,
});

broadcastToWindows('sync-info-update', {
action: 'DOWNLOADING',
name: this.nameWithExtension(name, extension),
progress: progress.percentage,
});
}

async downloadFinished(
name: string,
extension: string,
size: number,
progress: {
elapsedTime: number;
}
): Promise<void> {
const nameWithExtension = this.nameWithExtension(name, extension);

setTrayStatus('IDLE');

trackEvent('Upload Completed', {
file_name: name,
file_extension: extension,
file_size: size,
elapsedTimeMs: progress.elapsedTime,
});

broadcastToWindows('sync-info-update', {
action: 'UPLOADED',
name: nameWithExtension,
});
}

async error(name: string, extension: string): Promise<void> {
const nameWithExtension = this.nameWithExtension(name, extension);

// TODO: finish this
trackError('Upload Error', new Error(), {
itemType: 'File',
root: '',
from: name,
action: 'Upload',
});

broadcastToWindows('sync-info-update', {
action: 'DOWNLOAD_ERROR',
name: nameWithExtension,
});
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { broadcastToWindows } from '../../../../apps/main/windows';
import { DownloadProgressTracker } from '../../../shared/domain/DownloadProgressTracker';
import { File } from '../../files/domain/File';
import { EventBus } from '../../shared/domain/EventBus';
import { ContentsId } from '../domain/ContentsId';
import { ContentsManagersFactory } from '../domain/ContentsManagersFactory';
import { LocalFileContents } from '../domain/LocalFileContents';
import { LocalFileSystem } from '../domain/LocalFileSystem';
Expand All @@ -10,43 +11,45 @@ import Logger from 'electron-log';
export class DownloadContentsToPlainFile {
constructor(
private readonly managerFactory: ContentsManagersFactory,
private readonly localWriter: LocalFileSystem,
private readonly eventBus: EventBus
private readonly local: LocalFileSystem,
private readonly eventBus: EventBus,
private readonly tracker: DownloadProgressTracker
) {}

private async registerEvents(downloader: ContentFileDownloader, file: File) {
downloader.on('start', () => {
broadcastToWindows('sync-info-update', {
action: 'DOWNLOADING',
name: file.nameWithExtension,
progress: 0,
});
this.tracker.downloadStarted(file.name, file.type, file.size);
});

downloader.on('progress', (progress: number) => {
broadcastToWindows('sync-info-update', {
action: 'DOWNLOADING',
name: file.nameWithExtension,
progress: progress,
downloader.on('progress', (progress: number, elapsedTime: number) => {
this.tracker.downloadUpdate(file.name, file.type, file.size, {
elapsedTime,
percentage: progress,
});
});

downloader.on('error', () => {
broadcastToWindows('sync-info-update', {
action: 'DOWNLOAD_ERROR',
name: file.nameWithExtension,
});
this.tracker.error(file.name, file.type);
});

downloader.on('finish', () => {
broadcastToWindows('sync-info-update', {
action: 'DOWNLOADED',
name: file.nameWithExtension,
downloader.on('finish', (elapsedTime: number) => {
this.tracker.downloadFinished(file.name, file.type, file.size, {
elapsedTime,
});
});
}

async run(file: File): Promise<string> {
async run(file: File): Promise<void> {
const contentsId = new ContentsId(file.contentsId);

const metadata = await this.local.metadata(contentsId);

if (metadata) {
if (metadata.isUpToDate(file.updatedAt)) {
return;
}
}

Logger.debug(`downloading "${file.nameWithExtension}"`);

const downloader = this.managerFactory.downloader();
Expand All @@ -60,11 +63,9 @@ export class DownloadContentsToPlainFile {
downloader.elapsedTime()
);

const write = await this.localWriter.write(localContents, file.contentsId);
await this.local.write(localContents, file.contentsId);

const events = localContents.pullDomainEvents();
await this.eventBus.publish(events);

return write;
}
}
30 changes: 30 additions & 0 deletions src/context/virtual-drive/contents/domain/ContentsMetadata.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { AggregateRoot } from '../../../shared/domain/AggregateRoot';
import { DateValueObject } from '../../../shared/domain/value-objects/DateValueObject';

type ContentsMetadataAttributes = {
modificationDate: Date;
};

export class ContentsMetadata extends AggregateRoot {
private constructor(readonly modificationDate: DateValueObject) {
super();
}

static from(attributes: ContentsMetadataAttributes): ContentsMetadata {
return new ContentsMetadata(
new DateValueObject(attributes.modificationDate)
);
}

attributes(): ContentsMetadataAttributes {
return {
modificationDate: this.modificationDate.value,
};
}

isUpToDate(date: Date): boolean {
return (
this.modificationDate.same(date) || this.modificationDate.isAfter(date)
);
}
}
Loading

0 comments on commit d1269e5

Please sign in to comment.