Skip to content
This repository has been archived by the owner on Feb 22, 2020. It is now read-only.

Commit

Permalink
feat(nsis-compat-updater): expose download progress event
Browse files Browse the repository at this point in the history
  • Loading branch information
evshiron committed Apr 20, 2017
1 parent c3945bb commit db359ab
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
15 changes: 15 additions & 0 deletions packages/nsis-compat-updater/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ interface IVersion {
updaters: IUpdater[];
}

interface IStreamProgress {
percentage: number;
transferred: number;
length: number;
remaining: number;
eta: number;
runtime: number;
delta: number;
speed: number;
}

```

### `new NsisCompatUpdater(feed: string, version: string, arch: 'x86' | 'x64')`
Expand All @@ -48,6 +59,10 @@ interface IVersion {
const updater = new NsisCompatUpdater(feed, version, arch);
```

### `updater.onDownloadProgress.subscribe((state: IStreamProgress) => void)`

### `updater.onDownloadProgress.unsubscribe((state: IStreamProgress) => void)`

### `updater.checkForUpdates(): Promise<IVersion | null>`

Returns an instance of `IVersion` if new version is available, otherwise `null`.
Expand Down
8 changes: 5 additions & 3 deletions packages/nsis-compat-updater/src/lib/NsisCompatUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const debug = require('debug/src/browser')('nsis-compat-updater');
const got = require('got');
const progressStream = require('progress-stream');

import { Event } from './Event';

interface IInstaller {
arch: string;
path: string;
Expand Down Expand Up @@ -54,6 +56,8 @@ interface IStreamProgress {

export class NsisCompatUpdater {

public onDownloadProgress: Event<IStreamProgress> = new Event('downloadProgress');

protected versionInfo: IVersionInfo;

constructor(protected seed: string, protected currentVersion: string, protected currentArch: 'x86' | 'x64') {
Expand Down Expand Up @@ -269,9 +273,7 @@ export class NsisCompatUpdater {
time: 1000,
});

progress.on('progress', onProgress ? onProgress : (state: IStreamProgress) => {
debug('in handleProgress', 'state.speed', state.speed);
});
progress.on('progress', this.onDownloadProgress.trigger);

await new Promise((resolve, reject) => {
stream.pipe(progress)
Expand Down

0 comments on commit db359ab

Please sign in to comment.