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

Detect Dark Mode Settings #978

Merged
merged 10 commits into from
Mar 25, 2021
Merged

Detect Dark Mode Settings #978

merged 10 commits into from
Mar 25, 2021

Conversation

grolu
Copy link
Contributor

@grolu grolu commented Mar 18, 2021

What this PR does / why we need it:
With this PR the Dashboard can detect the system settings for dark mode

Screenshot 2021-03-22 at 13 26 03

Which issue(s) this PR fixes:
Fixes #

Special notes for your reviewer:

Release note:

Dark Mode: The Dashboard now applies system settings by default

@gardener-robot gardener-robot added needs/review Needs review size/s Size of pull request is small (see gardener-robot robot/bots/size.py) labels Mar 18, 2021
@gardener-robot-ci-3 gardener-robot-ci-3 added the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Mar 18, 2021
@gardener-robot-ci-1 gardener-robot-ci-1 added needs/ok-to-test Needs approval for testing (check PR in detail before setting this label because PR is run on CI/CD) and removed reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) labels Mar 18, 2021
@gardener-robot-ci-1 gardener-robot-ci-1 added reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) and removed reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) labels Mar 18, 2021
@gardener-robot-ci-1 gardener-robot-ci-1 added the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Mar 19, 2021
@gardener-robot-ci-2 gardener-robot-ci-2 removed the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Mar 19, 2021
state.darkMode = value
localStorage.setItem('global/dark-mode', value)
Vue.vuetify.framework.theme.dark = value
if (value !== undefined) {
Copy link
Member

@holgerkoser holgerkoser Mar 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my point of view this is an antipattern. A mutation should only mutate the store state and not run mediaqueries. The new value must come from outside the mutation.

Copy link
Member

@holgerkoser holgerkoser Mar 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should start using store plugins for this kind of problems.

export default function createMediaPlugin (window) {
  return store => {
    const colorScheme = window.localStorage.getItem('global/color-scheme')
    store.commit('SET_COLOR_SCHEME', colorScheme)
    const mq = window.matchMedia('(prefers-color-scheme: dark)')
    switch (store.state.coloScheme) {
      case 'dark':
        store.commit('SET_DARK_THEME', true)
        break
      case 'light':
        store.commit('SET_DARK_THEME', false)
        break
      default:
        store.commit('SET_DARK_THEME', mq.matches)
        break
    }
    mq.addEventListener(e => {
      if (!['dark', 'light'].includes(store.state.coloScheme)) {
        store.commit('SET_DARK_THEME', e.matches)
      }
    })
  }
}

@@ -21,8 +21,13 @@ const App = Vue.extend({
}
})

const darkMode = this.$localStorage.getItem('global/dark-mode') === 'true'
const darkMode = this.$localStorage.getItem('global/setting-dark-mode') || 2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why global/seeting-dark-mode and not global/dark-mode or global/settings/dark-mode?

Copy link
Member

@holgerkoser holgerkoser Mar 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would propose to have a localStorage porperty 'global/color-scheme' or 'global/settings/color-scheme' with possible values dark, light and any other value means use system settings

@gardener-robot-ci-1 gardener-robot-ci-1 added the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Mar 19, 2021
@gardener-robot gardener-robot added size/m Size of pull request is medium (see gardener-robot robot/bots/size.py) and removed size/s Size of pull request is small (see gardener-robot robot/bots/size.py) labels Mar 19, 2021
@gardener-robot-ci-2 gardener-robot-ci-2 removed the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Mar 19, 2021
@gardener-robot-ci-3 gardener-robot-ci-3 added reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) and removed reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) labels Mar 19, 2021
Comment on lines +227 to +245
return 0
case 'dark':
return 1
default:
return 2
}
},
set (value) {
this.setDarkMode(value)
switch (value) {
case 0:
this.setColorScheme('light')
break
case 1:
this.setColorScheme('dark')
break
default:
this.setColorScheme('auto')
break
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use constants instead of magic/index numbers

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@gardener-robot-ci-3 gardener-robot-ci-3 added the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Mar 22, 2021
Co-authored-by: Peter Sutter <peter.sutter@sap.com>
@gardener-robot-ci-1 gardener-robot-ci-1 removed the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Mar 22, 2021
@gardener-robot-ci-2 gardener-robot-ci-2 added the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Mar 22, 2021
@gardener-robot-ci-1 gardener-robot-ci-1 removed the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Mar 22, 2021
@gardener-robot-ci-2 gardener-robot-ci-2 added the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Mar 22, 2021
@gardener-robot-ci-3 gardener-robot-ci-3 removed the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Mar 22, 2021
Copy link
Member

@petersutter petersutter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@gardener-robot gardener-robot added reviewed/lgtm Has approval for merging and removed needs/review Needs review labels Mar 22, 2021
Copy link
Member

@holgerkoser holgerkoser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@grolu grolu merged commit b2d0499 into master Mar 25, 2021
@grolu grolu deleted the detect-dm branch March 25, 2021 07:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs/ok-to-test Needs approval for testing (check PR in detail before setting this label because PR is run on CI/CD) reviewed/lgtm Has approval for merging size/m Size of pull request is medium (see gardener-robot robot/bots/size.py)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants