Repository navigation
Expand file tree
/
Copy pathabout.js
More file actions
251 lines (212 loc) · 7.47 KB
/
Copy pathabout.js
File metadata and controls
251 lines (212 loc) · 7.47 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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
/* -*- Mode: js; js-indent-level: 2; indent-tabs-mode: nil -*- */
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
'use strict';
var About = {
init: function about_init() {
document.getElementById('check-update-now').>
document.getElementById('ftuLauncher').>
this.loadHardwareInfo();
this.loadGaiaCommit();
this.loadLastUpdated();
this.networkStatus();
},
networkStatus: function about_networkStatus() {
var button = document.getElementById('check-update-now');
var status = {
offline: function() { button.disabled = true; },
online: function() { button.disabled = false; }
};
window.addEventListener('offline', status.offline);
window.addEventListener('online', status.online);
status[(window.navigator.onLine ? 'online' : 'offline')]();
},
loadGaiaCommit: function about_loadGaiaCommit() {
var GAIA_COMMIT = 'resources/gaia_commit.txt';
var dispDate = document.getElementById('gaia-commit-date');
var dispHash = document.getElementById('gaia-commit-hash');
if (dispHash.textContent)
return; // `gaia-commit.txt' has already been loaded
function dateToUTC(d) {
var arr = [];
[
d.getUTCFullYear(), (d.getUTCMonth() + 1), d.getUTCDate(),
d.getUTCHours(), d.getUTCMinutes(), d.getUTCSeconds()
].forEach(function(n) {
arr.push((n >= 10) ? n : '0' + n);
});
return arr.splice(0, 3).join('-') + ' ' + arr.join(':');
}
var req = new XMLHttpRequest();
req. {
if (req.readyState === 4) {
if (req.status === 0 || req.status === 200) {
var data = req.responseText.split('\n');
/**
* XXX it would be great to pop a link to the github page showing the
* commit, but there doesn't seem to be any way to tell the browser
* to do it.
*/
var d = new Date(parseInt(data[1] + '000', 10));
dispDate.textContent = dateToUTC(d);
dispHash.textContent = data[0];
} else {
console.error('Failed to fetch gaia commit: ', req.statusText);
}
}
}).bind(this);
req.open('GET', GAIA_COMMIT, true); // async
req.responseType = 'text';
req.send();
},
loadLastUpdated: function about_loadLastUpdated() {
var settings = Settings.mozSettings;
if (!settings)
return;
var lastUpdateDate = document.getElementById('last-update-date');
var lock = settings.createLock();
var key = 'deviceinfo.last_updated';
var request = lock.get(key);
request. {
var lastUpdated = request.result[key];
if (!lastUpdated) {
return;
}
var f = new navigator.mozL10n.DateTimeFormat();
var _ = navigator.mozL10n.get;
lastUpdateDate.textContent =
f.localeFormat(new Date(lastUpdated), _('shortDateTimeFormat'));
};
},
loadHardwareInfo: function about_loadHardwareInfo() {
var mobileConnection = getMobileConnection();
if (!mobileConnection)
return;
if (!IccHelper.enabled)
return;
var deviceInfoIccid = document.getElementById('deviceInfo-iccid');
var deviceInfoMsisdn = document.getElementById('deviceInfo-msisdn');
var deviceInfoImei = document.getElementById('deviceInfo-imei');
var info = IccHelper.iccInfo;
if (!navigator.mozTelephony) {
deviceInfoIccid.parentNode.hidden = true;
deviceInfoMsisdn.parentNode.hidden = true;
deviceInfoImei.parentNode.hidden = true;
} else {
deviceInfoIccid.textContent = info.iccid;
deviceInfoMsisdn.textContent = info.msisdn ||
navigator.mozL10n.get('unknown-phoneNumber');
var req = mobileConnection.sendMMI('*#06#');
req. getIMEI() {
if (req.result && req.result.statusMessage) {
deviceInfoImei.textContent = req.result.statusMessage;
}
};
}
},
checkForUpdates: function about_checkForUpdates() {
var settings = Settings.mozSettings;
if (!settings)
return;
var _ = navigator.mozL10n.get;
var updateStatus = document.getElementById('update-status'),
systemStatus = updateStatus.querySelector('.system-update-status');
function onUpdateStatus(setting, event) {
var value = event.settingValue;
checkStatus[setting].value = value;
/**
* possible return values:
*
* - for system updates:
* - no-updates
* - already-latest-version
* - check-complete
* - retry-when-online
* - check-error-$nsresult
* - check-error-http-$code
*
* - for apps updates:
* - check-complete
*
* use
* http://mxr.mozilla.org/mozilla-central/ident?i=setUpdateStatus&tree=mozilla-central&filter=&strict=1
* to check if this is still current
*/
if (value !== 'check-complete') {
systemStatus.textContent = _(value) || _('check-error');
console.error('Error checking for system update:', value);
}
checkIfStatusComplete();
settings.removeObserver(setting, checkStatus[setting].cb);
checkStatus[setting].cb = null;
}
function checkIfStatusComplete() {
var hasAllCheckComplete =
Object.keys(checkStatus).every(function(setting) {
return checkStatus[setting].value === 'check-complete';
});
var hasAllResponses =
Object.keys(checkStatus).every(function(setting) {
return !!checkStatus[setting].value;
});
if (hasAllCheckComplete) {
updateStatus.classList.remove('visible');
systemStatus.textContent = '';
}
if (hasAllResponses) {
updateStatus.classList.remove('checking');
}
}
/* Firefox currently doesn't implement adding 2 classes in one call */
/* see Bug 814014 */
updateStatus.classList.add('checking');
updateStatus.classList.add('visible');
/* remove whatever was there before */
systemStatus.textContent = '';
var checkStatus = {
'gecko.updateStatus': {},
'apps.updateStatus': {}
};
for (var setting in checkStatus) {
checkStatus[setting].cb = onUpdateStatus.bind(null, setting);
settings.addObserver(setting, checkStatus[setting].cb);
}
var lock = settings.createLock();
lock.set({
'gaia.system.checkForUpdates': true
});
},
launchFTU: function about_launchFTU() {
var settings = Settings.mozSettings;
if (!settings)
return;
var key = 'ftu.manifestURL';
var req = settings.createLock().get(key);
req. ftuManifest() {
var ftuManifestURL = req.result[key];
// fallback if no settings present
if (!ftuManifestURL) {
ftuManifestURL = document.location.protocol +
'//communications.gaiamobile.org' +
(location.port ? (':' + location.port) : '') +
'/manifest.webapp';
}
var ftuApp = null;
navigator.mozApps.mgmt.getAll(). gotApps(evt) {
var apps = evt.target.result;
for (var i = 0; i < apps.length && ftuApp == null; i++) {
var app = apps[i];
if (app.manifestURL == ftuManifestURL) {
ftuApp = app;
}
}
if (ftuApp) {
ftuApp.launch('ftu');
} else {
alert(navigator.mozL10n.get('no-ftu'));
}
};
};
}
};
// startup
navigator.mozL10n.ready(About.init.bind(About));
You can’t perform that action at this time.