Skip to content

Commit

Permalink
Merge pull request #27107 from brave/emerick-remove-ts-nocheck-from-s…
Browse files Browse the repository at this point in the history
…ettings-files

Remove ts-nocheck from brave://settings files
  • Loading branch information
emerick authored Jan 7, 2025
2 parents 0a999fb + c45e471 commit feab1f7
Show file tree
Hide file tree
Showing 35 changed files with 1,448 additions and 1,130 deletions.
Original file line number Diff line number Diff line change
@@ -1,151 +1,168 @@
// @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) => {
this.braveRewardsEnabled_ = enabled;
'brave-rewards-enabled-changed', (enabled: boolean) => {
this.braveRewardsEnabled_ = enabled
})

this.clearDataBrowserProxy_.getBraveRewardsEnabled().then((enabled) => {
this.braveRewardsEnabled_ = enabled;
this.braveRewardsEnabled_ = enabled
})
}

override connectedCallback() {
super.connectedCallback();
super.connectedCallback()

this.onSelectedPageChangedCallback_ = this.onSelectedPageChanged_.bind(this);
this.onSelectedPageChangedCallback_ = this.onSelectedPageChanged_.bind(this)
this.$.pages.addEventListener('iron-select',
this.onSelectedPageChangedCallback_);
this.onSelectedPageChangedCallback_)

this.updateSaveButtonStateCallback_ = this.updateSaveButtonState_.bind(this);
this.shadowRoot.querySelector('#on-exit-tab').addEventListener(
'clear-data-on-exit-page-change', this.updateSaveButtonStateCallback_);
this.updateSaveButtonStateCallback_ = this.updateSaveButtonState_.bind(this)
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);
this.onClearBraveAdsDataClickHandler_ = this.clearBraveAdsData_.bind(this)
}

override disconnectedCallback() {
super.disconnectedCallback()

if (this.onSelectedPageChangedCallback_) {
this.$.pages.removeEventListener('selected-item-changed',
this.onSelectedPageChangedCallback_);
this.onSelectedPageChangedCallback_ = null;
this.onSelectedPageChangedCallback_)
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_ = () => {};
this.onClearBraveAdsDataClickHandler_ = () => {}
}

/**
* Updates the text of a browsing data counter corresponding to the given
* 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.<datatype>".
// Strip the common prefix, i.e. use only "<datatype>".
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<SettingsBraveClearBrowsingDataOnExitPageElement>(
'#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;
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<CrButtonElement>(
'#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<CrButtonElement>('#saveOnExitSettingsConfirm')
if (saveButton) {
saveButton.disabled = !this.shadowRoot!.
querySelector<SettingsBraveClearBrowsingDataOnExitPageElement>(
'#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<SettingsBraveClearBrowsingDataOnExitPageElement>(
'#on-exit-tab')!.getChangedSettings()
changed.forEach((change) => {
this.set('prefs.' + change.key + '.value', change.value);
});
this.updateSaveButtonState_();
if (!this.clearingInProgress_) {
this.$.clearBrowsingDataDialog.close();
this.set('prefs.' + change.key + '.value', change.value)
})
this.updateSaveButtonState_()
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()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,28 @@
* 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/. */

import {sendWithPromise} from 'chrome://resources/js/cr.js';
import {sendWithPromise} from 'chrome://resources/js/cr.js'

export interface BraveClearBrowsingDataDialogBrowserProxy {
getBraveRewardsEnabled(): Promise<boolean>;
clearBraveAdsData(): void;
getBraveRewardsEnabled: () => Promise<boolean>
clearBraveAdsData: () => void
}

export class BraveClearBrowsingDataDialogBrowserProxyImpl
implements BraveClearBrowsingDataDialogBrowserProxy {

getBraveRewardsEnabled() {
return sendWithPromise('getBraveRewardsEnabled');
return sendWithPromise('getBraveRewardsEnabled')
}

clearBraveAdsData() {
chrome.send('clearBraveAdsData');
chrome.send('clearBraveAdsData')
}

static getInstance(): BraveClearBrowsingDataDialogBrowserProxyImpl {
return instance ||
(instance = new BraveClearBrowsingDataDialogBrowserProxyImpl());
(instance = new BraveClearBrowsingDataDialogBrowserProxyImpl())
}
}

let instance: BraveClearBrowsingDataDialogBrowserProxyImpl|null = null;
let instance: BraveClearBrowsingDataDialogBrowserProxyImpl|null = null
Loading

0 comments on commit feab1f7

Please sign in to comment.