Skip to content

Commit

Permalink
[MIG] web_dark_mode: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
RUS authored and bizzappdev committed Feb 20, 2025
1 parent 85caaa3 commit 25ef896
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 14 deletions.
1 change: 1 addition & 0 deletions web_dark_mode/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ Contributors
------------

- Florian Kantelberg <[email protected]>
- Ruchir Shukla <[email protected]>

Maintainers
-----------
Expand Down
7 changes: 2 additions & 5 deletions web_dark_mode/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,14 @@
"name": "Dark Mode",
"summary": "Enabled Dark Mode for the Odoo Backend",
"license": "AGPL-3",
"version": "16.0.1.0.2",
"version": "17.0.1.0.0",
"website": "https://github.com/OCA/web",
"author": "initOS GmbH, Odoo Community Association (OCA)",
"depends": ["web"],
"excludes": ["web_enterprise"],
"installable": True,
"assets": {
"web.dark_mode_assets_common": [
("prepend", "web_dark_mode/static/src/scss/variables.scss"),
],
"web.dark_mode_assets_backend": [
"web.assets_web_dark": [
("prepend", "web_dark_mode/static/src/scss/variables.scss"),
],
"web.assets_backend": [
Expand Down
1 change: 1 addition & 0 deletions web_dark_mode/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
- Florian Kantelberg \<<[email protected]>\>
- Ruchir Shukla \<<[email protected]>\>
1 change: 1 addition & 0 deletions web_dark_mode/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ <h2><a class="toc-backref" href="#toc-entry-4">Authors</a></h2>
<h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
<ul class="simple">
<li>Florian Kantelberg &lt;<a class="reference external" href="mailto:florian.kantelberg&#64;initos.com">florian.kantelberg&#64;initos.com</a>&gt;</li>
<li>Ruchir Shukla &lt;<a class="reference external" href="mailto:ruchir&#64;bizzappdev.com">ruchir&#64;bizzappdev.com</a>&gt;</li>
</ul>
</div>
<div class="section" id="maintainers">
Expand Down
21 changes: 12 additions & 9 deletions web_dark_mode/static/src/js/switch_item.esm.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,42 @@
/** @odoo-module **/

import {_t} from "@web/core/l10n/translation";
import {browser} from "@web/core/browser/browser";
import {cookie} from "@web/core/browser/cookie";
import {registry} from "@web/core/registry";

export function darkModeSwitchItem(env) {
return {
type: "switch",
id: "color_scheme.switch",
description: env._t("Dark Mode"),
description: _t("Dark Mode"),
callback: () => {
env.services.color_scheme.switchColorScheme();
},
isChecked: env.services.cookie.current.color_scheme === "dark",
isChecked: cookie.get("color_scheme") === "dark",
sequence: 40,
};
}

export const colorSchemeService = {
dependencies: ["cookie", "orm", "ui", "user"],
dependencies: ["orm", "ui", "user"],

async start(env, {cookie, orm, ui, user}) {
async start(env, {orm, ui, user}) {
registry.category("user_menuitems").add("darkmode", darkModeSwitchItem);

if (!cookie.current.color_scheme) {
if (!cookie.get("color_scheme")) {
const match_media = window.matchMedia("(prefers-color-scheme: dark)");
const dark_mode = match_media.matches;
cookie.setCookie("color_scheme", dark_mode ? "dark" : "light");

cookie.set("color_scheme", dark_mode ? "dark" : "light");
if (dark_mode) browser.location.reload();
}

return {
async switchColorScheme() {
const scheme =
cookie.current.color_scheme === "dark" ? "light" : "dark";
cookie.setCookie("color_scheme", scheme);
const scheme = cookie.get("color_scheme") === "dark" ? "light" : "dark";

cookie.set("color_scheme", scheme);

await orm.write("res.users", [user.userId], {
dark_mode: scheme === "dark",
Expand Down

0 comments on commit 25ef896

Please sign in to comment.