-
Notifications
You must be signed in to change notification settings - Fork 502
/
Copy pathdownloadInfoExample.js
66 lines (52 loc) · 1.53 KB
/
downloadInfoExample.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//
// downloadInfoExample.js
// examples/example
//
// Created by David Rowe on 5 Jan 2015
// Copyright 2015 High Fidelity, Inc.
//
// Display downloads information the same as in the stats.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
var downloadInfo,
downloadInfoOverlay;
function formatInfo(info) {
var string = "Downloads: ",
i;
for (i = 0; i < info.downloading.length; i += 1) {
string += info.downloading[i].toFixed(0) + "% ";
}
string += "(" + info.pending.toFixed(0) + " pending)";
return string;
}
// Get and log the current downloads info ...
downloadInfo = GlobalServices.getDownloadInfo();
print(formatInfo(downloadInfo));
// Display and update the downloads info in an overlay ...
function setUp() {
downloadInfoOverlay = Overlays.addOverlay("text", {
x: 300,
y: 200,
width: 300,
height: 50,
color: { red: 255, green: 255, blue: 255 },
alpha: 1.0,
backgroundColor: { red: 127, green: 127, blue: 127 },
backgroundAlpha: 0.5,
topMargin: 15,
leftMargin: 20,
text: ""
});
}
function updateInfo(info) {
Overlays.editOverlay(downloadInfoOverlay, { text: formatInfo(info) });
}
function tearDown() {
Overlays.deleteOverlay(downloadInfoOverlay);
}
setUp();
GlobalServices.downloadInfoChanged.connect(updateInfo);
GlobalServices.updateDownloadInfo();
Script.scriptEnding.connect(tearDown);