Sync theme between windows (#2090)

* Sync expandSideBar across tabs

* Sync baseTheme, mainColor, secColor between windows

* Fix lint errors

* Fix lint errors: electric boogaloo
This commit is contained in:
vallode 2022-03-05 09:09:32 +01:00 committed by GitHub
parent 2dd184fba3
commit 815c348948
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 70 additions and 84 deletions

View File

@ -101,6 +101,18 @@ export default Vue.extend({
return this.$store.getters.getDefaultInvidiousInstance return this.$store.getters.getDefaultInvidiousInstance
}, },
baseTheme: function () {
return this.$store.getters.getBaseTheme
},
mainColor: function () {
return this.$store.getters.getMainColor
},
secColor: function () {
return this.$store.getters.getSecColor
},
externalLinkOpeningPromptNames: function () { externalLinkOpeningPromptNames: function () {
return [ return [
this.$t('Yes'), this.$t('Yes'),
@ -114,6 +126,13 @@ export default Vue.extend({
}, },
watch: { watch: {
windowTitle: 'setWindowTitle', windowTitle: 'setWindowTitle',
baseTheme: 'checkThemeSettings',
mainColor: 'checkThemeSettings',
secColor: 'checkThemeSettings',
$route () { $route () {
// react to route changes... // react to route changes...
// Hide top nav filter panel on page change // Hide top nav filter panel on page change
@ -160,39 +179,22 @@ export default Vue.extend({
}, },
methods: { methods: {
checkThemeSettings: function () { checkThemeSettings: function () {
let baseTheme = localStorage.getItem('baseTheme')
let mainColor = localStorage.getItem('mainColor')
let secColor = localStorage.getItem('secColor')
if (baseTheme === null) {
baseTheme = 'dark'
}
if (mainColor === null) {
mainColor = 'mainRed'
}
if (secColor === null) {
secColor = 'secBlue'
}
const theme = { const theme = {
baseTheme: baseTheme, baseTheme: this.baseTheme || 'dark',
mainColor: mainColor, mainColor: this.mainColor || 'mainRed',
secColor: secColor secColor: this.secColor || 'secBlue'
} }
this.updateTheme(theme) this.updateTheme(theme)
}, },
updateTheme: function (theme) { updateTheme: function (theme) {
console.log(theme) console.group('updateTheme')
const className = `${theme.baseTheme} ${theme.mainColor} ${theme.secColor}` console.log('Theme: ', theme)
const className = `${theme.baseTheme} main${theme.mainColor} sec${theme.secColor}`
const body = document.getElementsByTagName('body')[0] const body = document.getElementsByTagName('body')[0]
body.className = className body.className = className
localStorage.setItem('baseTheme', theme.baseTheme) console.groupEnd()
localStorage.setItem('mainColor', theme.mainColor)
localStorage.setItem('secColor', theme.secColor)
}, },
checkForNewUpdates: function () { checkForNewUpdates: function () {
@ -473,7 +475,10 @@ export default Vue.extend({
'getExternalPlayerCmdArgumentsData', 'getExternalPlayerCmdArgumentsData',
'fetchInvidiousInstances', 'fetchInvidiousInstances',
'setRandomCurrentInvidiousInstance', 'setRandomCurrentInvidiousInstance',
'setupListenersToSyncWindows' 'setupListenersToSyncWindows',
'updateBaseTheme',
'updateMainColor',
'updateSecColor'
]) ])
} }
}) })

View File

@ -19,10 +19,6 @@ export default Vue.extend({
}, },
data: function () { data: function () {
return { return {
currentBaseTheme: '',
currentMainColor: '',
currentSecColor: '',
expandSideBar: false,
minUiScale: 50, minUiScale: 50,
maxUiScale: 300, maxUiScale: 300,
uiScaleStep: 5, uiScaleStep: 5,
@ -70,6 +66,18 @@ export default Vue.extend({
return this.$store.getters.getBarColor return this.$store.getters.getBarColor
}, },
baseTheme: function () {
return this.$store.getters.getBaseTheme
},
mainColor: function () {
return this.$store.getters.getMainColor
},
secColor: function () {
return this.$store.getters.getSecColor
},
isSideNavOpen: function () { isSideNavOpen: function () {
return this.$store.getters.getIsSideNavOpen return this.$store.getters.getIsSideNavOpen
}, },
@ -81,9 +89,15 @@ export default Vue.extend({
disableSmoothScrolling: function () { disableSmoothScrolling: function () {
return this.$store.getters.getDisableSmoothScrolling return this.$store.getters.getDisableSmoothScrolling
}, },
expandSideBar: function () {
return this.$store.getters.getExpandSideBar
},
hideLabelsSideBar: function () { hideLabelsSideBar: function () {
return this.$store.getters.getHideLabelsSideBar return this.$store.getters.getHideLabelsSideBar
}, },
restartPromptMessage: function () { restartPromptMessage: function () {
return this.$t('Settings["The app needs to restart for changes to take effect. Restart and apply change?"]') return this.$t('Settings["The app needs to restart for changes to take effect. Restart and apply change?"]')
}, },
@ -133,34 +147,15 @@ export default Vue.extend({
} }
}, },
mounted: function () { mounted: function () {
this.currentBaseTheme = localStorage.getItem('baseTheme')
this.currentMainColor = localStorage.getItem('mainColor').replace('main', '')
this.currentSecColor = localStorage.getItem('secColor').replace('sec', '')
this.expandSideBar = localStorage.getItem('expandSideBar') === 'true'
this.disableSmoothScrollingToggleValue = this.disableSmoothScrolling this.disableSmoothScrollingToggleValue = this.disableSmoothScrolling
}, },
methods: { methods: {
updateBaseTheme: function (theme) {
const mainColor = `main${this.currentMainColor}`
const secColor = `sec${this.currentSecColor}`
const payload = {
baseTheme: theme,
mainColor: mainColor,
secColor: secColor
}
this.$parent.$parent.updateTheme(payload)
this.currentBaseTheme = theme
},
handleExpandSideBar: function (value) { handleExpandSideBar: function (value) {
if (this.isSideNavOpen !== value) { if (this.isSideNavOpen !== value) {
this.$store.commit('toggleSideNav') this.$store.commit('toggleSideNav')
} }
this.expandSideBar = value this.updateExpandSideBar(value)
localStorage.setItem('expandSideBar', value)
}, },
handleRestartPrompt: function (value) { handleRestartPrompt: function (value) {
@ -186,36 +181,12 @@ export default Vue.extend({
}) })
}, },
updateMainColor: function (color) {
const mainColor = `main${color}`
const secColor = `sec${this.currentSecColor}`
const payload = {
baseTheme: this.currentBaseTheme,
mainColor: mainColor,
secColor: secColor
}
this.$parent.$parent.updateTheme(payload)
this.currentMainColor = color
},
updateSecColor: function (color) {
const mainColor = `main${this.currentMainColor}`
const secColor = `sec${color}`
const payload = {
baseTheme: this.currentBaseTheme,
mainColor: mainColor,
secColor: secColor
}
this.$parent.$parent.updateTheme(payload)
this.currentSecColor = color
},
...mapActions([ ...mapActions([
'updateBarColor', 'updateBarColor',
'updateBaseTheme',
'updateMainColor',
'updateSecColor',
'updateExpandSideBar',
'updateUiScale', 'updateUiScale',
'updateDisableSmoothScrolling', 'updateDisableSmoothScrolling',
'updateHideLabelsSideBar' 'updateHideLabelsSideBar'

View File

@ -43,21 +43,21 @@
<ft-flex-box> <ft-flex-box>
<ft-select <ft-select
:placeholder="$t('Settings.Theme Settings.Base Theme.Base Theme')" :placeholder="$t('Settings.Theme Settings.Base Theme.Base Theme')"
:value="currentBaseTheme" :value="baseTheme"
:select-names="baseThemeNames" :select-names="baseThemeNames"
:select-values="baseThemeValues" :select-values="baseThemeValues"
@change="updateBaseTheme" @change="updateBaseTheme"
/> />
<ft-select <ft-select
:placeholder="$t('Settings.Theme Settings.Main Color Theme.Main Color Theme')" :placeholder="$t('Settings.Theme Settings.Main Color Theme.Main Color Theme')"
:value="currentMainColor" :value="mainColor"
:select-names="colorNames" :select-names="colorNames"
:select-values="colorValues" :select-values="colorValues"
@change="updateMainColor" @change="updateMainColor"
/> />
<ft-select <ft-select
:placeholder="$t('Settings.Theme Settings.Secondary Color Theme')" :placeholder="$t('Settings.Theme Settings.Secondary Color Theme')"
:value="currentSecColor" :value="secColor"
:select-names="colorNames" :select-names="colorNames"
:select-values="colorValues" :select-values="colorValues"
@change="updateSecColor" @change="updateSecColor"

View File

@ -60,6 +60,10 @@ export default Vue.extend({
return this.$store.getters.getBackendPreference return this.$store.getters.getBackendPreference
}, },
expandSideBar: function () {
return this.$store.getters.getExpandSideBar
},
forwardText: function () { forwardText: function () {
return this.$t('Forward') return this.$t('Forward')
}, },
@ -80,9 +84,12 @@ export default Vue.extend({
searchContainer.style.display = 'none' searchContainer.style.display = 'none'
} }
if (localStorage.getItem('expandSideBar') === 'true') { // Store is not up-to-date when the component mounts, so we use timeout.
this.toggleSideNav() setTimeout(() => {
} if (this.expandSideBar) {
this.toggleSideNav()
}
}, 0)
window.addEventListener('resize', function (event) { window.addEventListener('resize', function (event) {
const width = event.srcElement.innerWidth const width = event.srcElement.innerWidth

View File

@ -167,7 +167,9 @@ const state = {
barColor: false, barColor: false,
checkForBlogPosts: true, checkForBlogPosts: true,
checkForUpdates: true, checkForUpdates: true,
// currentTheme: 'lightRed', baseTheme: 'dark',
mainColor: 'Red',
secColor: 'Blue',
defaultCaptionSettings: '{}', defaultCaptionSettings: '{}',
defaultInterval: 5, defaultInterval: 5,
defaultPlayback: 1, defaultPlayback: 1,
@ -185,6 +187,7 @@ const state = {
externalPlayerExecutable: '', externalPlayerExecutable: '',
externalPlayerIgnoreWarnings: false, externalPlayerIgnoreWarnings: false,
externalPlayerCustomArgs: '', externalPlayerCustomArgs: '',
expandSideBar: false,
forceLocalBackendForLegacy: false, forceLocalBackendForLegacy: false,
hideActiveSubscriptions: false, hideActiveSubscriptions: false,
hideChannelSubscriptions: false, hideChannelSubscriptions: false,