-
-
Notifications
You must be signed in to change notification settings - Fork 202
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
feat(ui): updates to dark mode logic #3740
Open
zackbcom
wants to merge
3
commits into
zwave-js:master
Choose a base branch
from
zackbcom:dark-toggle
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<template> | ||
<v-app :dark="darkMode"> | ||
<v-app> | ||
<div | ||
v-if="$route.meta.requiresAuth && auth !== undefined && !hideTopbar" | ||
> | ||
|
@@ -595,8 +595,11 @@ export default { | |
this.title = value.name || '' | ||
this.startSocket() | ||
}, | ||
systemDark() { | ||
this.updateDarkMode(this.darkMode) | ||
}, | ||
darkMode(val) { | ||
this.$vuetify.theme.dark = !!val | ||
this.updateDarkMode(val) | ||
}, | ||
pages() { | ||
// this.verifyRoute() | ||
|
@@ -669,6 +672,8 @@ export default { | |
hideTopbar: false, | ||
title: '', | ||
messages: [], | ||
systemDark: false, | ||
mq_system_dark: null, | ||
} | ||
}, | ||
methods: { | ||
|
@@ -1573,6 +1578,14 @@ export default { | |
log.error(error) | ||
} | ||
}, | ||
updateSystemDark(update) { | ||
this.systemDark = update.matches | ||
}, | ||
updateDarkMode(value) { | ||
// Set to system defualt if null | ||
this.$vuetify.theme.dark = | ||
value === null ? this.systemDark : !!value | ||
}, | ||
}, | ||
beforeMount() { | ||
manager.register(instances.APP, this) | ||
|
@@ -1590,22 +1603,26 @@ export default { | |
|
||
const settings = useBaseStore().settings | ||
|
||
// system dark mode | ||
const systemThemeDark = !!window.matchMedia( | ||
'(prefers-color-scheme: dark)', | ||
).matches | ||
|
||
// set the dark mode to the system dark mode if it's different | ||
if (settings.load('dark') === undefined) { | ||
useBaseStore().setDarkMode(systemThemeDark) | ||
} else { | ||
// load the theme from localstorage | ||
// this is needed to prevent the theme switch on load | ||
// this will be overriden by settings value once `initSettings` | ||
// base store method is called | ||
this.$vuetify.theme.dark = settings.load('dark', false) | ||
// Event listener to capture system dark changes. | ||
if (this.mq_system_dark === null && window) { | ||
this.mq_system_dark = window.matchMedia( | ||
'(prefers-color-scheme: dark)', | ||
) | ||
this.mq_system_dark.addEventListener( | ||
'change', | ||
this.updateSystemDark, | ||
) | ||
} | ||
|
||
// pre-load System Dark | ||
this.updateSystemDark(this.mq_system_dark) | ||
|
||
// load the theme from localstorage | ||
// this is needed to prevent the theme switch on load | ||
// this will be overriden by settings value once `initSettings` | ||
// base store method is called | ||
this.updateDarkMode(settings.load('dark', null)) | ||
|
||
useBaseStore().$onAction(({ name, args }) => { | ||
if (name === 'showSnackbar') { | ||
this.showSnackbar(...args) | ||
|
@@ -1615,6 +1632,14 @@ export default { | |
} | ||
}) | ||
}, | ||
beforeUnmount() { | ||
if (this.mq_system_dark !== null) { | ||
this.mq_system_dark.removeEventListener( | ||
'change', | ||
this.updateSystemDark, | ||
) | ||
} | ||
}, | ||
Comment on lines
+1635
to
+1642
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is a bit useless as the App will only be unmounted when the page is destroyed |
||
beforeDestroy() { | ||
if (this.socket) this.socket.close() | ||
}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why don't use a watch for this instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also it's not clear to me what
mq_system_dark
is used for, you never re-assign it, I would instead use a let in beforeMount insteadThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First time using Vue. Will re look at the logic here. Thanks for the notes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's ok no worries I appreciate a lot your help 🙏🏼