From 5e704f02f666ce3155213f95a097c64feecd2ec5 Mon Sep 17 00:00:00 2001 From: Emerick Rogul Date: Mon, 6 Jan 2025 15:55:07 -0500 Subject: [PATCH] Remove ts-nocheck from brave://settings files --- ...ave_clear_browsing_data_dialog_behavior.ts | 127 +++++---- .../brave_clear_browsing_data_on_exit_page.ts | 144 ++++++---- .../settings/brave_overrides/about_page.ts | 22 +- .../settings/brave_overrides/basic_page.ts | 6 +- .../clear_browsing_data_dialog.ts | 14 +- .../brave_overrides/default_browser_page.ts | 18 +- .../brave_overrides/import_data_dialog.ts | 10 +- .../brave_overrides/page_visibility.ts | 20 +- .../settings/brave_overrides/settings_menu.ts | 55 ++-- .../settings/brave_overrides/settings_ui.ts | 43 +-- .../settings/brave_overrides/site_details.ts | 87 +++--- .../brave_overrides/site_settings_page.ts | 75 +++-- .../brave_reset_profile_dialog_behavior.ts | 11 +- browser/resources/settings/brave_routes.ts | 12 +- .../brave_sync_page/brave_sync_subpage.ts | 253 ++++++++--------- .../brave_tor_bridges_dialog.ts | 61 ++-- .../brave_tor_page/brave_tor_browser_proxy.ts | 12 +- ...ave_tor_snowflake_install_failed_dialog.ts | 15 +- .../brave_tor_page/brave_tor_subpage.ts | 187 +++++++----- .../brave_wallet_browser_proxy.ts | 6 +- .../brave_wallet_page/brave_wallet_page.ts | 267 +++++++++++------- .../brave_wallet_page/wallet_networks_list.ts | 197 ++++++++----- .../wallet_networks_subpage.ts | 49 ++-- .../brave_adblock_browser_proxy.ts | 138 +++++---- .../brave_adblock_subpage.ts | 115 +++++--- .../components/brave_adblock_editor.ts | 22 +- .../brave_adblock_subscribe_dropdown.ts | 36 +-- .../default_brave_shields_browser_proxy.ts | 138 +++------ .../default_brave_shields_page.ts | 71 +++-- .../pin_shortcut_page/pin_shortcut_page.ts | 25 +- .../brave_overrides/certificate_manager_v2.ts | 2 - 31 files changed, 1253 insertions(+), 985 deletions(-) diff --git a/browser/resources/settings/brave_clear_browsing_data_dialog/brave_clear_browsing_data_dialog_behavior.ts b/browser/resources/settings/brave_clear_browsing_data_dialog/brave_clear_browsing_data_dialog_behavior.ts index 3508c4278592..e8389f1970fe 100644 --- a/browser/resources/settings/brave_clear_browsing_data_dialog/brave_clear_browsing_data_dialog_behavior.ts +++ b/browser/resources/settings/brave_clear_browsing_data_dialog/brave_clear_browsing_data_dialog_behavior.ts @@ -1,39 +1,48 @@ -// @ts-nocheck /* Copyright (c) 2019 The Brave Authors. All rights reserved. * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * you can obtain one at https://mozilla.org/MPL/2.0/. */ + * You can obtain one at https://mozilla.org/MPL/2.0/. */ +import './brave_clear_browsing_data_on_exit_page.js' -import "./brave_clear_browsing_data_on_exit_page.js" +import {CrButtonElement} from 'chrome://resources/cr_elements/cr_button/cr_button.js' +import { + SettingsBraveClearBrowsingDataOnExitPageElement +} from './brave_clear_browsing_data_on_exit_page.js' -import {loadTimeData} from "../i18n_setup.js" -import {WebUiListenerMixin} from 'chrome://resources/cr_elements/web_ui_listener_mixin.js'; -import {SettingsClearBrowsingDataDialogElement} from '../clear_browsing_data_dialog/clear_browsing_data_dialog.js' -import type {SettingsClearBrowsingDataDialogElement as BraveSettingsClearBrowsingDataDialogElement} - from '../clear_browsing_data_dialog/clear_browsing_data_dialog.js' -import {BraveClearBrowsingDataDialogBrowserProxy, BraveClearBrowsingDataDialogBrowserProxyImpl} - from './brave_clear_browsing_data_dialog_proxy.js' +import {loadTimeData} from '../i18n_setup.js' -const BaseElement = WebUiListenerMixin(SettingsClearBrowsingDataDialogElement) -export class BraveSettingsClearBrowsingDataDialogElement extends BaseElement { - braveRewardsEnabled_: Boolean = false; - onClearBraveAdsDataClickHandler_: (() => void) = () => {}; +import { + SettingsClearBrowsingDataDialogElement +} from '../clear_browsing_data_dialog/clear_browsing_data_dialog.js' - private clearDataBrowserProxy_ = - BraveClearBrowsingDataDialogBrowserProxyImpl.getInstance(); - private onSelectedPageChangedCallback_: (() => void) | null = null; - private updateSaveButtonStateCallback_: (() => void) | null = null; - private saveOnExitSettingsCallback_: (() => void) | null = null; +import { + BraveClearBrowsingDataDialogBrowserProxy, + BraveClearBrowsingDataDialogBrowserProxyImpl +} from './brave_clear_browsing_data_dialog_proxy.js' + +export class BraveSettingsClearBrowsingDataDialogElement +extends SettingsClearBrowsingDataDialogElement { + braveRewardsEnabled_: Boolean = false + onClearBraveAdsDataClickHandler_: ((e: Event) => void) = () => {} + + private clearDataBrowserProxy_: BraveClearBrowsingDataDialogBrowserProxy = + BraveClearBrowsingDataDialogBrowserProxyImpl.getInstance() + + private onSelectedPageChangedCallback_: (() => void) | null = null + + private updateSaveButtonStateCallback_: (() => void) | null = null + + private saveOnExitSettingsCallback_: (() => void) | null = null override ready() { - super.ready(); + super.ready() // Append On exit tab to tab selector. - this.tabsNames_.push(loadTimeData.getString('onExitPageTitle')); + ;(this as any).tabsNames_.push(loadTimeData.getString('onExitPageTitle')) this.addWebUiListener( - 'update-counter-text', this.updateOnExitCountersText.bind(this)) + 'update-counter-text', this.updateOnExitCountersText_.bind(this)) this.addWebUiListener( 'brave-rewards-enabled-changed', (enabled: boolean) => { @@ -56,9 +65,9 @@ export class BraveSettingsClearBrowsingDataDialogElement extends BaseElement { this.shadowRoot!.querySelector('#on-exit-tab')!.addEventListener( 'clear-data-on-exit-page-change', this.updateSaveButtonStateCallback_) - this.saveOnExitSettingsCallback_ = this.saveOnExitSettings_.bind(this); - this.shadowRoot.querySelector('#saveOnExitSettingsConfirm').addEventListener( - 'click', this.saveOnExitSettingsCallback_); + this.saveOnExitSettingsCallback_ = this.saveOnExitSettings_.bind(this) + this.shadowRoot!.querySelector('#saveOnExitSettingsConfirm')! + .addEventListener('click', this.saveOnExitSettingsCallback_) this.onClearBraveAdsDataClickHandler_ = this.clearBraveAdsData_.bind(this) } @@ -72,16 +81,17 @@ export class BraveSettingsClearBrowsingDataDialogElement extends BaseElement { this.onSelectedPageChangedCallback_ = null } - if (this.saveOnExitSettingsCallback_) { - this.shadowRoot.querySelector('#on-exit-tab').removeEventListener( - 'clear-data-on-exit-page-change', this.updateSaveButtonStateCallback_); - this.updateSaveButtonStateCallback_ = null; + if (this.updateSaveButtonStateCallback_) { + this.shadowRoot!.querySelector('#on-exit-tab')!.removeEventListener( + 'clear-data-on-exit-page-change', this.updateSaveButtonStateCallback_) + this.updateSaveButtonStateCallback_ = null } if (this.saveOnExitSettingsCallback_) { - this.shadowRoot.querySelector('#saveOnExitSettingsConfirm').removeEventListener( - 'click', this.saveOnExitSettingsCallback_); - this.saveOnExitSettingsCallback_ = null; + this.shadowRoot!. + querySelector('#saveOnExitSettingsConfirm')!. + removeEventListener('click', this.saveOnExitSettingsCallback_) + this.saveOnExitSettingsCallback_ = null } this.onClearBraveAdsDataClickHandler_ = () => {} @@ -92,60 +102,67 @@ export class BraveSettingsClearBrowsingDataDialogElement extends BaseElement { * preference. * @param {string} prefName Browsing data type deletion preference. * @param {string} text The text with which to update the counter - * @private */ - updateOnExitCountersText(prefName, text) { + private updateOnExitCountersText_(prefName: string, text: string) { // Data type deletion preferences are named "browser.clear_data.". // Strip the common prefix, i.e. use only "". - const matches = prefName.match(/^browser\.clear_data\.(\w+)$/); - this.shadowRoot.querySelector('#on-exit-tab').setCounter(matches[1], text); + const matches = prefName.match(/^browser\.clear_data\.(\w+)$/) + if (matches) { + this.shadowRoot!. + querySelector( + '#on-exit-tab')!.setCounter(matches[1], text) + } } /** * Updates Clear and Save buttons visibility based on the selected tab. - * @private */ - onSelectedPageChanged_() { - const page = this.$.pages.selectedItem; + private onSelectedPageChanged_() { + const page = this.$.pages.selectedItem if (!page) { return } - const isOnExitPage = (page.id === 'on-exit-tab'); - this.$.clearButton.hidden = isOnExitPage; - this.shadowRoot.querySelector('#saveOnExitSettingsConfirm').hidden = !isOnExitPage; + const isOnExitPage = page.id === 'on-exit-tab' + this.$.clearButton.hidden = isOnExitPage + this.shadowRoot!.querySelector( + '#saveOnExitSettingsConfirm')!.hidden = !isOnExitPage } /** * Updates Save button enabled state based on on-exit-tab's changed state. - * @private */ - updateSaveButtonState_() { - this.shadowRoot.querySelector('#saveOnExitSettingsConfirm').disabled = - !this.shadowRoot.querySelector('#on-exit-tab').isModified; + private updateSaveButtonState_() { + const saveButton = this.shadowRoot!. + querySelector('#saveOnExitSettingsConfirm') + if (saveButton) { + saveButton.disabled = !this.shadowRoot!. + querySelector( + '#on-exit-tab')!.isModified_ + } } /** * Saves on exit settings selections. - * @private */ - saveOnExitSettings_() { - const changed = this.shadowRoot.querySelector('#on-exit-tab').getChangedSettings(); + private saveOnExitSettings_() { + const changed = this.shadowRoot!. + querySelector( + '#on-exit-tab')!.getChangedSettings() changed.forEach((change) => { this.set('prefs.' + change.key + '.value', change.value) }) this.updateSaveButtonState_() - if (!this.clearingInProgress_) { + if (!(this as any).clearingInProgress_) { this.$.clearBrowsingDataDialog.close() } } /** * Clears Brave Ads data. - * @private */ - clearBraveAdsData_(e: any) { - e.preventDefault(); - this.clearDataBrowserProxy_.clearBraveAdsData(); - this.$.clearBrowsingDataDialog.close(); + private clearBraveAdsData_(e: Event) { + e.preventDefault() + this.clearDataBrowserProxy_.clearBraveAdsData() + this.$.clearBrowsingDataDialog.close() } } diff --git a/browser/resources/settings/brave_clear_browsing_data_dialog/brave_clear_browsing_data_on_exit_page.ts b/browser/resources/settings/brave_clear_browsing_data_dialog/brave_clear_browsing_data_on_exit_page.ts index 586007df111e..ab237ecd4b96 100644 --- a/browser/resources/settings/brave_clear_browsing_data_dialog/brave_clear_browsing_data_on_exit_page.ts +++ b/browser/resources/settings/brave_clear_browsing_data_dialog/brave_clear_browsing_data_on_exit_page.ts @@ -3,85 +3,115 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this file, // you can obtain one at https://mozilla.org/MPL/2.0/. -// @ts-nocheck - -import {Polymer} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js'; -import {loadTimeData} from '../i18n_setup.js'; -import '../settings_shared.css.js'; -import '../settings_vars.css.js'; -import '../controls/settings_checkbox.js'; +import {PrefsMixin} from '/shared/settings/prefs/prefs_mixin.js' +import {BaseMixin} from '../base_mixin.js' +import {PolymerElement} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js' +import {loadTimeData} from '../i18n_setup.js' +import '../settings_shared.css.js' +import '../settings_vars.css.js' +import '../controls/settings_checkbox.js' import {getTemplate} from './brave_clear_browsing_data_on_exit_page.html.js' -Polymer({ - is: 'settings-brave-clear-browsing-data-on-exit-page', +export interface SettingsBraveClearBrowsingDataOnExitPageElement { + $: { + checkboxes: HTMLElement, + } +} - _template: getTemplate(), +const SettingsBraveClearBrowsingDataOnExitPageElementBase = + PrefsMixin(BaseMixin(PolymerElement)) - properties: { - prefs: { - type: Object, - notify: true, - }, +export class SettingsBraveClearBrowsingDataOnExitPageElement +extends SettingsBraveClearBrowsingDataOnExitPageElementBase { + static get is() { + return 'settings-brave-clear-browsing-data-on-exit-page' + } - counters: { - type: Object, - // Will be filled as results are reported. - value: function() { - return {}; - } - }, + static get template() { + return getTemplate() + } - isModified: { - type: Boolean, - value: false, - }, + static getProperties() { + return { + prefs: { + type: Object, + notify: true, + }, + + counters: { + type: Object, + // Will be filled as results are reported. + value() { + return {} + } + }, - isChildAccount_: { - type: Boolean, - value: function() { - return loadTimeData.getBoolean('isChildAccount'); + isModified_: { + type: Boolean, + value: false, }, - }, - isAIChatAndHistoryAllowed_: { - type: Boolean, - value: function() { - return loadTimeData.getBoolean('isLeoAssistantAllowed') - && loadTimeData.getBoolean('isLeoAssistantHistoryAllowed'); + isChildAccount_: { + type: Boolean, + value() { + return loadTimeData.getBoolean('isChildAccount') + }, }, + + isAIChatAndHistoryAllowed_: { + type: Boolean, + value() { + return loadTimeData.getBoolean('isLeoAssistantAllowed') + && loadTimeData.getBoolean('isLeoAssistantHistoryAllowed') + }, + } } - }, + } + + public isModified_: boolean + + private counters: {[k: string]: string} = {} + private isChildAccount_: boolean + private isAIChatAndHistoryAllowed_: boolean - listeners: {'settings-boolean-control-change': 'updateModified_'}, + override ready() { + super.ready() + this.addEventListener( + 'settings-boolean-control-change', this.updateModified_) + } - setCounter: function (counter: string, text: string) { - this.set('counters.' + counter, text); - }, + public setCounter(counter: string, text: string) { + this.set('counters.' + counter, text) + } - getChangedSettings: function () { - let changed: {key: string, value: boolean}[] = []; - const boxes = this.$.checkboxes.querySelectorAll('settings-checkbox'); + public getChangedSettings() { + let changed: Array<{key: string, value: boolean}> = [] + const boxes = this.$.checkboxes.querySelectorAll('settings-checkbox') boxes.forEach((checkbox) => { - if (checkbox.checked != this.get(checkbox.pref.key, this.prefs).value) { - changed.push({key:checkbox.pref.key, value:checkbox.checked}); + if (checkbox.checked !== this.get(checkbox.pref!.key, this.prefs).value) { + changed.push({key:checkbox.pref!.key, value:checkbox.checked}) } }) return changed } - updateModified_: function () { - let modified = false; - const boxes = this.$.checkboxes.querySelectorAll('settings-checkbox'); + private updateModified_() { + let modified = false + const boxes = this.$.checkboxes.querySelectorAll('settings-checkbox') for (let checkbox of boxes) { - if (checkbox.checked != this.get(checkbox.pref.key, this.prefs).value) { - modified = true; - break; + if (checkbox.checked !== this.get(checkbox.pref!.key, this.prefs).value) { + modified = true + break } } - if (this.isModified !== modified) { - this.isModified = modified; - this.fire('clear-data-on-exit-page-change'); + if (this.isModified_ !== modified) { + this.isModified_ = modified + this.fire('clear-data-on-exit-page-change') } - }, -}); + } +} + +customElements.define( + SettingsBraveClearBrowsingDataOnExitPageElement.is, + SettingsBraveClearBrowsingDataOnExitPageElement) diff --git a/browser/resources/settings/brave_overrides/about_page.ts b/browser/resources/settings/brave_overrides/about_page.ts index 20cd5f0bc9f4..19fd5f28fc72 100644 --- a/browser/resources/settings/brave_overrides/about_page.ts +++ b/browser/resources/settings/brave_overrides/about_page.ts @@ -3,9 +3,12 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this file, // you can obtain one at https://mozilla.org/MPL/2.0/. -// @ts-nocheck TODO(petemill): Define types and remove ts-nocheck +import {html} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js' -import {html, RegisterPolymerTemplateModifications, RegisterStyleOverride} from 'chrome://resources/brave/polymer_overriding.js' +import { + RegisterPolymerTemplateModifications, + RegisterStyleOverride +} from 'chrome://resources/brave/polymer_overriding.js' import {getSectionElement} from './basic_page.js' @@ -24,27 +27,34 @@ RegisterStyleOverride( RegisterPolymerTemplateModifications({ 'settings-about-page': (templateContent) => { const section = getSectionElement(templateContent, 'about') + if (!section) { + console.error('[Settings] Could not find about section') + return + } if (!section.querySelector('a#release-notes')) { const version = section.querySelector('#updateStatusMessage ~ .secondary') if (!version) { - console.error('[Brave Settings Overrides] Could not find version div') + console.error('[Settings] Could not find version div') + return } // Remove the class from the version, so we take the link styling. version.removeAttribute('class') - const parent = version.parentNode const wrapper = document.createElement('a') wrapper.setAttribute('id', 'release-notes') wrapper.setAttribute('target', '_blank') wrapper.setAttribute('rel', 'noopener noreferrer') wrapper.setAttribute('href', 'https://brave.com/latest/') - parent.replaceChild(wrapper, version) + + const parent = version.parentNode + parent?.replaceChild(wrapper, version) wrapper.appendChild(version) } // Help link shown if update fails - const updateStatusMessageLink = section.querySelector('#updateStatusMessage a') + const updateStatusMessageLink = + section.querySelector('#updateStatusMessage a') if (updateStatusMessageLink) { // updateStatusMessageLink.href = diff --git a/browser/resources/settings/brave_overrides/basic_page.ts b/browser/resources/settings/brave_overrides/basic_page.ts index 03b0e1db6fe9..46f079ee32de 100644 --- a/browser/resources/settings/brave_overrides/basic_page.ts +++ b/browser/resources/settings/brave_overrides/basic_page.ts @@ -23,7 +23,11 @@ import '../social_blocking_page/social_blocking_page.js' import '../brave_leo_assistant_page/brave_leo_assistant_page.js' import '../brave_leo_assistant_page/model_list_section.js' -import {html, RegisterPolymerTemplateModifications, RegisterStyleOverride} from 'chrome://resources/brave/polymer_overriding.js' +import { + html, + RegisterPolymerTemplateModifications, + RegisterStyleOverride +} from 'chrome://resources/brave/polymer_overriding.js' import {loadTimeData} from '../i18n_setup.js' diff --git a/browser/resources/settings/brave_overrides/clear_browsing_data_dialog.ts b/browser/resources/settings/brave_overrides/clear_browsing_data_dialog.ts index 63352e217a00..0f98fe05bd8e 100644 --- a/browser/resources/settings/brave_overrides/clear_browsing_data_dialog.ts +++ b/browser/resources/settings/brave_overrides/clear_browsing_data_dialog.ts @@ -3,13 +3,19 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this file, // you can obtain one at https://mozilla.org/MPL/2.0/. -// @ts-nocheck TODO(petemill): Define types and remove ts-nocheck +import { + RegisterPolymerComponentReplacement, + RegisterPolymerTemplateModifications, + RegisterStyleOverride +} from 'chrome://resources/brave/polymer_overriding.js' -import {RegisterPolymerComponentReplacement, RegisterPolymerTemplateModifications, RegisterStyleOverride} from 'chrome://resources/brave/polymer_overriding.js' import {getTrustedHTML} from 'chrome://resources/js/static_types.js' import {html} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js' -import {BraveSettingsClearBrowsingDataDialogElement} from '../brave_clear_browsing_data_dialog/brave_clear_browsing_data_dialog_behavior.js' +import { + BraveSettingsClearBrowsingDataDialogElement +} from '../brave_clear_browsing_data_dialog/brave_clear_browsing_data_dialog_behavior.js' + import {loadTimeData} from '../i18n_setup.js' RegisterStyleOverride( @@ -33,7 +39,7 @@ RegisterPolymerComponentReplacement( ) RegisterPolymerTemplateModifications({ - 'settings-clear-browsing-data-dialog': (templateContent: HTMLTemplateElement) => { + 'settings-clear-browsing-data-dialog': (templateContent) => { // Append On exit tab page. const pagesElement = templateContent.querySelector('#pages') if (!pagesElement) { diff --git a/browser/resources/settings/brave_overrides/default_browser_page.ts b/browser/resources/settings/brave_overrides/default_browser_page.ts index bbd2ffd42259..eeb741aef745 100644 --- a/browser/resources/settings/brave_overrides/default_browser_page.ts +++ b/browser/resources/settings/brave_overrides/default_browser_page.ts @@ -3,18 +3,19 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this file, // you can obtain one at https://mozilla.org/MPL/2.0/. -// @ts-nocheck TODO(petemill): Define types and remove ts-nocheck - import {RegisterPolymerTemplateModifications} from 'chrome://resources/brave/polymer_overriding.js' -function queryInAllTemplates(element, selector, onFound) { - if (!element) { +function queryInAllTemplates( + fragment: DocumentFragment, + selector: string, + onFound: (element: Element) => void) { + if (!fragment) { return } - for (const foundElement of element.querySelectorAll(selector)) { + for (const foundElement of fragment.querySelectorAll(selector)) { onFound(foundElement) } - for (const foundTemplate of element.querySelectorAll('template')) { + for (const foundTemplate of fragment.querySelectorAll('template')) { if (foundTemplate.content) { queryInAllTemplates(foundTemplate.content, selector, onFound) } @@ -25,8 +26,9 @@ RegisterPolymerTemplateModifications({ 'settings-default-browser-page': (templateContent) => { // Stop both versions thinking they are the first, since this item is added // to Brave's "Get Started" section. - queryInAllTemplates(templateContent, '.cr-row.first', function (element) { - element.classList.remove('first') + queryInAllTemplates(templateContent, '.cr-row.first', + element => { + element.classList.remove('first') }) } }) diff --git a/browser/resources/settings/brave_overrides/import_data_dialog.ts b/browser/resources/settings/brave_overrides/import_data_dialog.ts index 9e98854d4fa1..29d76ed3a010 100644 --- a/browser/resources/settings/brave_overrides/import_data_dialog.ts +++ b/browser/resources/settings/brave_overrides/import_data_dialog.ts @@ -3,15 +3,17 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this file, // you can obtain one at https://mozilla.org/MPL/2.0/. -// @ts-nocheck TODO(petemill): Define types and remove ts-nocheck +import { + html, + RegisterPolymerTemplateModifications +} from 'chrome://resources/brave/polymer_overriding.js' -import {html, RegisterPolymerTemplateModifications} from 'chrome://resources/brave/polymer_overriding.js' import {loadTimeData} from 'chrome://resources/js/load_time_data.js' RegisterPolymerTemplateModifications({ 'settings-import-data-dialog': (templateContent) => { - let checkBoxesParent = - templateContent.querySelector('#browserSelect').parentElement + const checkBoxesParent = + templateContent.querySelector('#browserSelect')!.parentElement checkBoxesParent.appendChild(html`