├── .gitignore ├── LICENSE.md ├── Makefile ├── README.md ├── gulpfile.js ├── icons └── icon.png ├── index.js ├── manifest.json ├── package.json ├── package.zip └── styles.css /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | 5 | # Runtime data 6 | pids 7 | *.pid 8 | *.seed 9 | 10 | # Directory for instrumented libs generated by jscoverage/JSCover 11 | lib-cov 12 | 13 | # Coverage directory used by tools like istanbul 14 | coverage 15 | 16 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 17 | .grunt 18 | 19 | # node-waf configuration 20 | .lock-wscript 21 | 22 | # Compiled binary addons (http://nodejs.org/api/addons.html) 23 | build/Release 24 | 25 | # Dependency directory 26 | # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git 27 | node_modules 28 | 29 | # editorconfig 30 | .editorconfig 31 | 32 | # linter 33 | .eslintrc 34 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Mozilla Public License, version 2.0 2 | 3 | 1. Definitions 4 | 5 | 1.1. "Contributor" 6 | 7 | means each individual or legal entity that creates, contributes to the 8 | creation of, or owns Covered Software. 9 | 10 | 1.2. "Contributor Version" 11 | 12 | means the combination of the Contributions of others (if any) used by a 13 | Contributor and that particular Contributor's Contribution. 14 | 15 | 1.3. "Contribution" 16 | 17 | means Covered Software of a particular Contributor. 18 | 19 | 1.4. "Covered Software" 20 | 21 | means Source Code Form to which the initial Contributor has attached the 22 | notice in Exhibit A, the Executable Form of such Source Code Form, and 23 | Modifications of such Source Code Form, in each case including portions 24 | thereof. 25 | 26 | 1.5. "Incompatible With Secondary Licenses" 27 | means 28 | 29 | a. that the initial Contributor has attached the notice described in 30 | Exhibit B to the Covered Software; or 31 | 32 | b. that the Covered Software was made available under the terms of 33 | version 1.1 or earlier of the License, but not also under the terms of 34 | a Secondary License. 35 | 36 | 1.6. "Executable Form" 37 | 38 | means any form of the work other than Source Code Form. 39 | 40 | 1.7. "Larger Work" 41 | 42 | means a work that combines Covered Software with other material, in a 43 | separate file or files, that is not Covered Software. 44 | 45 | 1.8. "License" 46 | 47 | means this document. 48 | 49 | 1.9. "Licensable" 50 | 51 | means having the right to grant, to the maximum extent possible, whether 52 | at the time of the initial grant or subsequently, any and all of the 53 | rights conveyed by this License. 54 | 55 | 1.10. "Modifications" 56 | 57 | means any of the following: 58 | 59 | a. any file in Source Code Form that results from an addition to, 60 | deletion from, or modification of the contents of Covered Software; or 61 | 62 | b. any new file in Source Code Form that contains any Covered Software. 63 | 64 | 1.11. "Patent Claims" of a Contributor 65 | 66 | means any patent claim(s), including without limitation, method, 67 | process, and apparatus claims, in any patent Licensable by such 68 | Contributor that would be infringed, but for the grant of the License, 69 | by the making, using, selling, offering for sale, having made, import, 70 | or transfer of either its Contributions or its Contributor Version. 71 | 72 | 1.12. "Secondary License" 73 | 74 | means either the GNU General Public License, Version 2.0, the GNU Lesser 75 | General Public License, Version 2.1, the GNU Affero General Public 76 | License, Version 3.0, or any later versions of those licenses. 77 | 78 | 1.13. "Source Code Form" 79 | 80 | means the form of the work preferred for making modifications. 81 | 82 | 1.14. "You" (or "Your") 83 | 84 | means an individual or a legal entity exercising rights under this 85 | License. For legal entities, "You" includes any entity that controls, is 86 | controlled by, or is under common control with You. For purposes of this 87 | definition, "control" means (a) the power, direct or indirect, to cause 88 | the direction or management of such entity, whether by contract or 89 | otherwise, or (b) ownership of more than fifty percent (50%) of the 90 | outstanding shares or beneficial ownership of such entity. 91 | 92 | 93 | 2. License Grants and Conditions 94 | 95 | 2.1. Grants 96 | 97 | Each Contributor hereby grants You a world-wide, royalty-free, 98 | non-exclusive license: 99 | 100 | a. under intellectual property rights (other than patent or trademark) 101 | Licensable by such Contributor to use, reproduce, make available, 102 | modify, display, perform, distribute, and otherwise exploit its 103 | Contributions, either on an unmodified basis, with Modifications, or 104 | as part of a Larger Work; and 105 | 106 | b. under Patent Claims of such Contributor to make, use, sell, offer for 107 | sale, have made, import, and otherwise transfer either its 108 | Contributions or its Contributor Version. 109 | 110 | 2.2. Effective Date 111 | 112 | The licenses granted in Section 2.1 with respect to any Contribution 113 | become effective for each Contribution on the date the Contributor first 114 | distributes such Contribution. 115 | 116 | 2.3. Limitations on Grant Scope 117 | 118 | The licenses granted in this Section 2 are the only rights granted under 119 | this License. No additional rights or licenses will be implied from the 120 | distribution or licensing of Covered Software under this License. 121 | Notwithstanding Section 2.1(b) above, no patent license is granted by a 122 | Contributor: 123 | 124 | a. for any code that a Contributor has removed from Covered Software; or 125 | 126 | b. for infringements caused by: (i) Your and any other third party's 127 | modifications of Covered Software, or (ii) the combination of its 128 | Contributions with other software (except as part of its Contributor 129 | Version); or 130 | 131 | c. under Patent Claims infringed by Covered Software in the absence of 132 | its Contributions. 133 | 134 | This License does not grant any rights in the trademarks, service marks, 135 | or logos of any Contributor (except as may be necessary to comply with 136 | the notice requirements in Section 3.4). 137 | 138 | 2.4. Subsequent Licenses 139 | 140 | No Contributor makes additional grants as a result of Your choice to 141 | distribute the Covered Software under a subsequent version of this 142 | License (see Section 10.2) or under the terms of a Secondary License (if 143 | permitted under the terms of Section 3.3). 144 | 145 | 2.5. Representation 146 | 147 | Each Contributor represents that the Contributor believes its 148 | Contributions are its original creation(s) or it has sufficient rights to 149 | grant the rights to its Contributions conveyed by this License. 150 | 151 | 2.6. Fair Use 152 | 153 | This License is not intended to limit any rights You have under 154 | applicable copyright doctrines of fair use, fair dealing, or other 155 | equivalents. 156 | 157 | 2.7. Conditions 158 | 159 | Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted in 160 | Section 2.1. 161 | 162 | 163 | 3. Responsibilities 164 | 165 | 3.1. Distribution of Source Form 166 | 167 | All distribution of Covered Software in Source Code Form, including any 168 | Modifications that You create or to which You contribute, must be under 169 | the terms of this License. You must inform recipients that the Source 170 | Code Form of the Covered Software is governed by the terms of this 171 | License, and how they can obtain a copy of this License. You may not 172 | attempt to alter or restrict the recipients' rights in the Source Code 173 | Form. 174 | 175 | 3.2. Distribution of Executable Form 176 | 177 | If You distribute Covered Software in Executable Form then: 178 | 179 | a. such Covered Software must also be made available in Source Code Form, 180 | as described in Section 3.1, and You must inform recipients of the 181 | Executable Form how they can obtain a copy of such Source Code Form by 182 | reasonable means in a timely manner, at a charge no more than the cost 183 | of distribution to the recipient; and 184 | 185 | b. You may distribute such Executable Form under the terms of this 186 | License, or sublicense it under different terms, provided that the 187 | license for the Executable Form does not attempt to limit or alter the 188 | recipients' rights in the Source Code Form under this License. 189 | 190 | 3.3. Distribution of a Larger Work 191 | 192 | You may create and distribute a Larger Work under terms of Your choice, 193 | provided that You also comply with the requirements of this License for 194 | the Covered Software. If the Larger Work is a combination of Covered 195 | Software with a work governed by one or more Secondary Licenses, and the 196 | Covered Software is not Incompatible With Secondary Licenses, this 197 | License permits You to additionally distribute such Covered Software 198 | under the terms of such Secondary License(s), so that the recipient of 199 | the Larger Work may, at their option, further distribute the Covered 200 | Software under the terms of either this License or such Secondary 201 | License(s). 202 | 203 | 3.4. Notices 204 | 205 | You may not remove or alter the substance of any license notices 206 | (including copyright notices, patent notices, disclaimers of warranty, or 207 | limitations of liability) contained within the Source Code Form of the 208 | Covered Software, except that You may alter any license notices to the 209 | extent required to remedy known factual inaccuracies. 210 | 211 | 3.5. Application of Additional Terms 212 | 213 | You may choose to offer, and to charge a fee for, warranty, support, 214 | indemnity or liability obligations to one or more recipients of Covered 215 | Software. However, You may do so only on Your own behalf, and not on 216 | behalf of any Contributor. You must make it absolutely clear that any 217 | such warranty, support, indemnity, or liability obligation is offered by 218 | You alone, and You hereby agree to indemnify every Contributor for any 219 | liability incurred by such Contributor as a result of warranty, support, 220 | indemnity or liability terms You offer. You may include additional 221 | disclaimers of warranty and limitations of liability specific to any 222 | jurisdiction. 223 | 224 | 4. Inability to Comply Due to Statute or Regulation 225 | 226 | If it is impossible for You to comply with any of the terms of this License 227 | with respect to some or all of the Covered Software due to statute, 228 | judicial order, or regulation then You must: (a) comply with the terms of 229 | this License to the maximum extent possible; and (b) describe the 230 | limitations and the code they affect. Such description must be placed in a 231 | text file included with all distributions of the Covered Software under 232 | this License. Except to the extent prohibited by statute or regulation, 233 | such description must be sufficiently detailed for a recipient of ordinary 234 | skill to be able to understand it. 235 | 236 | 5. Termination 237 | 238 | 5.1. The rights granted under this License will terminate automatically if You 239 | fail to comply with any of its terms. However, if You become compliant, 240 | then the rights granted under this License from a particular Contributor 241 | are reinstated (a) provisionally, unless and until such Contributor 242 | explicitly and finally terminates Your grants, and (b) on an ongoing 243 | basis, if such Contributor fails to notify You of the non-compliance by 244 | some reasonable means prior to 60 days after You have come back into 245 | compliance. Moreover, Your grants from a particular Contributor are 246 | reinstated on an ongoing basis if such Contributor notifies You of the 247 | non-compliance by some reasonable means, this is the first time You have 248 | received notice of non-compliance with this License from such 249 | Contributor, and You become compliant prior to 30 days after Your receipt 250 | of the notice. 251 | 252 | 5.2. If You initiate litigation against any entity by asserting a patent 253 | infringement claim (excluding declaratory judgment actions, 254 | counter-claims, and cross-claims) alleging that a Contributor Version 255 | directly or indirectly infringes any patent, then the rights granted to 256 | You by any and all Contributors for the Covered Software under Section 257 | 2.1 of this License shall terminate. 258 | 259 | 5.3. In the event of termination under Sections 5.1 or 5.2 above, all end user 260 | license agreements (excluding distributors and resellers) which have been 261 | validly granted by You or Your distributors under this License prior to 262 | termination shall survive termination. 263 | 264 | 6. Disclaimer of Warranty 265 | 266 | Covered Software is provided under this License on an "as is" basis, 267 | without warranty of any kind, either expressed, implied, or statutory, 268 | including, without limitation, warranties that the Covered Software is free 269 | of defects, merchantable, fit for a particular purpose or non-infringing. 270 | The entire risk as to the quality and performance of the Covered Software 271 | is with You. Should any Covered Software prove defective in any respect, 272 | You (not any Contributor) assume the cost of any necessary servicing, 273 | repair, or correction. This disclaimer of warranty constitutes an essential 274 | part of this License. No use of any Covered Software is authorized under 275 | this License except under this disclaimer. 276 | 277 | 7. Limitation of Liability 278 | 279 | Under no circumstances and under no legal theory, whether tort (including 280 | negligence), contract, or otherwise, shall any Contributor, or anyone who 281 | distributes Covered Software as permitted above, be liable to You for any 282 | direct, indirect, special, incidental, or consequential damages of any 283 | character including, without limitation, damages for lost profits, loss of 284 | goodwill, work stoppage, computer failure or malfunction, or any and all 285 | other commercial damages or losses, even if such party shall have been 286 | informed of the possibility of such damages. This limitation of liability 287 | shall not apply to liability for death or personal injury resulting from 288 | such party's negligence to the extent applicable law prohibits such 289 | limitation. Some jurisdictions do not allow the exclusion or limitation of 290 | incidental or consequential damages, so this exclusion and limitation may 291 | not apply to You. 292 | 293 | 8. Litigation 294 | 295 | Any litigation relating to this License may be brought only in the courts 296 | of a jurisdiction where the defendant maintains its principal place of 297 | business and such litigation shall be governed by laws of that 298 | jurisdiction, without reference to its conflict-of-law provisions. Nothing 299 | in this Section shall prevent a party's ability to bring cross-claims or 300 | counter-claims. 301 | 302 | 9. Miscellaneous 303 | 304 | This License represents the complete agreement concerning the subject 305 | matter hereof. If any provision of this License is held to be 306 | unenforceable, such provision shall be reformed only to the extent 307 | necessary to make it enforceable. Any law or regulation which provides that 308 | the language of a contract shall be construed against the drafter shall not 309 | be used to construe this License against a Contributor. 310 | 311 | 312 | 10. Versions of the License 313 | 314 | 10.1. New Versions 315 | 316 | Mozilla Foundation is the license steward. Except as provided in Section 317 | 10.3, no one other than the license steward has the right to modify or 318 | publish new versions of this License. Each version will be given a 319 | distinguishing version number. 320 | 321 | 10.2. Effect of New Versions 322 | 323 | You may distribute the Covered Software under the terms of the version 324 | of the License under which You originally received the Covered Software, 325 | or under the terms of any subsequent version published by the license 326 | steward. 327 | 328 | 10.3. Modified Versions 329 | 330 | If you create software not governed by this License, and you want to 331 | create a new license for such software, you may create and use a 332 | modified version of this License if you rename the license and remove 333 | any references to the name of the license steward (except to note that 334 | such modified license differs from this License). 335 | 336 | 10.4. Distributing Source Code Form that is Incompatible With Secondary 337 | Licenses If You choose to distribute Source Code Form that is 338 | Incompatible With Secondary Licenses under the terms of this version of 339 | the License, the notice described in Exhibit B of this License must be 340 | attached. 341 | 342 | Exhibit A - Source Code Form License Notice 343 | 344 | This Source Code Form is subject to the 345 | terms of the Mozilla Public License, v. 346 | 2.0. If a copy of the MPL was not 347 | distributed with this file, You can 348 | obtain one at 349 | http://mozilla.org/MPL/2.0/. 350 | 351 | If it is not possible or desirable to put the notice in a particular file, 352 | then You may include the notice in a location (such as a LICENSE file in a 353 | relevant directory) where a recipient would be likely to look for such a 354 | notice. 355 | 356 | You may add additional accurate notices of copyright ownership. 357 | 358 | Exhibit B - "Incompatible With Secondary Licenses" Notice 359 | 360 | This Source Code Form is "Incompatible 361 | With Secondary Licenses", as defined by 362 | the Mozilla Public License, v. 2.0. 363 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | package: 2 | zip package.zip index.js manifest.json -r icons 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | #Firefox Quick Settings Enhancement Add-on 2 | Adds additional functionalities in Firefox OS quick settings, including NFC, Silence Incomming calls, Flashlight, Internet Sharing, Lock Orientation, Battery Saving Mode, Geolocation, Enable USB Storage, Developer panel configs. 3 | 4 | [Introduction Slide](https://docs.google.com/presentation/d/1KPUdxxjIeMYjxCEAvdOEKOpjkX0fxVcRu721L4QoiYk/edit?usp=sharing) 5 | 6 | Expanded view 7 | 8 | ![Imgur](http://i.imgur.com/yGX48rAm.png) 9 | 10 | Shrink view 11 | 12 | ![Imgur](http://i.imgur.com/9Xlxg4Gm.png) 13 | -------------------------------------------------------------------------------- /gulpfile.js: -------------------------------------------------------------------------------- 1 | var gulp = require('gulp'); 2 | var zip = require('gulp-zip'); 3 | 4 | gulp.task('default', function() { 5 | return gulp.src(['index.js', 'manifest.json', 'LICENSE.md', '**/icons/*']) 6 | .pipe(zip('package.zip')) 7 | .pipe(gulp.dest('./')); 8 | }); 9 | -------------------------------------------------------------------------------- /icons/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gasolin/fxos-quick-settings/ccf5ef296c5f3c9a1cb547924543ddd29eb9345e/icons/icon.png -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | (function () { 2 | 3 | // Borrowed from shared/js/settings_listener.js 4 | var SettingsListener = { 5 | /* lock stores here */ 6 | _lock: null, 7 | 8 | /* keep record of observers in order to remove them in the future */ 9 | _observers: [], 10 | 11 | /** 12 | * getSettingsLock: create a lock or retrieve one that we saved. 13 | * mozSettings.createLock() is expensive and lock should be reused 14 | * whenever possible. 15 | */ 16 | getSettingsLock: function sl_getSettingsLock() { 17 | // If there is a lock present we return that 18 | if (this._lock && !this._lock.closed) { 19 | return this._lock; 20 | } 21 | 22 | // If there isn't we return one. 23 | var settings = window.navigator.mozSettings; 24 | 25 | return (this._lock = settings.createLock()); 26 | }, 27 | 28 | observe: function sl_observe(name, defaultValue, callback) { 29 | var settings = window.navigator.mozSettings; 30 | if (!settings) { 31 | window.setTimeout(function() { callback(defaultValue); }); 32 | return; 33 | } 34 | 35 | var req; 36 | try { 37 | req = this.getSettingsLock().get(name); 38 | } catch (e) { 39 | // It is possible (but rare) for getSettingsLock() to return 40 | // a SettingsLock object that is no longer valid. 41 | // Until https://bugzilla.mozilla.org/show_bug.cgi?id=793239 42 | // is fixed, we just catch the resulting exception and try 43 | // again with a fresh lock 44 | console.warn('Stale lock in settings_listener.js.', 45 | 'See https://bugzilla.mozilla.org/show_bug.cgi?id=793239'); 46 | this._lock = null; 47 | req = this.getSettingsLock().get(name); 48 | } 49 | 50 | req.addEventListener('success', (function onsuccess() { 51 | callback(typeof(req.result[name]) != 'undefined' ? 52 | req.result[name] : defaultValue); 53 | })); 54 | 55 | var settingChanged = function settingChanged(evt) { 56 | callback(evt.settingValue); 57 | }; 58 | settings.addObserver(name, settingChanged); 59 | this._observers.push({ 60 | name: name, 61 | callback: callback, 62 | observer: settingChanged 63 | }); 64 | }, 65 | 66 | unobserve: function sl_unobserve(name, callback) { 67 | var settings = window.navigator.mozSettings; 68 | var that = this; 69 | this._observers.forEach(function(value, index) { 70 | if (value.name === name && value.callback === callback) { 71 | settings.removeObserver(name, value.observer); 72 | that._observers.splice(index, 1); 73 | } 74 | }); 75 | } 76 | }; 77 | 78 | 79 | var QuickSettings = { 80 | _elements: {}, 81 | supportItems: ['nfc', 'volume', 'flashlight', 'hotspot', 'brightness', 82 | 'location', 'powersave', 'orientation', 'developer'], 83 | workingItems: [], 84 | 85 | initialize: function initialize() { 86 | this._elements = { 87 | quickSettingsFields: document.querySelector('#quick-settings'), 88 | quickSettingsContainer: (function () { 89 | var ul = document.querySelector('#quick-settings > ul'); 90 | ul.cachedHeight = ul.clientHeight; 91 | return ul; 92 | }()), 93 | quickSettingsContainerExtension: (function () { 94 | var ul = document.createElement('ul'); 95 | ul.id = 'quick-settings-extension'; 96 | document.querySelector('#quick-settings').appendChild(ul); 97 | return ul; 98 | }()), 99 | lastButton: document.querySelector('#quick-settings-full-app').parentNode, 100 | utilityTrayFooter: document.querySelector('#utility-tray-footer'), 101 | utilityTrayMotion: document.querySelector('#utility-tray-motion'), 102 | notificationsContainer: document.querySelector('#notifications-container'), 103 | }; 104 | 105 | this.workingItems = this.supportItems; 106 | 107 | var KEY = 'quick.settings.addon'; 108 | var settings = window.navigator.mozSettings; 109 | var req = settings.createLock().get(KEY); 110 | req.onsccess = () => { 111 | var result = req.result[KEY]; 112 | if (typeof result === 'undefined') { 113 | console.log('initial to default'); 114 | this.workingItems = this.supportItems; 115 | } else { 116 | this.workingItems = result 117 | } 118 | }; 119 | req.onerror = () => { 120 | console.log('Error fail to get settings'); 121 | this.workingItems = this.supportItems; 122 | }; 123 | 124 | this.renderItems(); 125 | }, 126 | 127 | renderItems: function renderItems() { 128 | this._elements.quickSettingsContainerExtension.style.flexWrap = 'wrap'; 129 | 130 | var availableItems = { 131 | 'nfc': this.initNfcButton, 132 | 'volume': this.initVolumeButton, 133 | 'flashlight': this.initFlashButton, 134 | 'hotspot': this.initHotSpotButton, 135 | 'orientation': this.initOrientationButton, 136 | 'powersave': this.initPowersaveButton, 137 | 'location': this.initLocationButton, 138 | 'ums': this.initUmsButton, 139 | 'developer': this.initDeveloperButton, 140 | 'brightness': this.initBrightnessButton.bind(this), 141 | 'config': this.initConfigButton.bind(this) 142 | }; 143 | 144 | // if (this.workingItems.indexOf('config') < 0) { 145 | // this.workingItems.push('config'); 146 | // } 147 | 148 | var btn = null; 149 | this.workingItems.forEach((item) => { 150 | btn = this.createButton(item); 151 | availableItems[item].call(this, btn.firstChild); 152 | this._elements.quickSettingsContainerExtension.appendChild(btn); 153 | }); 154 | 155 | this.arrangeSettingsButton(); 156 | 157 | // cache the number of icon rows in extra settings to calculate 158 | // how much the settings must be expanded 159 | this._numberOfRows = Math.ceil(this.workingItems.length / 5); 160 | 161 | // Add additional li as placeholders to layout buttons correctly 162 | var fillLi = 5 - this.workingItems.length % 5; 163 | for (i=0; i < fillLi; i++) { 164 | this._elements.quickSettingsContainerExtension.appendChild( 165 | document.createElement('li')); 166 | } 167 | 168 | var allSettings = document.querySelectorAll('#quick-settings-extension > li'); 169 | for (var i=0; i < allSettings.length; i++) { 170 | allSettings[i].style.flex = '1 1 20%'; 171 | } 172 | }, 173 | 174 | arrangeSettingsButton: function arrangeSettingsButton() { 175 | // move settings button to extra settings 176 | this._elements.quickSettingsContainerExtension.appendChild(this._elements.lastButton) 177 | 178 | // change settings button per a arrow button 179 | var arrowButton = document.querySelector('#quick-settings-topup'); 180 | if (arrowButton) { 181 | arrowButton.parentNode.remove(); //remove li 182 | } 183 | arrowButton = this.createButton('topup'); 184 | arrowButton.firstChild.dataset.icon = 'topup'; 185 | this._elements.quickSettingsContainer.appendChild(arrowButton); 186 | 187 | // init arrow button 188 | this.initArrowButton(arrowButton); 189 | // catch events that should shrink the expanded settings 190 | this.initAutoShrinkSettings(); 191 | }, 192 | 193 | // Template: 194 | //
  • 195 | createButton: function createButton(name) { 196 | var li = document.createElement('li'); 197 | var a = document.createElement('a'); 198 | a.href = '#'; 199 | a.id = 'quick-settings-' + name; 200 | a.classList.add('icon'); 201 | a.classList.add('bb-button'); 202 | a.setAttribute('role', 'button'); 203 | 204 | // elements raises an visual alarm about missing aria attribute 205 | // at least in 2.6 206 | a.setAttribute('aria-hidden', 'true'); 207 | 208 | li.appendChild(a); 209 | 210 | return li; 211 | }, 212 | 213 | _shrinkSettings: function () { 214 | this._elements.utilityTrayFooter.style.transform = 'translateY(0%)'; 215 | this._elements.utilityTrayFooter.classList.remove('open'); 216 | }, 217 | 218 | _expandSettings: function () { 219 | var dY = this._numberOfRows * this._elements.quickSettingsContainer.cachedHeight; 220 | this._elements.utilityTrayFooter.style.transform = `translateY(-${dY}px)`; 221 | this._elements.utilityTrayFooter.classList.add('open'); 222 | }, 223 | 224 | _toggleSettings: function () { 225 | if (this._elements.utilityTrayFooter.classList.contains('open')) { 226 | this._shrinkSettings(); 227 | } else { 228 | this._expandSettings(); 229 | } 230 | }, 231 | 232 | initAutoShrinkSettings: function () { 233 | // shrink when closing the utility try 234 | this._elements.utilityTrayMotion.addEventListener('tray-motion-state', (event) => { 235 | // if the visual effect looks weird change to closed 236 | if (event.detail.value === 'closing') { 237 | this._shrinkSettings(); 238 | } 239 | }, false); 240 | 241 | // shrink when scroll notification to make visual room 242 | this._elements.notificationsContainer.addEventListener('scroll', (event) => { 243 | this._shrinkSettings(); 244 | }, false); 245 | }, 246 | 247 | initArrowButton: function initArrowButton(button) { 248 | // toggle on click arrow button 249 | button.addEventListener('click', this._toggleSettings.bind(this)); 250 | }, 251 | 252 | initVolumeButton: function initVolumeButton(button) { 253 | var originalVolume = 0; 254 | 255 | function onVolumeChanged(value) { 256 | if (value > 14) { 257 | button.dataset.icon = 'sound-max'; 258 | button.style.color = ''; 259 | button.dataset.l10nId = 'quick-settings-volumeButton-max'; 260 | } else if (value < 1) { 261 | button.dataset.icon = 'mute'; 262 | button.style.color = '#008EAB'; 263 | button.dataset.l10nId = 'quick-settings-volumeButton-mute'; 264 | } else { 265 | button.dataset.icon = 'sound-min'; 266 | button.style.color = ''; 267 | button.dataset.l10nId = 'quick-settings-volumeButton-min'; 268 | } 269 | 270 | originalVolume = value > 0 ? value : originalVolume; 271 | } 272 | 273 | function onClick() { 274 | if (button.dataset.icon === 'mute') { 275 | window.navigator.mozSettings.createLock().set({'audio.volume.notification': originalVolume}); 276 | } else { 277 | window.navigator.mozSettings.createLock().set({'audio.volume.notification': 0}); 278 | } 279 | } 280 | 281 | button.dataset.icon = 'sound-max'; 282 | // button.dataset.enabled = false; 283 | button.dataset.l10nId = 'quick-settings-volumeButton-max'; 284 | button.addEventListener('click', onClick); 285 | 286 | SettingsListener.observe('audio.volume.notification', '', onVolumeChanged); 287 | }, 288 | 289 | initNfcButton: function initNfcButton(button) { 290 | 291 | function onNfcStatusChanged(status) { 292 | if (status === 'enabling' || status === 'enabled') { 293 | button.style.color = '#008EAB'; 294 | button.dataset.enabled = true; 295 | button.dataset.l10nId = 'quick-settings-nfcButton-on'; 296 | } else if (status === 'disabling' || status === 'disabled') { 297 | button.style.color = ''; 298 | button.dataset.enabled = false; 299 | button.dataset.l10nId = 'quick-settings-nfcButton-off'; 300 | } 301 | } 302 | 303 | function onClick() { 304 | if (button.dataset.enabled === 'true') { 305 | window.navigator.mozSettings.createLock().set({'nfc.enabled': false}); 306 | } else { 307 | window.navigator.mozSettings.createLock().set({'nfc.enabled': true}); 308 | } 309 | } 310 | 311 | button.dataset.icon = 'nfc'; 312 | button.dataset.enabled = false; 313 | button.dataset.l10nId = 'quick-settings-nfcButton-off'; 314 | button.addEventListener('click', onClick); 315 | 316 | SettingsListener.observe('nfc.status', undefined, onNfcStatusChanged); 317 | }, 318 | 319 | initFlashButton: function initFlashButton(button) { 320 | 321 | var options = { 322 | mode: 'video' 323 | }; 324 | 325 | var cameraId = window.navigator.mozCameras.getListOfCameras()[0]; 326 | var mozCamera; 327 | 328 | // need to check if the current app uses camera or not, show an error toast if yes 329 | 330 | // need to release camera when the screen is on after it went black 331 | 332 | // before getCamera, need to check if any app other than the current app occupies the camera, 333 | // release the camera if yes 334 | 335 | function onClick () { 336 | console.log('onClick', button.dataset.enabled); 337 | if (button.dataset.enabled === 'true') { 338 | console.log('release camera'); 339 | mozCamera.release(); 340 | 341 | button.style.color = ''; 342 | button.dataset.enabled = false; 343 | button.dataset.l10nId = 'quick-settings-flashlightButton-off'; 344 | } else { 345 | console.log('get camera'); 346 | window.navigator.mozCameras.getCamera(cameraId, options) 347 | .then(function (result) { 348 | console.log('set flash on'); 349 | mozCamera = result.camera; 350 | mozCamera.flashMode = 'torch'; 351 | }, function (error) { 352 | console.log(error); 353 | }).catch(function (e) { 354 | console.log('catch', e); 355 | }); 356 | 357 | button.style.color = '#008EAB'; 358 | button.dataset.enabled = true; 359 | button.dataset.l10nId = 'quick-settings-flashlightButton-on'; 360 | } 361 | } 362 | 363 | button.dataset.icon = 'flash-on'; 364 | button.dataset.enabled = false; 365 | button.dataset.l10nId = 'quick-settings-flashlightButton-off'; 366 | button.addEventListener('click', onClick); 367 | }, 368 | 369 | initHotSpotButton: function initHotSpotButton(button) { 370 | 371 | function onHotSpotStatusChanged(status) { 372 | if (status) { 373 | button.style.color = '#008EAB'; 374 | button.dataset.enabled = true; 375 | button.dataset.l10nId = 'quick-settings-hotSpotButton-on'; 376 | } else { 377 | button.style.color = ''; 378 | button.dataset.enabled = false; 379 | button.dataset.l10nId = 'quick-settings-hotSpotButton-off'; 380 | } 381 | } 382 | 383 | function onClick() { 384 | if (button.dataset.enabled === 'true') { 385 | window.navigator.mozSettings.createLock().set({'tethering.wifi.enabled': false}); 386 | } else { 387 | window.navigator.mozSettings.createLock().set({'tethering.wifi.enabled': true}); 388 | } 389 | } 390 | 391 | button.dataset.icon = 'tethering'; 392 | button.dataset.enabled = false; 393 | button.dataset.l10nId = 'quick-settings-hotspotButton-off'; 394 | button.addEventListener('click', onClick); 395 | 396 | SettingsListener.observe('tethering.wifi.enabled', false, onHotSpotStatusChanged); 397 | }, 398 | 399 | initOrientationButton: function initOrientationButton(button) { 400 | 401 | function onOrientationStatusChanged(status) { 402 | if (status) { 403 | button.style.color = '#008EAB'; 404 | button.dataset.enabled = true; 405 | button.dataset.l10nId = 'quick-settings-orientButton-on'; 406 | } else { 407 | button.style.color = ''; 408 | button.dataset.enabled = false; 409 | button.dataset.l10nId = 'quick-settings-orientButton-off'; 410 | } 411 | } 412 | 413 | function onClick() { 414 | if (button.dataset.enabled === 'true') { 415 | window.navigator.mozSettings.createLock().set({'screen.orientation.lock': false}); 416 | } else { 417 | window.navigator.mozSettings.createLock().set({'screen.orientation.lock': true}); 418 | } 419 | } 420 | 421 | button.dataset.icon = 'toggle-camera-front'; 422 | button.dataset.enabled = false; 423 | button.dataset.l10nId = 'quick-settings-orientationButton-off'; 424 | button.addEventListener('click', onClick); 425 | 426 | SettingsListener.observe('screen.orientation.lock', false, onOrientationStatusChanged); 427 | }, 428 | 429 | initPowersaveButton: function initPowersaveButton(button) { 430 | 431 | function onPowersaveStatusChanged(status) { 432 | if (status) { 433 | button.style.color = '#008EAB'; 434 | button.dataset.enabled = true; 435 | button.dataset.l10nId = 'quick-settings-powersaveButton-on'; 436 | } else { 437 | button.style.color = ''; 438 | button.dataset.enabled = false; 439 | button.dataset.l10nId = 'quick-settings-powersaveButton-off'; 440 | } 441 | } 442 | 443 | function onClick() { 444 | if (button.dataset.enabled === 'true') { 445 | window.navigator.mozSettings.createLock().set({'powersave.enabled': false}); 446 | } else { 447 | window.navigator.mozSettings.createLock().set({'powersave.enabled': true}); 448 | } 449 | } 450 | 451 | button.dataset.icon = 'battery-3'; 452 | button.dataset.enabled = false; 453 | button.dataset.l10nId = 'quick-settings-powersaveButton-off'; 454 | button.addEventListener('click', onClick); 455 | 456 | SettingsListener.observe('powersave.enabled', false, onPowersaveStatusChanged); 457 | }, 458 | 459 | initLocationButton: function initLocationButton(button) { 460 | 461 | function onLocationStatusChanged(status) { 462 | if (status) { 463 | button.style.color = '#008EAB'; 464 | button.dataset.enabled = true; 465 | button.dataset.l10nId = 'quick-settings-locationButton-on'; 466 | } else { 467 | button.style.color = ''; 468 | button.dataset.enabled = false; 469 | button.dataset.l10nId = 'quick-settings-locationButton-off'; 470 | } 471 | } 472 | 473 | function onClick() { 474 | if (button.dataset.enabled === 'true') { 475 | window.navigator.mozSettings.createLock().set({'geolocation.enabled': false}); 476 | } else { 477 | window.navigator.mozSettings.createLock().set({'geolocation.enabled': true}); 478 | } 479 | } 480 | 481 | button.dataset.icon = 'location'; 482 | button.dataset.enabled = false; 483 | button.dataset.l10nId = 'quick-settings-locationButton-off'; 484 | button.addEventListener('click', onClick); 485 | 486 | SettingsListener.observe('geolocation.enabled', false, onLocationStatusChanged); 487 | }, 488 | 489 | initUmsButton: function initUmsButton(button) { 490 | 491 | function onLocationStatusChanged(status) { 492 | if (status) { 493 | button.style.color = '#008EAB'; 494 | button.dataset.enabled = true; 495 | button.dataset.l10nId = 'quick-settings-umsButton-on'; 496 | } else { 497 | button.style.color = ''; 498 | button.dataset.enabled = false; 499 | button.dataset.l10nId = 'quick-settings-umsButton-off'; 500 | } 501 | } 502 | 503 | function onClick() { 504 | if (button.dataset.enabled === 'true') { 505 | window.navigator.mozSettings.createLock().set({'ums.enabled': false}); 506 | } else { 507 | window.navigator.mozSettings.createLock().set({'ums.enabled': true}); 508 | } 509 | } 510 | 511 | button.dataset.icon = 'usb'; 512 | button.dataset.enabled = false; 513 | button.dataset.l10nId = 'quick-settings-umsButton-off'; 514 | button.addEventListener('click', onClick); 515 | SettingsListener.observe('ums.enabled', false, onLocationStatusChanged); 516 | }, 517 | 518 | // Build the brightness control elements. 519 | renderBrightnessControl: function renderBrightnessControl() { 520 | var containerEl = document.createElement('div'); 521 | containerEl.setAttribute('id', 'quick-brightness-container'); 522 | containerEl.setAttribute('data-time-inserted', Date.now()); 523 | // Inline styles are icky, but I think injected addon CSS is broken right now. 524 | // see: https://developer.mozilla.org/en-US/Firefox_OS/Add-ons#Stylesheets 525 | containerEl.setAttribute('style', [ 526 | 'height: 3.5rem;', 527 | 'margin: 1.5rem 0 0 0;' 528 | ].join('\n')); 529 | 530 | // Markup stolen and munged from gaia settings 531 | containerEl.innerHTML = [ 532 | '' 541 | ].join('\n'); 542 | 543 | // Inject the elements into the system app 544 | this._elements.utilityTrayFooter.insertBefore(containerEl, this._elements.quickSettingsFields); 545 | 546 | // Wire up an event listener to set brightness on slider change. 547 | var sliderEl = document.querySelector('#quick-brightness-control'); 548 | sliderEl.addEventListener('change', function (ev) { 549 | window.navigator.mozSettings.createLock() 550 | .set({'screen.brightness': sliderEl.value}); 551 | }); 552 | SettingsListener.observe('screen.brightness', 0.5, function(value) { 553 | sliderEl.value = value; 554 | }); 555 | }, 556 | 557 | // borrow from https://github.com/lmorchard/fxos-addon-quick-brightness/blob/master/index.js 558 | initBrightnessButton: function initBrightnessButton(button) { 559 | 560 | function onStateChanged(status) { 561 | // Remove existing control, for when this addon is re-run. 562 | var existingContainerEl = 563 | document.querySelector('#quick-brightness-container'); 564 | if (existingContainerEl) { 565 | existingContainerEl.parentNode.removeChild(existingContainerEl); 566 | } 567 | 568 | if (status) { 569 | button.style.color = ''; 570 | button.dataset.enabled = false; 571 | button.dataset.l10nId = 'quick-settings-brightnessButton-off'; 572 | } else { 573 | button.style.color = '#008EAB'; 574 | button.dataset.enabled = true; 575 | button.dataset.l10nId = 'quick-settings-brightnessButton-on'; 576 | this.renderBrightnessControl(); 577 | } 578 | } 579 | 580 | function onClick() { 581 | if (button.dataset.enabled === 'true') { 582 | window.navigator.mozSettings.createLock() 583 | .set({'screen.automatic-brightness': true}); 584 | } else { 585 | window.navigator.mozSettings.createLock() 586 | .set({'screen.automatic-brightness': false}); 587 | } 588 | } 589 | 590 | button.dataset.icon = 'brightness'; 591 | button.dataset.enabled = false; 592 | button.dataset.l10nId = 'quick-settings-brightnessButton-off'; 593 | button.addEventListener('click', onClick); 594 | SettingsListener.observe('screen.automatic-brightness', false, onStateChanged.bind(this)); 595 | }, 596 | 597 | initDeveloperButton: function initDeveloperButton(button) { 598 | function onClick() { 599 | new MozActivity({ 600 | name: 'configure', 601 | data: { 602 | target: 'device', 603 | section: 'developer' 604 | } 605 | }); 606 | } 607 | 608 | button.dataset.icon = 'bug'; 609 | button.dataset.enabled = false; 610 | button.dataset.l10nId = 'quick-settings-developerButton-off'; 611 | button.addEventListener('click', onClick); 612 | }, 613 | 614 | initConfigButton: function initConfigButton(button) { 615 | function onClick() { 616 | var activity = new MozActivity({ 617 | name: 'configure', 618 | data: { 619 | target: 'user' 620 | } 621 | }); 622 | 623 | activity.onsuccess = () => { 624 | console.log("XXX Activity successfuly handled", activity); 625 | this.renderItems(); 626 | }; 627 | 628 | activity.onerror = function() { 629 | console.log("The activity encouter en error: " + this.error); 630 | }; 631 | } 632 | 633 | button.dataset.icon = 'addons'; 634 | button.dataset.enabled = false; 635 | button.dataset.l10nId = 'quick-settings-configButton-off'; 636 | button.addEventListener('click', onClick.bind(this)); 637 | } 638 | }; 639 | 640 | // If injecting into an app that was already running at the time 641 | // the app was enabled, simply initialize it. 642 | if (document.documentElement) { 643 | QuickSettings.initialize(); 644 | } else { 645 | // Otherwise, we need to wait for the DOM to be ready before 646 | // starting initialization since add-ons are usually (always?) 647 | // injected *before* `document.documentElement` is defined. 648 | window.addEventListener('DOMContentLoaded', QuickSettings.initialize); 649 | } 650 | }()); 651 | -------------------------------------------------------------------------------- /manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "manifest_version": 2, 3 | "name": "Quick Settings Enhancement", 4 | "description": "Adds torch and more settings to quick settings menu. Welcome to contribute https://github.com/gasolin/fxos-quick-settings", 5 | "version": "2.0.0", 6 | "author": "begeeben & gasolin", 7 | "content_scripts": [{ 8 | "matches": "app://system.gaiamobile.org/index.html", 9 | "css": ["styles.css"], 10 | "js": ["index.js"] 11 | }], 12 | "icons": { 13 | "128": "icons/icon.png" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "quick-settings-enhancement", 3 | "description": "Adds missing functionalities in quick settings menu. Welcome to contribute https://github.com/gasolin/fxos-quick-settings", 4 | "developer": { 5 | "name": "begeeben & gasolin" 6 | }, 7 | "dependencies": { 8 | "gulp": "*", 9 | "gulp-zip": "*" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /package.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gasolin/fxos-quick-settings/ccf5ef296c5f3c9a1cb547924543ddd29eb9345e/package.zip -------------------------------------------------------------------------------- /styles.css: -------------------------------------------------------------------------------- 1 | #utility-tray { 2 | overflow: hidden; 3 | } 4 | 5 | #utility-tray-footer { 6 | transition: transform 0.2s; 7 | transform: translateY(0%); 8 | 9 | overflow: visible !important; 10 | z-index: 2 !important; 11 | } 12 | 13 | #quick-settings-extension { 14 | position: absolute; 15 | width: 100%; 16 | 17 | } 18 | 19 | #utility-tray-grippy { 20 | z-index: 3 !important; 21 | } 22 | 23 | /* We need to give a solid background because */ 24 | /* the footer will take place over the notification */ 25 | /* container an would be hard to read the settings */ 26 | #utility-tray-footer, 27 | #utility-tray-footer ul { 28 | background-color: hsl(0, 0%, 24%);; 29 | } 30 | 31 | 32 | /* spin arrow icon on open */ 33 | #quick-settings-topup { 34 | transition: transform 0.2s; 35 | transform: rotatez(0deg); 36 | } 37 | 38 | #utility-tray-footer.open #quick-settings-topup { 39 | transform: rotatez(180deg); 40 | } 41 | --------------------------------------------------------------------------------