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
MM-23853 Support dark mode and light mode syncing with OS theme setting #18140
MM-23853 Support dark mode and light mode syncing with OS theme setting #18140
Conversation
https://github.com/mattermost/mattermost-server/blob/308a88efb17e5756812a992ea17dd2cb346bcb8a/app/export.go#L35 |
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.
Thanks for the contribution @komik966 🎉! I've left some questions.
@@ -116,7 +118,7 @@ func (o *Preference) PreUpdate() { | |||
|
|||
// blank out any invalid theme values | |||
for name, value := range props { | |||
if name == "image" || name == "type" || name == "codeTheme" { | |||
if name == "image" || name == "type" || name == "codeTheme" || name == "colorScheme" { |
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.
Does this colorScheme
name refer to the light/dark mode?
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.
@streamer45 possible values of colorScheme
are light
/ dark
. It is used by client apps to categorize themes in theme selection form:
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.
Thanks 👍 I am wondering if the name is appropriate. I identify a color scheme as a set of colors and you can have many of those. Maybe lightMode
would be more fitting?
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.
@streamer45 React native uses colorScheme
https://reactnative.dev/docs/appearance#getcolorscheme. I named it same way to keep "ubiquitous language".
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.
For me, it is no problem to change it 😉
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.
@streamer45 I think isLight
would be better (this is theme's property so in the webapp we have theme.isLight
)
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.
React native uses colorScheme https://reactnative.dev/docs/appearance#getcolorscheme. I named it same way to keep "ubiquitous language".
TIL :)
I think isLight would be better (this is theme's property so in the webapp we have theme.isLight)
Yeah that's good as well but I have no strong opinion. We can also keep it as is since now I know why it was named that way and I am all for consistency :) @esethna , thoughts?
store/sqlstore/upgrade.go
Outdated
disableThemeSync := ` | ||
INSERT INTO preferences (userid, category, name, value) | ||
SELECT userid, '` + model.PreferenceCategoryDisableThemeSync + `', name, 'true' | ||
FROM preferences | ||
WHERE category = 'theme' | ||
` | ||
if _, err := sqlStore.GetMaster().ExecNoTimeout(disableThemeSync); err != nil { | ||
mlog.Error("Error inserting "+model.PreferenceCategoryDisableThemeSync+" preferences", mlog.Err(err)) | ||
} |
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.
Is this actually needed? I am thinking that if nothing special is found we should consider the feature disabled for the user. Unless we are explicitly making it an opt-out thing.
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.
I was thinking the same. In addition to this; if we auto enable this, we will need to set a dark_theme by default as well.
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.
@streamer45 Intention of this DB migration is to disable synchronization for users who already have edited their theme #15975 (comment)
@isacikgoz dark_theme
works same way as theme
works already. When no dark_theme
is saved, client apps use default dark theme.
model/preference.go
Outdated
PreferenceCategoryTheme = "theme" | ||
PreferenceCategoryTheme = "theme" | ||
PreferenceCategoryThemeDark = "theme_dark" | ||
PreferenceCategoryDisableThemeSync = "disable_theme_sync" |
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.
This goes along with my other comment. Maybe we should consider an enable_theme_sync
boolean setting 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.
By default, theme synchronization should be enabled. Only users who have changed their theme before introduction of this feature should have synchronization disabled.
enable_theme_sync
will force us to save this setting during new user registration.
disable_theme_sync
is saved only when user explicitly disables / enables it in theme selection form.
So disable_theme_sync
have three states:
- empty (no row in db table) - use default behavior (sync with os), we know that user never has switched it in theme selection form.
true
- not sync with osfalse
- sync with os
@streamer45
Now I see, the same is doable with enable_theme_sync
, and it's easier 🙃:
empty (no row in db table) - use default behavior (sync with os), we know that user never has switched it in theme selection form.
true - sync with os
false - not sync with os
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.
Sounds good. Also I think that defaulting to positive logic (enable vs disable) in variable/setting naming is usually better and easier to digest.
This PR has been automatically labelled "stale" because it hasn't had recent activity. |
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.
One change needed but otherwise looks great, thanks @komik966 👍
disableThemeSync := ` | ||
INSERT INTO preferences (userid, category, name, value) | ||
SELECT userid, '` + model.PreferenceCategoryEnableThemeSync + `', name, 'false' | ||
FROM preferences | ||
WHERE category = 'theme' | ||
` | ||
if _, err := sqlStore.GetMaster().ExecNoTimeout(disableThemeSync); err != nil { | ||
mlog.Error("Error inserting "+model.PreferenceCategoryEnableThemeSync+" preferences", mlog.Err(err)) | ||
} |
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.
This should be moved to the upgradeDatabaseToVersion610
method now.
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.
moved to 610
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.
@komik966 By now this is scheduled for 6.2.0 so it should be moved again. You may have to create a new method for it. Let me know if you need help with that.
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.
Approving to not block this, I will review on the webapp PR
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.
Nothing on top of @streamer45's point. Anticipating this feature for a long time, awesome work @komik966 🎉
This PR has been automatically labelled "stale" because it hasn't had recent activity. |
Adding @jgilliam17 for QA review. @komik966 once the changes for webapp are ready we can spin up a test server and as long as the branch names are the same on the webapp and server PRs our test servers will pick up the changes together for testing FYI @jgilliam17 there's also a mobile PR: mattermost/mattermost-mobile#5635 |
@komik966 just circling back on this as I was out for a few weeks. What are the next steps for the server, webapp and mobile PRs? Let us know when/if they are ready for reviews and I can help chase them down |
|
Great, thanks for the update @komik966! We will wait to merge this until it can be tested with the webapp PR cc// @jgilliam17 |
This PR has been automatically labelled "stale" because it hasn't had recent activity. |
Hey @komik966, let us know if you're still working on this. Would love to see it in the product! |
Summary
This PR adds:
Ticket Link
#15975
Release Note