[ADD][16.0] Module web_dark_mode

This commit is contained in:
fkantelberg
2022-11-29 18:44:45 +01:00
parent f02095f8a9
commit abe28c7a9e
17 changed files with 754 additions and 0 deletions

View File

@@ -0,0 +1,4 @@
# © 2022 Florian Kantelberg - initOS GmbH
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import ir_http, res_users

View File

@@ -0,0 +1,22 @@
# © 2022 Florian Kantelberg - initOS GmbH
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import models
from odoo.http import request
class IrHttp(models.AbstractModel):
_inherit = "ir.http"
@classmethod
def _set_color_scheme(cls, response):
scheme = request.httprequest.cookies.get("color_scheme")
user = request.env.user
user_scheme = "dark" if user.dark_mode else "light"
if (not user.dark_mode_device_dependent) and scheme != user_scheme:
response.set_cookie("color_scheme", user_scheme)
@classmethod
def _post_dispatch(cls, response):
cls._set_color_scheme(response)
return super()._post_dispatch(response)

View File

@@ -0,0 +1,12 @@
# © 2022 Florian Kantelberg - initOS GmbH
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import fields, models
class ResUsers(models.Model):
_inherit = "res.users"
dark_mode = fields.Boolean()
dark_mode_device_dependent = fields.Boolean("Device Dependent Dark Mode")