Repository navigation
Expand file tree
/
Copy pathabout.js
More file actions
160 lines (133 loc) · 4.64 KB
/
Copy pathabout.js
File metadata and controls
160 lines (133 loc) · 4.64 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
/* -*- 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 mobileConnection = getMobileConnection();
if (!mobileConnection) {
document.getElementById('deviceinfo-phone-num').hidden = true;
return;
}
if (!IccHelper)
return;
var deviceInfoMsisdn = document.getElementById('deviceInfo-msisdn');
var info = IccHelper.iccInfo;
if (!navigator.mozTelephony || !info) {
deviceInfoMsisdn.parentNode.hidden = true;
} else {
// If the icc card is gsm card, the phone number is in msisdn.
// Otherwise, the phone number is in mdn.
deviceInfoMsisdn.textContent = info.msisdn || info.mdn ||
navigator.mozL10n.get('unknown-phoneNumber');
}
},
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));
You can’t perform that action at this time.