From 1fdebf63a4d780f969462e40f2f6849247163265 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Thu, 29 Jan 2015 13:14:43 -0800 Subject: [PATCH] Add progress.js; calculate download percent complete value --- examples/progress.js | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 examples/progress.js diff --git a/examples/progress.js b/examples/progress.js new file mode 100644 index 0000000000..01fb22bc3b --- /dev/null +++ b/examples/progress.js @@ -0,0 +1,36 @@ +// +// progress.js +// examples +// +// Created by David Rowe on 29 Jan 2015. +// Copyright 2015 High Fidelity, Inc. +// +// This script displays a progress download indicator when downloads are in progress. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +(function () { + + var progress = 100; // % + + function updateInfo(info) { + var i; + + if (info.downloading.length + info.pending === 0) { + progress = 100; + } else { + progress = 0; + for (i = 0; i < info.downloading.length; i += 1) { + progress += info.downloading[i]; + } + progress = progress / (info.downloading.length + info.pending); + } + + print(progress.toFixed(0) + "%"); + } + + GlobalServices.downloadInfoChanged.connect(updateInfo); + GlobalServices.updateDownloadInfo(); +}());