Repository navigation
Expand file tree
/
Copy pathabout.js
More file actions
193 lines (162 loc) · 5.54 KB
/
Copy pathabout.js
File metadata and controls
193 lines (162 loc) · 5.54 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
/* -*- 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').>
this.loadHardwareInfo();
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')]();
},
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 deviceInfoPhoneNum = document.getElementById('deviceinfo-phone-num');
var deviceInfoMsisdns = document.getElementById('deviceInfo-msisdns');
var conns = navigator.mozMobileConnections;
if (!conns) {
deviceInfoPhoneNum.hidden = true;
return;
}
var multiSim = conns.length > 1;
// Only show the list item when there are valid iccinfos.
var showListItem = false;
// update msisdns
while (deviceInfoMsisdns.hasChildNodes()) {
deviceInfoMsisdns.removeChild(deviceInfoMsisdns.lastChild);
}
Array.prototype.forEach.call(conns, function(conn, index) {
var iccId = conn.iccId;
if (!iccId) {
return;
}
var iccObj = navigator.mozIccManager.getIccById(iccId);
if (!iccObj) {
return;
}
var iccInfo = iccObj.iccInfo;
if (!iccInfo) {
return;
}
showListItem = true;
// If the icc card is gsm card, the phone number is in msisdn.
// Otherwise, the phone number is in mdn.
var span = document.createElement('span');
var msisdn = iccInfo.msisdn || iccInfo.mdn;
if (msisdn) {
span.textContent = multiSim ?
'SIM ' + (index + 1) + ': ' + msisdn : msisdn;
} else {
if (multiSim) {
navigator.mozL10n.localize(span,
'unknown-phoneNumber-sim', { index: index + 1 });
} else {
navigator.mozL10n.localize(span, 'unknown-phoneNumber');
}
}
deviceInfoMsisdns.appendChild(span);
});
deviceInfoPhoneNum.hidden = !showListItem;
},
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
});
}
};
// startup
navigator.mozL10n.ready(About.init.bind(About));