Commit 8deb9f9f authored by Anastasia Helfinstein's avatar Anastasia Helfinstein Committed by Chromium LUCI CQ

[Switch Access] Only open settings on enabled when unconfigured

When the settings UI was improved, the underlying preferences changed.
This updates the extension JS to use the new preferences.

AX-Relnotes: Fix bug where settings opened every time Switch Access was enabled.
Bug: 1162750
Change-Id: I0c09fb35aba5f3182cfeeb82d3767acacb496285
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2618580
Auto-Submit: Anastasia Helfinstein <anastasi@google.com>
Commit-Queue: Josiah Krutz <josiahk@google.com>
Reviewed-by: default avatarJosiah Krutz <josiahk@google.com>
Cr-Commit-Position: refs/heads/master@{#841711}
parent 8c86c0a8
......@@ -62,6 +62,22 @@ export class PreferenceManager {
return null;
}
/**
* Get the preference value for the given name, or |null| if the value is not
* a dictionary or does not exist.
*
* @param {SAConstants.Preference} name
* @return {Object|null}
* @private
*/
getDict_(name) {
const pref = this.preferences_.get(name);
if (pref && pref.type === chrome.settingsPrivate.PrefType.DICTIONARY) {
return /** @type {Object} */ (pref.value);
}
return null;
}
/** @private */
init_() {
chrome.settingsPrivate.onPrefsChanged.addListener(
......@@ -77,19 +93,26 @@ export class PreferenceManager {
* @private
*/
settingsAreConfigured_() {
const selectSetting =
this.getNumber_(SAConstants.Preference.SELECT_SETTING);
const nextSetting = this.getNumber_(SAConstants.Preference.NEXT_SETTING);
const previousSetting =
this.getNumber_(SAConstants.Preference.PREVIOUS_SETTING);
const selectPref =
this.getDict_(SAConstants.Preference.SELECT_DEVICE_KEY_CODES);
const selectSet = selectPref ? Object.keys(selectPref).length : false;
const nextPref =
this.getDict_(SAConstants.Preference.NEXT_DEVICE_KEY_CODES);
const nextSet = nextPref ? Object.keys(nextPref).length : false;
const previousPref =
this.getDict_(SAConstants.Preference.PREVIOUS_DEVICE_KEY_CODES);
const previousSet = previousPref ? Object.keys(previousPref).length : false;
const autoScanEnabled =
!!this.getBoolean_(SAConstants.Preference.AUTO_SCAN_ENABLED);
if (!selectSetting) {
if (!selectSet) {
return false;
}
if (nextSetting || previousSetting) {
if (nextSet || previousSet) {
return true;
}
......
......@@ -92,9 +92,11 @@ export const SAConstants = {
AUTO_SCAN_TIME: 'settings.a11y.switch_access.auto_scan.speed_ms',
AUTO_SCAN_KEYBOARD_TIME:
'settings.a11y.switch_access.auto_scan.keyboard.speed_ms',
NEXT_SETTING: 'settings.a11y.switch_access.next.setting',
PREVIOUS_SETTING: 'settings.a11y.switch_access.previous.setting',
SELECT_SETTING: 'settings.a11y.switch_access.select.setting',
NEXT_DEVICE_KEY_CODES: 'settings.a11y.switch_access.next.device_key_codes',
PREVIOUS_DEVICE_KEY_CODES:
'settings.a11y.switch_access.previous.device_key_codes',
SELECT_DEVICE_KEY_CODES:
'settings.a11y.switch_access.select.device_key_codes',
},
// =========================== Sub-objects ===========================
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment