mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 04:06:41 +02:00
Add progress.js; calculate download percent complete value
This commit is contained in:
parent
b5e62922a2
commit
1fdebf63a4
1 changed files with 36 additions and 0 deletions
36
examples/progress.js
Normal file
36
examples/progress.js
Normal file
|
@ -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();
|
||||||
|
}());
|
Loading…
Reference in a new issue