forked from rust-lang/rustup
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrustup.js
More file actions
216 lines (188 loc) · 7 KB
/
rustup.js
File metadata and controls
216 lines (188 loc) · 7 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
// IF YOU CHANGE THIS FILE IT MUST BE CHANGED ON BOTH rust-www and rustup.rs
var platforms = ["default", "unknown", "win32", "win64", "unix"];
var platform_override = null;
var rustup_install_command = "curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh";
function detect_platform() {
"use strict";
if (platform_override !== null) {
return platforms[platform_override];
}
var os = "unknown";
if (navigator.platform == "Linux x86_64") {os = "unix";}
if (navigator.platform == "Linux i686") {os = "unix";}
if (navigator.platform == "Linux i686 on x86_64") {os = "unix";}
if (navigator.platform == "Linux aarch64") {os = "unix";}
if (navigator.platform == "Linux armv6l") {os = "unix";}
if (navigator.platform == "Linux armv7l") {os = "unix";}
if (navigator.platform == "Linux armv8l") {os = "unix";}
if (navigator.platform == "Linux ppc64") {os = "unix";}
if (navigator.platform == "Linux mips") {os = "unix";}
if (navigator.platform == "Linux mips64") {os = "unix";}
if (navigator.platform == "Mac") {os = "unix";}
if (navigator.platform == "Win32") {os = "win32";}
if (navigator.platform == "Win64" ||
navigator.userAgent.indexOf("WOW64") != -1 ||
navigator.userAgent.indexOf("Win64") != -1) { os = "win64"; }
if (navigator.platform == "FreeBSD x86_64") {os = "unix";}
if (navigator.platform == "FreeBSD amd64") {os = "unix";}
if (navigator.platform == "NetBSD x86_64") {os = "unix";}
if (navigator.platform == "NetBSD amd64") {os = "unix";}
if (navigator.platform == "SunOS i86pc") {os = "unix";}
// I wish I knew by now, but I don't. Try harder.
if (os == "unknown") {
if (navigator.appVersion.indexOf("Win")!=-1) {os = "win32";}
if (navigator.appVersion.indexOf("Mac")!=-1) {os = "unix";}
// rust-www/#692 - FreeBSD epiphany!
if (navigator.appVersion.indexOf("FreeBSD")!=-1) {os = "unix";}
}
// Firefox Quantum likes to hide platform and appVersion but oscpu works
if (navigator.oscpu) {
if (navigator.oscpu.indexOf("Win32")!=-1) {os = "win32";}
if (navigator.oscpu.indexOf("Win64")!=-1) {os = "win64";}
if (navigator.oscpu.indexOf("Mac")!=-1) {os = "unix";}
if (navigator.oscpu.indexOf("Linux")!=-1) {os = "unix";}
if (navigator.oscpu.indexOf("FreeBSD")!=-1) {os = "unix";}
if (navigator.oscpu.indexOf("NetBSD")!=-1) {os = "unix";}
if (navigator.oscpu.indexOf("SunOS")!=-1) {os = "unix";}
}
return os;
}
function vis(elem, value) {
var possible = ["block", "inline", "none"];
for (var i = 0; i < possible.length; i++) {
if (possible[i] === value) {
elem.classList.add("display-" + possible[i]);
} else {
elem.classList.remove("display-" + possible[i]);
}
}
}
function adjust_for_platform() {
"use strict";
var platform = detect_platform();
platforms.forEach(function (platform_elem) {
var platform_div = document.getElementById("platform-instructions-" + platform_elem);
vis(platform_div, "none");
if (platform == platform_elem) {
vis(platform_div, "block");
}
});
adjust_platform_specific_instrs(platform);
}
// NB: This has no effect on rustup.rs
function adjust_platform_specific_instrs(platform) {
var platform_specific = document.getElementsByClassName("platform-specific");
for (var el of platform_specific) {
var el_is_not_win = el.className.indexOf("not-win") !== -1;
var el_is_inline = el.tagName.toLowerCase() == "span";
var el_visible_style = "block";
if (el_is_inline) {
el_visible_style = "inline";
}
if (platform == "win64" || platform == "win32") {
if (el_is_not_win) {
vis(el, "none");
} else {
vis(el, el_visible_style);
}
} else {
if (el_is_not_win) {
vis(el, el_visible_style);
} else {
vis(el, "none");
}
}
}
}
function cycle_platform() {
if (platform_override == null) {
platform_override = 0;
} else {
platform_override = (platform_override + 1) % platforms.length;
}
adjust_for_platform();
}
function set_up_cycle_button() {
var cycle_button = document.getElementById("platform-button");
cycle_button.onclick = cycle_platform;
var key="test";
var idx=0;
var unlocked=false;
document.onkeypress = function(event) {
if (event.key == "n" && unlocked) {
cycle_platform();
}
if (event.key == key[idx]) {
idx += 1;
if (idx == key.length) {
vis(cycle_button, "block");
unlocked = true;
cycle_platform();
}
} else if (event.key == key[0]) {
idx = 1;
} else {
idx = 0;
}
};
}
function go_to_default_platform() {
platform_override = 0;
adjust_for_platform();
}
// NB: This has no effect on rust-lang.org/install.html
function set_up_default_platform_buttons() {
var defaults_buttons = document.getElementsByClassName('default-platform-button');
for (var i = 0; i < defaults_buttons.length; i++) {
defaults_buttons[i].onclick = go_to_default_platform;
}
}
function fill_in_bug_report_values() {
var nav_plat = document.getElementById("nav-plat");
var nav_app = document.getElementById("nav-app");
nav_plat.textContent = navigator.platform;
nav_app.textContent = navigator.appVersion;
}
function process_copy_button_click(id) {
try {
navigator.clipboard.writeText(rustup_install_command).then(() =>
document.getElementById(id).style.opacity = '1');
setTimeout(() => document.getElementById(id).style.opacity = '0', 3000);
} catch (e) {
console.log('Hit a snag when copying to clipboard: ', e);
}
}
function handle_copy_button_click(e) {
switch (e.id) {
case 'copy-button-unix':
process_copy_button_click('copy-status-message-unix');
break;
case 'copy-button-win32':
process_copy_button_click('copy-status-message-win32');
break;
case 'copy-button-win64':
process_copy_button_click('copy-status-message-win64');
break;
case 'copy-button-unknown':
process_copy_button_click('copy-status-message-unknown');
break;
case 'copy-button-default':
process_copy_button_click('copy-status-message-default');
break;
}
}
function set_up_copy_button_clicks() {
var buttons = document.querySelectorAll(".copy-button");
buttons.forEach(function (element) {
element.addEventListener('click', function() {
handle_copy_button_click(element);
});
})
}
(function () {
adjust_for_platform();
set_up_cycle_button();
set_up_default_platform_buttons();
set_up_copy_button_clicks();
fill_in_bug_report_values();
}());