Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove ts-nocheck from brave://settings files #27107

Merged
merged 3 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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',
emerick marked this conversation as resolved.
Show resolved Hide resolved
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
}
emerick marked this conversation as resolved.
Show resolved Hide resolved

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_ = () => {}
}
emerick marked this conversation as resolved.
Show resolved Hide resolved

/**
* 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)
}
fallaciousreasoning marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* 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
Loading