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

Sync theme between windows #2090

Merged
merged 4 commits into from
Mar 5, 2022
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
55 changes: 30 additions & 25 deletions src/renderer/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,18 @@ export default Vue.extend({
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 () {
return [
this.$t('Yes'),
Expand All @@ -114,6 +126,13 @@ export default Vue.extend({
},
watch: {
windowTitle: 'setWindowTitle',

baseTheme: 'checkThemeSettings',

mainColor: 'checkThemeSettings',

secColor: 'checkThemeSettings',

$route () {
// react to route changes...
// Hide top nav filter panel on page change
Expand Down Expand Up @@ -160,39 +179,22 @@ export default Vue.extend({
},
methods: {
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 = {
baseTheme: baseTheme,
mainColor: mainColor,
secColor: secColor
baseTheme: this.baseTheme || 'dark',
mainColor: this.mainColor || 'mainRed',
secColor: this.secColor || 'secBlue'
}

this.updateTheme(theme)
},

updateTheme: function (theme) {
console.log(theme)
const className = `${theme.baseTheme} ${theme.mainColor} ${theme.secColor}`
console.group('updateTheme')
console.log('Theme: ', theme)
const className = `${theme.baseTheme} main${theme.mainColor} sec${theme.secColor}`
const body = document.getElementsByTagName('body')[0]
body.className = className
localStorage.setItem('baseTheme', theme.baseTheme)
localStorage.setItem('mainColor', theme.mainColor)
localStorage.setItem('secColor', theme.secColor)
console.groupEnd()
},

checkForNewUpdates: function () {
Expand Down Expand Up @@ -473,7 +475,10 @@ export default Vue.extend({
'getExternalPlayerCmdArgumentsData',
'fetchInvidiousInstances',
'setRandomCurrentInvidiousInstance',
'setupListenersToSyncWindows'
'setupListenersToSyncWindows',
'updateBaseTheme',
'updateMainColor',
'updateSecColor'
])
}
})
75 changes: 23 additions & 52 deletions src/renderer/components/theme-settings/theme-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ export default Vue.extend({
},
data: function () {
return {
currentBaseTheme: '',
currentMainColor: '',
currentSecColor: '',
expandSideBar: false,
minUiScale: 50,
maxUiScale: 300,
uiScaleStep: 5,
Expand Down Expand Up @@ -70,6 +66,18 @@ export default Vue.extend({
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 () {
return this.$store.getters.getIsSideNavOpen
},
Expand All @@ -81,9 +89,15 @@ export default Vue.extend({
disableSmoothScrolling: function () {
return this.$store.getters.getDisableSmoothScrolling
},

expandSideBar: function () {
return this.$store.getters.getExpandSideBar
},

hideLabelsSideBar: function () {
return this.$store.getters.getHideLabelsSideBar
},

restartPromptMessage: function () {
return this.$t('Settings["The app needs to restart for changes to take effect. Restart and apply change?"]')
},
Expand Down Expand Up @@ -133,34 +147,15 @@ export default Vue.extend({
}
},
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
},
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) {
if (this.isSideNavOpen !== value) {
this.$store.commit('toggleSideNav')
}

this.expandSideBar = value
localStorage.setItem('expandSideBar', value)
this.updateExpandSideBar(value)
},

handleRestartPrompt: function (value) {
Expand All @@ -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([
'updateBarColor',
'updateBaseTheme',
'updateMainColor',
'updateSecColor',
'updateExpandSideBar',
'updateUiScale',
'updateDisableSmoothScrolling',
'updateHideLabelsSideBar'
Expand Down
6 changes: 3 additions & 3 deletions src/renderer/components/theme-settings/theme-settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,21 @@
<ft-flex-box>
<ft-select
:placeholder="$t('Settings.Theme Settings.Base Theme.Base Theme')"
:value="currentBaseTheme"
:value="baseTheme"
:select-names="baseThemeNames"
:select-values="baseThemeValues"
@change="updateBaseTheme"
/>
<ft-select
:placeholder="$t('Settings.Theme Settings.Main Color Theme.Main Color Theme')"
:value="currentMainColor"
:value="mainColor"
:select-names="colorNames"
:select-values="colorValues"
@change="updateMainColor"
/>
<ft-select
:placeholder="$t('Settings.Theme Settings.Secondary Color Theme')"
:value="currentSecColor"
:value="secColor"
:select-names="colorNames"
:select-values="colorValues"
@change="updateSecColor"
Expand Down
13 changes: 10 additions & 3 deletions src/renderer/components/top-nav/top-nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ export default Vue.extend({
return this.$store.getters.getBackendPreference
},

expandSideBar: function () {
return this.$store.getters.getExpandSideBar
},

forwardText: function () {
return this.$t('Forward')
},
Expand All @@ -80,9 +84,12 @@ export default Vue.extend({
searchContainer.style.display = 'none'
}

if (localStorage.getItem('expandSideBar') === 'true') {
this.toggleSideNav()
}
// Store is not up-to-date when the component mounts, so we use timeout.
setTimeout(() => {
if (this.expandSideBar) {
this.toggleSideNav()
}
}, 0)

window.addEventListener('resize', function (event) {
const width = event.srcElement.innerWidth
Expand Down
5 changes: 4 additions & 1 deletion src/renderer/store/modules/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ const state = {
barColor: false,
checkForBlogPosts: true,
checkForUpdates: true,
// currentTheme: 'lightRed',
baseTheme: 'dark',
mainColor: 'Red',
secColor: 'Blue',
defaultCaptionSettings: '{}',
defaultInterval: 5,
defaultPlayback: 1,
Expand All @@ -185,6 +187,7 @@ const state = {
externalPlayerExecutable: '',
externalPlayerIgnoreWarnings: false,
externalPlayerCustomArgs: '',
expandSideBar: false,
forceLocalBackendForLegacy: false,
hideActiveSubscriptions: false,
hideChannelSubscriptions: false,
Expand Down