This repository has been archived by the owner on Nov 3, 2021. It is now read-only.
/
root.js
109 lines (101 loc) · 3.32 KB
/
root.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
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
/* global TelephonySettingHelper */
/**
* The module loads scripts used by the root panel. In the future these scripts
* must be converted to AMD modules. Implementation details please refer to
* {@link Root}.
*
* @module root/root
*/
define(function(require) {
'use strict';
var LazyLoader = require('shared/lazy_loader');
/**
* @alias module:root/root
* @class Root
* @requires module:shared/lazy_loader
* @returns {Root}
*/
function Root() {}
Root.prototype = {
_panel: null,
_loadScripts: function root_loadScripts() {
/**
* Enable or disable the menu items related to the ICC card
* relying on the card and radio state.
*/
LazyLoader.load([
'js/firefox_accounts/menu_loader.js',
'js/dsds_settings.js',
'js/telephony_settings.js',
'js/telephony_items_handler.js'
], function() {
TelephonySettingHelper
.init()
.then(function telephonySettingInitDone() {
window.dispatchEvent(new CustomEvent('telephony-settings-loaded'));
});
});
},
/**
* Update the sim related items based on mozMobileConnections.
*/
_showSimItems: function root_showSimItems(panel) {
var mozMobileConnections = navigator.mozMobileConnections;
if (mozMobileConnections) {
if (mozMobileConnections.length === 1) { // single sim
var duelSimItem =
this._panel.querySelector('#simCardManager-settings');
duelSimItem.hidden = true;
} else { // DSDS
var simItem = this._panel.querySelector('#simSecurity-settings');
simItem.hidden = true;
}
} else {
// hide telephony panels
var elements = ['#call-settings',
'#data-connectivity',
'#messaging-settings',
'#simSecurity-settings',
'#simCardManager-settings'];
elements.forEach(el => {
this._panel.querySelector(el).hidden = true;
});
}
},
/**
* Update the developer menu item based on the preference.
*/
_showDeveloperMenuItem: function root_showDeveloperMenuItem() {
var developerItem = this._panel.querySelector(
'[data-show-name="developer.menu.enabled"]');
if (developerItem && navigator.mozSettings) {
return navigator.mozSettings.createLock()
.get('developer.menu.enabled').then(
function(result) {
developerItem.hidden = !result['developer.menu.enabled'];
}, function(error) {
console.error(error);
});
} else {
return Promise.resolve();
}
},
// To delay the show/hide in root panel will cause extra screen reflow,
// it can be checked by Toggle on Developer > Flash Repainted Area.
init: function root_init(panel) {
this._panel = panel;
// Load the necessary scripts after the UI update
setTimeout(this._loadScripts);
// Show NFC panel when supported
var nfcItem = panel.querySelector('.nfc-settings');
nfcItem.hidden = !navigator.mozNfc;
// Show proper SIM panel
this._showSimItems();
// Show developer panel when necessary
this._showDeveloperMenuItem();
}
};
return function ctor_root() {
return new Root();
};
});