Skip to content

Commit 4e78755

Browse files
author
Stefania
committed
fixed upload on chromeos
1 parent 65f2968 commit 4e78755

File tree

3 files changed

+27
-38
lines changed

3 files changed

+27
-38
lines changed

src/chrome-app-daemon.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export default class ChromeOsDaemon extends Daemon {
7070
this.serialMonitorMessages.next(message.serialData);
7171
}
7272

73-
if (message.programmerstatus) {
73+
if (message.uploadStatus) {
7474
this.handleUploadMessage(message);
7575
}
7676

@@ -254,4 +254,9 @@ export default class ChromeOsDaemon extends Daemon {
254254
this.uploading.next({ status: this.UPLOAD_ERROR, err: 'you need to be logged in on a Create site to upload by Chrome App' });
255255
}
256256
}
257+
258+
downloadTool() {
259+
// no need to download tool on chromeOS
260+
this.downloading.next({ status: this.DOWNLOAD_DONE });
261+
}
257262
}

src/daemon.js

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ export default class Daemon {
3030
this.UPLOAD_ERROR = 'UPLOAD_ERROR';
3131
this.UPLOAD_IN_PROGRESS = 'UPLOAD_IN_PROGRESS';
3232

33+
this.DOWNLOAD_DONE = 'DOWNLOAD_DONE';
34+
this.DOWNLOAD_NOPE = 'DOWNLOAD_NOPE';
35+
this.DOWNLOAD_ERROR = 'DOWNLOAD_ERROR';
36+
this.DOWNLOAD_IN_PROGRESS = 'DOWNLOAD_IN_PROGRESS';
37+
3338
this.agentInfo = {};
3439
this.agentFound = new BehaviorSubject(null);
3540
this.channelOpen = new BehaviorSubject(null);
@@ -59,6 +64,14 @@ export default class Daemon {
5964
.pipe(filter(devices => devices.serial && devices.serial.length > 0))
6065
.pipe(first())
6166
.subscribe(() => this.closeAllPorts());
67+
68+
this.downloading = new BehaviorSubject({ status: this.DOWNLOAD_NOPE });
69+
this.downloadingDone = this.downloading.pipe(filter(download => download.status === this.DOWNLOAD_DONE))
70+
.pipe(first())
71+
.pipe(takeUntil(this.downloading.pipe(filter(download => download.status === this.DOWNLOAD_ERROR))));
72+
this.downloadingError = this.downloading.pipe(filter(download => download.status === this.DOWNLOAD_ERROR))
73+
.pipe(first())
74+
.pipe(takeUntil(this.downloadingDone));
6275
}
6376

6477
notifyUploadError(err) {
@@ -96,22 +109,6 @@ export default class Daemon {
96109
return a.every((item, index) => (b[index].Name === item.Name && b[index].IsOpen === item.IsOpen));
97110
}
98111

99-
/**
100-
* Download tool - not supported in Chrome app
101-
* @param {string} toolName
102-
* @param {string} toolVersion
103-
* @param {string} packageName
104-
* @param {string} replacementStrategy
105-
*/
106-
downloadTool(toolName, toolVersion, packageName, replacementStrategy = 'keep') {
107-
if (typeof this.downloadToolCommand === 'function') {
108-
this.downloadToolCommand(toolName, toolVersion, packageName, replacementStrategy);
109-
}
110-
else {
111-
throw new Error('Download Tool not supported on Chrome OS');
112-
}
113-
}
114-
115112
/**
116113
* Interrupt upload - not supported in Chrome app
117114
*/

src/socket-daemon.js

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import io from 'socket.io-client';
2222
import semVerCompare from 'semver-compare';
2323
import { detect } from 'detect-browser';
2424

25-
import { BehaviorSubject, timer } from 'rxjs';
25+
import { timer } from 'rxjs';
2626
import { filter, takeUntil, first } from 'rxjs/operators';
2727

2828
import Daemon from './daemon';
@@ -52,26 +52,13 @@ if (browser.name !== 'chrome' && browser.name !== 'firefox') {
5252
orderedPluginAddresses = [LOOPBACK_HOSTNAME, LOOPBACK_ADDRESS];
5353
}
5454

55-
const DOWNLOAD_NOPE = 'DOWNLOAD_NOPE';
56-
const DOWNLOAD_DONE = 'DOWNLOAD_DONE';
57-
const DOWNLOAD_ERROR = 'DOWNLOAD_ERROR';
58-
const DOWNLOAD_IN_PROGRESS = 'DOWNLOAD_IN_PROGRESS';
59-
6055
export default class SocketDaemon extends Daemon {
6156
constructor() {
6257
super();
6358
this.selectedProtocol = PROTOCOL.HTTP;
6459
this.socket = null;
6560
this.pluginURL = null;
6661

67-
this.downloading = new BehaviorSubject({ status: DOWNLOAD_NOPE });
68-
this.downloadingDone = this.downloading.pipe(filter(download => download.status === DOWNLOAD_DONE))
69-
.pipe(first())
70-
.pipe(takeUntil(this.downloading.pipe(filter(download => download.status === this.DOWNLOAD_ERROR))));
71-
this.downloadingError = this.downloading.pipe(filter(download => download.status === DOWNLOAD_ERROR))
72-
.pipe(first())
73-
.pipe(takeUntil(this.downloadingDone));
74-
7562
this.openChannel(() => this.socket.emit('command', 'list'));
7663

7764
this.agentFound
@@ -382,21 +369,21 @@ export default class SocketDaemon extends Daemon {
382369
}
383370

384371
handleDownloadMessage(message) {
385-
if (this.downloading.getValue().status !== DOWNLOAD_IN_PROGRESS) {
372+
if (this.downloading.getValue().status !== this.DOWNLOAD_IN_PROGRESS) {
386373
return;
387374
}
388375
switch (message.DownloadStatus) {
389376
case 'Pending':
390-
this.downloading.next({ status: DOWNLOAD_IN_PROGRESS, msg: message.Msg });
377+
this.downloading.next({ status: this.DOWNLOAD_IN_PROGRESS, msg: message.Msg });
391378
break;
392379
case 'Success':
393-
this.downloading.next({ status: DOWNLOAD_DONE, msg: message.Msg });
380+
this.downloading.next({ status: this.DOWNLOAD_DONE, msg: message.Msg });
394381
break;
395382
case 'Error':
396-
this.downloading.next({ status: DOWNLOAD_ERROR, err: message.Msg });
383+
this.downloading.next({ status: this.DOWNLOAD_ERROR, err: message.Msg });
397384
break;
398385
default:
399-
this.downloading.next({ status: DOWNLOAD_IN_PROGRESS, msg: message.Msg });
386+
this.downloading.next({ status: this.DOWNLOAD_IN_PROGRESS, msg: message.Msg });
400387
}
401388
}
402389

@@ -486,8 +473,8 @@ export default class SocketDaemon extends Daemon {
486473
* @param {string} packageName
487474
* @param {string} replacementStrategy
488475
*/
489-
downloadToolCommand(toolName, toolVersion, packageName, replacementStrategy) {
490-
this.downloading.next({ status: DOWNLOAD_IN_PROGRESS });
476+
downloadTool(toolName, toolVersion, packageName, replacementStrategy) {
477+
this.downloading.next({ status: this.DOWNLOAD_IN_PROGRESS });
491478
this.socket.emit('command', `downloadtool ${toolName} ${toolVersion} ${packageName} ${replacementStrategy}`);
492479
}
493480

0 commit comments

Comments
 (0)