-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Main Process Download Progress Tracker
- Loading branch information
1 parent
4762fe1
commit 8a8daea
Showing
8 changed files
with
161 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,21 @@ | ||
export interface DownloadProgressTracker { | ||
downloadStarted(name: string): Promise<void>; | ||
downloadUpdate(name: string, progress: number): Promise<void>; | ||
downloadFinished(name: string): Promise<void>; | ||
error(name: string): Promise<void>; | ||
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>; | ||
} |
93 changes: 93 additions & 0 deletions
93
src/context/shared/infrastructure/MainProcessDownloadProgressTracker.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters