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

[16.0][ADD] Module web_dark_mode #2351

Merged
merged 1 commit into from
Dec 7, 2022
Merged

Conversation

fkantelberg
Copy link
Member

Odoo 16.0 allows an easier implementation of a dark mode and I gave it a try. I want to contribute my work.

I appreciate it if you have hints about the color scheme or find weird/bad looking places.

Copy link
Contributor

@legalsylvain legalsylvain left a comment

Choose a reason for hiding this comment

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

hi @fkantelberg. Thanks for sharing !

  • Functional Test OK. (no code review)
    One minor point thought :
    -> go to settings : the background is very light, don't you think ?

image

  • could you add a text in a ROADMAP.rst file to mention that the module does'nt work for the point of sale module and requires extra glue modules ?
  • could you take a look on pre-commit errors ?

thank !

@etobella
Copy link
Member

Interesting module. I made similar module from my side as a test but with a different approach with odoo (in order to avoid similarities)

I also kept the the colors on the top bar in order to allow the dark mode to work with other possible modules like web_company_color

2022-11-27.20-57-39.mp4

I understand that you made it before, so it makes sense to keep your module.

@etobella
Copy link
Member

If you are interested, you can check it here:

https://github.com/tegin/web/tree/16.0-add-web_dark/web_dark

BTW, the error @legalsylvain found is fixed there

Copy link
Member

@ioans73 ioans73 left a comment

Choose a reason for hiding this comment

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

Functional review 👍🏻

@fkantelberg
Copy link
Member Author

Thank you for your response.

@legalsylvain Yes the settings page was light (again). This shows how much 16.0 still changes. I made it dark again and added a ROADMAP. With the new way of the assets it's maybe possible without a glue module otherwise a glue module might be wise.

The pre-commit seems a general error with loading flake8 from gitlab instead of github. Not sure how to tackle that because it's an issue in the entire CI of the OCA.

@etobella
Thank you. We can work together to make Odoo not blinding. I guess the web_company_color might still work because !important is used there. I haven't checked it yet because web_company_color isn't migrated yet. One main thing I wanted to solve is that the setting is device-independent :)

@ap-wtioit
Copy link
Contributor

@fkantelberg the issue with flake8 was solved in OCA/oca-addons-repo-template#170, now it should be fixed if you run copier -f update like pedro mentioned here OCA/oca-addons-repo-template@a48f386

@etobella
Copy link
Member

Well, to make it device independent, you should use only cookies, not a configuration on a user. The code used to make the cookie change without using the user was the following:
https://github.com/tegin/web/blob/16.0-add-web_dark/web_dark/static/src/js/dark_mode.esm.js#L13-L15

BTW, do you want to prefer the button on the user menu or something like the moon/sun button?

@pedrobaeza
Copy link
Member

Let me fix the pre-commit in a separate PR. Then you can rebase.

@fkantelberg
Copy link
Member Author

Well, to make it device independent, you should use only cookies, not a configuration on a user. The code used to make the cookie change without using the user was the following: https://github.com/tegin/web/blob/16.0-add-web_dark/web_dark/static/src/js/dark_mode.esm.js#L13-L15

BTW, do you want to prefer the button on the user menu or something like the moon/sun button?

You read me wrong. I wanted to make it device independent (not only cookie in browser). The user doesn't have to configure it on every device which would be the case if it's only a cookie.

I prefer that you need 2 clicks to change it. I love the sun/moon from your module but it's in a corner where many things to click are and it prevents some unintentional changes that way.

@pedrobaeza
Copy link
Member

The fix is merged. Now you can rebase and remove later commit. Anyway, you need to make the following changes:

  • Rename JS files to .esm.js for proper linting.
  • Execute pre-commit run -a in local before committing or install the hook (pre-commit install -f) for being executed automatically on each commit.

@etobella
Copy link
Member

etobella commented Nov 30, 2022

You read me wrong. I wanted to make it device independent (not only cookie in browser). The user doesn't have to configure it on every device which would be the case if it's only a cookie.

I think it is not bad to have different configuratons according to your device, as this is more flexible. When accessing from my computer I might prefer dark mode and on my mobile I might prefer light mode. The best option would be to use by default the configuration of your browser 🤔

I prefer that you need 2 clicks to change it. I love the sun/moon from your module but it's in a corner where many things to click are and it prevents some unintentional changes that way.

Good point 😄

@fkantelberg
Copy link
Member Author

You read me wrong. I wanted to make it device independent (not only cookie in browser). The user doesn't have to configure it on every device which would be the case if it's only a cookie.

I think it is not bad to have different configuratons according to your device, as this is more flexible. When accessing from my computer I might prefer dark mode and on my mobile I might prefer light mode. The best option would be to use by default the configuration of your browser thinking

Is that an option for the user or a global one?

Copy link

@jcdrubay jcdrubay left a comment

Choose a reason for hiding this comment

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

I did some functional tests on Runboat.
It looks great.
One thing that could be improved is to "auto-save" changes in progress when switching modes.

@etobella
Copy link
Member

You read me wrong. I wanted to make it device independent (not only cookie in browser). The user doesn't have to configure it on every device which would be the case if it's only a cookie.

I think it is not bad to have different configuratons according to your device, as this is more flexible. When accessing from my computer I might prefer dark mode and on my mobile I might prefer light mode. The best option would be to use by default the configuration of your browser thinking

Is that an option for the user or a global one?

This is something defined on the browser, however, I am not sure if this could work properly, because some changes might be needed from odoo side... It is more a wish than an option 😭

Anyway, I am not sure that we must define this by user, I would prefer to keep that on a cookie, in the same way Odoo does in order to follow the same logic with Odoo EE. If we want to force a cookie by user, I think it might be better to define a field on the user and accessing it from Preferences. On login, if the cookie is not already present, it will be defined as the value of the user. WDYT?

@fkantelberg
Copy link
Member Author

This is something defined on the browser, however, I am not sure if this could work properly, because some changes might be needed from odoo side... It is more a wish than an option sob

Anyway, I am not sure that we must define this by user, I would prefer to keep that on a cookie, in the same way Odoo does in order to follow the same logic with Odoo EE. If we want to force a cookie by user, I think it might be better to define a field on the user and accessing it from Preferences. On login, if the cookie is not already present, it will be defined as the value of the user. WDYT?

I added a configuration to the user preferences to make the dark mode device dependent if the user wants it. Default stays device independent. :)

@etobella
Copy link
Member

etobella commented Dec 1, 2022

Thanks!

@AntoniRomera
Copy link

I see super well this configuration but I have a doubt, the mobile devices along with several operating systems including windows 11, has settings for dark / light mode, would not it be better to take the configuration of the same device.

@OSevangelist
Copy link

Hi @etobella @pedrobaeza @legalsylvain @jcdrubay @ap-wtioit @ioans73

Interesting module. I made similar module from my side as a test but with a different approach with odoo (in order to avoid similarities)

@fkantelberg and me discussed that "similarity issue" very critically, taking into account also the other side of the potential spectrum of thoughts. We did so with regard to what recently happened in OCA/spreadsheet#1 , how this case was / wasn't handled and especially with the fact that a "dark mode" generally helps to keep the eyes healthy and reduce a waste of resources adding up to our all goal to improve sustainability and has therefore become a standard function of such web based systems.

Overall, we came to the conclusion that the approach is reasonably different (code wise) from the EE functionality, as the later does much more (i.e. higher functional coverage / complexity) is not encapsulated in a single module (different way of implementation) and doesn't have some of the features @fkantelberg added here (even replying to your request already).

The colors / coloring schemes and shades can be considered industry best practices and are well described in various public outlets (e.g. https://arpit-batri.medium.com/dark-mode-ui-conversion-604d2ecc0083).

However, if you have arguments / concerns that it is not different enough from the enterprise functionality please share these arguments / concerns here and lets all together try to set a benchmark of "difference" ultimately by also asking the other side of the spectrum for its consent as we can still change the function / coverage / implementation details further if necessary.

I am honestly sick of reinventing wheels especially for functions that are not economically relevant (i.e. nobody buys a license for a dark mode function) and i know so do many others in the community. We need to establish a common understanding with the vendor on what is possible and what not. Nobody wants to infringe anyones IPR. So again please share your thoughts on the matter and as soon as the case is being maturely discussed here i am happy to ask the Chief Executive Officer of the vendor for his consent or change requests.

@pedrobaeza
Copy link
Member

Odoo S.A. doesn't have the exclusivity of an enterprise feature. We can develop an exact drop-in replacement. The only condition is to not look at their code to develop it. But given that some of the tools used for the feature are at community level, it's very likely that the result code will be similar.

I don't think we should censor ourselves by fear of being very similar to enterprise.

Comment on lines 23 to 30
registry.category("user_menuitems").add("darkmode", darkModeSwitchItem);
if (!cookie.current.color_scheme) {
const data = await orm.webSearchRead(
"res.users",
[["id", "=", user.userId]],
["dark_mode"]
);

const dark_mode = data.length && data.records[0].dark_mode;
cookie.setCookie("color_scheme", dark_mode ? "dark" : "light");
}
Copy link

@AntoniRomera AntoniRomera Dec 2, 2022

Choose a reason for hiding this comment

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

window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', event => {
    cookie.setCookie("color_scheme", event.matches ? "dark" : "light");
    browser.location.reload();
})
const dark_mode = window.matchMedia('(prefers-color-scheme: dark)').matches;
cookie.setCookie("color_scheme", dark_mode ? "dark" : "light");

Copy link
Member Author

Choose a reason for hiding this comment

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

Interesting snippet to use the browser or system defaults. It would reload the entire page twice if your preferred scheme is dark which can be annoying but endurable for backend I guess. I'm just unsure if this is preferred because when it comes to workstations your system preference is just a default and Odoo is used in these environments (e.g. POS, non-personal devices for inventory etc)

Choose a reason for hiding this comment

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

If we are talking about work environments, it can happen the same as you activate the dark mode or disable it if the equipment you use is not unipersonal, but I'm not saying to remove the on or off button, sorry if I did not explain, it would only be interesting that the default is the one on the device

Copy link
Member Author

Choose a reason for hiding this comment

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

As far as I can see it can only happen in device dependent mode that the cookie isn't set by python code. In that case the dark_mode flag of res.users is just the last value selected on any device. In that case using the system preferences might be the better default. I'll give it a try. 👍

Copy link
Member Author

Choose a reason for hiding this comment

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

Alright the JS uses the prefers-color-scheme as default now if you have activated the device dependent mode.

@etobella
Copy link
Member

etobella commented Dec 2, 2022

IMO there is no issue with EE as the approach and functionality are different. Also, you did not took any EE code, so you should keep on. We cannot be scared as we did nothing wrong here.

It is a great addition for community, as this is needed by everyone.

@OSevangelist
Copy link

Thanks @pedrobaeza @etobella for your feedback. I think even looking at the EE code would be fine in general but the drop-in replacement must be developed in sufficiently different way. Of course, sometimes even two absolutely independent 'agents' would develop things in the same / almost similar way, because the framework and its constraints forces them to do so. If this is the case the functionality as a whole is not considered to have much technical depth and that is a very significant argument on whether something can be protected by copyright law or not. So i do agree with you. Lets merge it then!

@OCA-git-bot
Copy link
Contributor

This PR has the approved label and has been created more than 5 days ago. It should therefore be ready to merge by a maintainer (or a PSC member if the concerned addon has no declared maintainer). 🤖

@OSevangelist
Copy link

@etobella you see to be among the eligable persons on the web repo. Would you mind to initiate the ocabot to merge this piece. Of course if anyone of the other PSC members is faster, equally welcome ;-) Thx a lot!

@pedrobaeza
Copy link
Member

/ocabot merge nobump

@pedrobaeza pedrobaeza added this to the 16.0 milestone Dec 7, 2022
@OCA-git-bot
Copy link
Contributor

What a great day to merge this nice PR. Let's do it!
Prepared branch 16.0-ocabot-merge-pr-2351-by-pedrobaeza-bump-nobump, awaiting test results.

@OCA-git-bot OCA-git-bot merged commit 11a649d into OCA:16.0 Dec 7, 2022
@OCA-git-bot
Copy link
Contributor

Congratulations, your PR was merged at 539dc9e. Thanks a lot for contributing to OCA. ❤️

@OSevangelist
Copy link

thanks a lot @pedrobaeza

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants