From fa258a84ccd90e798e75926ab3c0b0b0a2d59edf Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Mon, 16 Mar 2015 11:45:17 -0400 Subject: [PATCH] Show a spinner if no progress state in os download command --- build/actions/os.js | 16 +++++++++++++--- lib/actions/os.coffee | 11 +++++++++-- package.json | 4 ++-- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/build/actions/os.js b/build/actions/os.js index 3413544f..e04bb112 100644 --- a/build/actions/os.js +++ b/build/actions/os.js @@ -66,11 +66,21 @@ }, function(callback) { return mkdirp(path.dirname(options.output), _.unary(callback)); }, function(callback) { - var bar; + var bar, spinner; console.info("Destination file: " + options.output + "\n"); bar = new visuals.widgets.Progress('Downloading Device OS'); - return resin.models.os.download(osParams, options.output, callback, function(state) { - return bar.update(state); + spinner = new visuals.widgets.Spinner('Downloading Device OS (size unknown)'); + return resin.models.os.download(osParams, options.output, function(error) { + spinner.stop(); + if (error != null) { + return callback(error); + } + }, function(state) { + if (state != null) { + return bar.update(state); + } else { + return spinner.start(); + } }); } ], function(error) { diff --git a/lib/actions/os.coffee b/lib/actions/os.coffee index 4c3b7f5c..b36fc2d0 100644 --- a/lib/actions/os.coffee +++ b/lib/actions/os.coffee @@ -76,9 +76,16 @@ exports.download = console.info("Destination file: #{options.output}\n") bar = new visuals.widgets.Progress('Downloading Device OS') + spinner = new visuals.widgets.Spinner('Downloading Device OS (size unknown)') - resin.models.os.download osParams, options.output, callback, (state) -> - bar.update(state) + resin.models.os.download osParams, options.output, (error) -> + spinner.stop() + return callback(error) if error? + , (state) -> + if state? + bar.update(state) + else + spinner.start() ], (error) -> return done(error) if error? diff --git a/package.json b/package.json index b21e3a98..ef57639a 100644 --- a/package.json +++ b/package.json @@ -61,8 +61,8 @@ "npm": "^2.6.1", "open": "0.0.5", "progress-stream": "^0.5.0", - "resin-cli-visuals": "^0.0.8", - "resin-sdk": "^0.0.2", + "resin-cli-visuals": "^0.1.0", + "resin-sdk": "^0.0.4", "resin-vcs": "^1.0.0", "underscore.string": "~2.4.0", "update-notifier": "^0.3.1"