Skip to content

Commit

Permalink
Merge pull request #24391 from brave/cr127-followup-remove-redundant-…
Browse files Browse the repository at this point in the history
…sidepanel-settings

Remove redundant side panel settings
  • Loading branch information
emerick committed Jun 26, 2024
1 parent 7608f3b commit 43a939f
Showing 1 changed file with 41 additions and 28 deletions.
69 changes: 41 additions & 28 deletions browser/resources/settings/brave_overrides/appearance_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
// 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 '../brave_appearance_page/super_referral.js'
import '../brave_appearance_page/brave_theme.js'

Expand All @@ -20,18 +18,18 @@ RegisterPolymerTemplateModifications({
'settings-appearance-page': (templateContent) => {
const theme = templateContent.getElementById('themeRow')
if (!theme) {
console.error(`[Brave Settings Overrides] Couldn't find #themeRow`)
console.error(`[Settings] Couldn't find #themeRow`)
} else {
const useDefaultButtonTemplate = templateContent.querySelector(
'template[is=dom-if][if="[[prefs.extensions.theme.id.value]]"]')
if (!useDefaultButtonTemplate) {
console.error(
'[Brave Settings Overrides] Appearance Page cannot find use default' +
'[Settings] Appearance Page cannot find use default' +
' theme button template')
} else {
useDefaultButtonTemplate.setAttribute("restamp", "true")
useDefaultButtonTemplate.setAttribute('restamp', 'true')
}
theme.setAttribute("class", "settings-row hr")
theme.setAttribute('class', 'settings-row hr')
theme.insertAdjacentHTML(
'beforebegin',
getTrustedHTML`
Expand All @@ -49,13 +47,13 @@ RegisterPolymerTemplateModifications({
)
if (hasSuperReferral) {
// Routes
const r = Router.getInstance().routes_
const r = Router.getInstance().getRoutes()
if (!r.APPEARANCE) {
console.error(
'[Brave Settings Overrides] Routes: could not find APPEARANCE page')
'[Settings] Routes: could not find APPEARANCE page')
return
} else {
r.THEMES = r.APPEARANCE.createChild('/themes');
r.THEMES = r.APPEARANCE.createChild('/themes')
// Hide chromium's theme section. It's replaced with our themes page.
if (theme) {
theme.remove()
Expand All @@ -65,7 +63,7 @@ RegisterPolymerTemplateModifications({
const pages = templateContent.getElementById('pages')
if (!pages) {
console.error(
`[Brave Settings Overrides] Couldn't find appearance_page #pages`)
`[Settings] Couldn't find appearance_page #pages`)
} else {
pages.appendChild(
html`
Expand All @@ -87,15 +85,15 @@ RegisterPolymerTemplateModifications({
'[pref="{{prefs.browser.show_home_button}}"]')
if (!homeButtonToggle) {
console.error(
`[Brave Settings Overrides] Couldn't find home button toggle`)
`[Settings] Couldn't find home button toggle`)
} else {
homeButtonToggle.remove()
}
const homeButtonOptionsTemplate = templateContent.querySelector(
'template[is=dom-if][if="[[prefs.browser.show_home_button.value]]"]')
if (!homeButtonOptionsTemplate) {
console.error(
`[Brave Settings Overrides] Couldn't find home button options template`)
`[Settings] Couldn't find home button options template`)
} else {
homeButtonOptionsTemplate.remove()
}
Expand All @@ -104,7 +102,7 @@ RegisterPolymerTemplateModifications({
'[pref="{{prefs.bookmark_bar.show_on_all_tabs}}"]')
if (!bookmarkBarToggle) {
console.error(
`[Brave Settings Overrides] Couldn't find bookmark bar toggle`)
`[Settings] Couldn't find bookmark bar toggle`)
} else {
// Remove Chromium bookmark toggle becasue it is replaced by
// settings-brave-appearance-bookmark-bar
Expand All @@ -115,54 +113,55 @@ RegisterPolymerTemplateModifications({
const defaultFontSize = templateContent.querySelector(
'.cr-row:has(#defaultFontSize)')
if (!defaultFontSize) {
console.error(`[Brave Settings Overrides] Couldn't find default font size option`)
console.error(`[Settings] Couldn't find default font size option`)
} else {
// Just hide instead of removing as upstream js refers this.
defaultFontSize.setAttribute("hidden", "true")
defaultFontSize.setAttribute('hidden', 'true')
}
const customizeFontsSubpageTrigger = templateContent.getElementById('customize-fonts-subpage-trigger')
if (!customizeFontsSubpageTrigger) {
console.error(`[Brave Settings Overrides] Couldn't find customize fonts subpage trigger`)
console.error(`[Settings] Couldn't find customize fonts subpage trigger`)
} else {
customizeFontsSubpageTrigger.remove()
}
const customizeFontsTemplate = templateContent.querySelector(
'template[is=dom-if][route-path="/fonts"]')
if (!customizeFontsTemplate) {
console.error(`[Brave Settings Overrides] Couldn't find customize fonts subpage template`)
console.error(`[Settings] Couldn't find customize fonts subpage template`)
} else {
customizeFontsTemplate.remove()
}
const pageZoom = templateContent.querySelector('.cr-row:has(#pageZoom)')
if (!pageZoom) {
console.error(`[Brave Settings Overrides] Couldn't find page zoom`)
console.error(`[Settings] Couldn't find page zoom`)
} else {
pageZoom.remove()
}

const hrsToHide = templateContent.querySelectorAll('div.hr:not(#themeRow):not([hidden="[[!pageVisibility.bookmarksBar]]"])');
const hrsToHide = templateContent.querySelectorAll(
'div.hr:not(#themeRow):not([hidden="[[!pageVisibility.bookmarksBar]]"])')
// We only want to hide two hrs now from upstream appearance_page.html.
if (hrsToHide.length !== 2) {
console.error(`[Brave Settings Overrides] detected more than two hrs to hide`)
console.error(`[Settings] detected more than two hrs to hide`)
} else {
for (const hr of hrsToHide) {
hr.setAttribute("hidden", "true")
hr.setAttribute('hidden', 'true')
}
}

// <if expr="is_macosx">
const confirmToQuit = templateContent.querySelector(
'[pref="{{prefs.browser.confirm_to_quit}}"]')
if (!confirmToQuit) {
console.error(`[Brave Settings Overrides] Couldn't find confirm to quit`)
console.error(`[Settings] Couldn't find confirm to quit`)
} else {
confirmToQuit.remove()
}

const tabsToLinks = templateContent.querySelector(
'[pref="{{prefs.webkit.webprefs.tabs_to_links}}"]')
if (!tabsToLinks) {
console.error(`[Brave Settings Overrides] Couldn't find tabs to links`)
console.error(`[Settings] Couldn't find tabs to links`)
} else {
tabsToLinks.remove()
}
Expand All @@ -174,7 +173,7 @@ RegisterPolymerTemplateModifications({
'template[is=dom-if][if="[[!showHoverCardImagesOption_]]"]')
if (!hoverCardImagesTemplateNotShow) {
console.error(
'[Brave Settings Overrides] Appearance Page cannot find hover card' +
'[Settings] Appearance Page cannot find hover card' +
' images template with !showHoverCardImagesOption_')
} else {
hoverCardImagesTemplateNotShow.remove()
Expand All @@ -183,18 +182,32 @@ RegisterPolymerTemplateModifications({
'template[is=dom-if][if="[[showHoverCardImagesOption_]]"]')
if (!hoverCardImagesTemplateShow) {
console.error(
'[Brave Settings Overrides] Appearance Page cannot find hover card' +
'[Settings] Appearance Page cannot find hover card' +
' images template with showHoverCardImagesOption_')
} else {
hoverCardImagesTemplateShow.remove()
}
const colorSchemeModeRow = templateContent.getElementById(
'colorSchemeModeRow')
if (!colorSchemeModeRow) {
console.error(
`[Brave Settings Overrides] Couldn't find colorSchemeModeRow`)
console.error(`[Settings] Couldn't find colorSchemeModeRow`)
} else {
colorSchemeModeRow.remove()
}
},

// Remove upstream side panel header and radio buttons from Appearance as we
// have our own separate side panel section
const sidePanelSettingsRadioGroup =
templateContent.getElementById('side-panel')
if (!sidePanelSettingsRadioGroup) {
console.error(`[Settings] Couldn't find side-panel`)
} else {
if (sidePanelSettingsRadioGroup.parentNode &&
sidePanelSettingsRadioGroup.parentNode.previousElementSibling) {
sidePanelSettingsRadioGroup.parentNode.previousElementSibling.
setAttribute('hidden', 'true')
}
sidePanelSettingsRadioGroup.setAttribute('hidden', 'true')
}
}
})

0 comments on commit 43a939f

Please sign in to comment.