added FileReceiver.reset

This commit is contained in:
Danny Coates 2018-02-04 18:30:33 -08:00
parent b08f40aaa3
commit fde4d311e3
No known key found for this signature in database
GPG Key ID: 4C442633C62E00CB
2 changed files with 11 additions and 6 deletions

View File

@ -173,6 +173,7 @@ export default function(state, emitter) {
await fadeOut('download-progress'); await fadeOut('download-progress');
saveFile(f); saveFile(f);
state.storage.totalDownloads += 1; state.storage.totalDownloads += 1;
state.transfer.reset();
metrics.completedDownload({ size, time, speed }); metrics.completedDownload({ size, time, speed });
emitter.emit('pushState', '/completed'); emitter.emit('pushState', '/completed');
} catch (err) { } catch (err) {
@ -181,6 +182,7 @@ export default function(state, emitter) {
return render(); return render();
} }
console.error(err); console.error(err);
state.transfer = null;
const location = err.message === 'notfound' ? '/404' : '/error'; const location = err.message === 'notfound' ? '/404' : '/error';
if (location === '/error') { if (location === '/error') {
state.raven.captureException(err); state.raven.captureException(err);
@ -188,7 +190,6 @@ export default function(state, emitter) {
} }
emitter.emit('pushState', location); emitter.emit('pushState', location);
} finally { } finally {
state.transfer = null;
openLinksInNewTab(links, false); openLinksInNewTab(links, false);
} }
}); });

View File

@ -11,11 +11,7 @@ export default class FileReceiver extends Nanobus {
this.keychain.setPassword(fileInfo.password, fileInfo.url); this.keychain.setPassword(fileInfo.password, fileInfo.url);
} }
this.fileInfo = fileInfo; this.fileInfo = fileInfo;
this.fileDownload = null; this.reset();
this.msg = 'fileSizeProgress';
this.state = 'initialized';
this.progress = [0, 1];
this.cancelled = false;
} }
get progressRatio() { get progressRatio() {
@ -36,6 +32,14 @@ export default class FileReceiver extends Nanobus {
} }
} }
reset() {
this.fileDownload = null;
this.msg = 'fileSizeProgress';
this.state = 'initialized';
this.progress = [0, 1];
this.cancelled = false;
}
async getMetadata() { async getMetadata() {
const meta = await metadata(this.fileInfo.id, this.keychain); const meta = await metadata(this.fileInfo.id, this.keychain);
if (meta) { if (meta) {