ui.js (2052B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 "use strict"; 5 6 const { 7 ENABLE, 8 RESET, 9 UPDATE_CAN_BE_DISABLED, 10 UPDATE_CAN_BE_ENABLED, 11 UPDATE_PREF, 12 PREF_KEYS, 13 UPDATE_DISPLAY_TABBING_ORDER, 14 } = require("resource://devtools/client/accessibility/constants.js"); 15 16 /** 17 * Reset accessibility panel UI. 18 */ 19 exports.reset = 20 (resetAccessiblity, supports) => 21 async ({ dispatch }) => { 22 try { 23 const { enabled, canBeDisabled, canBeEnabled } = 24 await resetAccessiblity(); 25 dispatch({ enabled, canBeDisabled, canBeEnabled, supports, type: RESET }); 26 } catch (error) { 27 dispatch({ type: RESET, error }); 28 } 29 }; 30 31 /** 32 * Update a "canBeDisabled" flag for accessibility service. 33 */ 34 exports.updateCanBeDisabled = 35 canBeDisabled => 36 ({ dispatch }) => 37 dispatch({ canBeDisabled, type: UPDATE_CAN_BE_DISABLED }); 38 39 /** 40 * Update a "canBeEnabled" flag for accessibility service. 41 */ 42 exports.updateCanBeEnabled = 43 canBeEnabled => 44 ({ dispatch }) => 45 dispatch({ canBeEnabled, type: UPDATE_CAN_BE_ENABLED }); 46 47 exports.updatePref = 48 (name, value) => 49 ({ dispatch }) => { 50 dispatch({ type: UPDATE_PREF, name, value }); 51 Services.prefs.setBoolPref(PREF_KEYS[name], value); 52 }; 53 54 /** 55 * Enable accessibility services in order to view accessible tree. 56 */ 57 exports.enable = 58 enableAccessibility => 59 async ({ dispatch }) => { 60 try { 61 await enableAccessibility(); 62 dispatch({ type: ENABLE }); 63 } catch (error) { 64 dispatch({ error, type: ENABLE }); 65 } 66 }; 67 68 exports.updateDisplayTabbingOrder = 69 tabbingOrderDisplayed => 70 async ({ dispatch, options: { toggleDisplayTabbingOrder } }) => { 71 try { 72 await toggleDisplayTabbingOrder(tabbingOrderDisplayed); 73 dispatch({ tabbingOrderDisplayed, type: UPDATE_DISPLAY_TABBING_ORDER }); 74 } catch (error) { 75 dispatch({ error, type: UPDATE_DISPLAY_TABBING_ORDER }); 76 } 77 };