A platform for community discussion. Free, open, simple.
FEATURE: Add dark color scheme setting for themes (#33967)
Krzysztof Kotlarek7a9cf9356e48
diff --git a/app/assets/javascripts/admin/addon/components/color-palette-list-item.gjs b/app/assets/javascripts/admin/addon/components/color-palette-list-item.gjsindex 9af3507551b..9548d467f4b 100644--- a/app/assets/javascripts/admin/addon/components/color-palette-list-item.gjs+++ b/app/assets/javascripts/admin/addon/components/color-palette-list-item.gjs@@ -4,10 +4,11 @@ import { array, fn } from "@ember/helper";import { action } from "@ember/object";import { LinkTo } from "@ember/routing";import { htmlSafe } from "@ember/template";-import { not } from "truth-helpers";+import { not, or } from "truth-helpers";import DButton from "discourse/components/d-button";import DropdownMenu from "discourse/components/dropdown-menu";import icon from "discourse/helpers/d-icon";+import { bind } from "discourse/lib/decorators";import { i18n } from "discourse-i18n";import SvgSingleColorPalettePlaceholder from "admin/components/svg/single-color-palette-placeholder";import { getColorSchemeStyles } from "admin/lib/color-transformations";@@ -22,14 +23,6 @@ export default class ColorPaletteListItem extends Component {return this.args.scheme?.is_builtin_default || false;}- get setAsDefaultLabel() {- const themeName = this.args.defaultTheme?.name || "Default";-- return i18n("admin.customize.colors.set_default", {- theme: themeName,- });- }-get canEdit() {return !this.isBuiltInDefault && this.args.scheme?.id;}@@ -45,13 +38,26 @@ export default class ColorPaletteListItem extends Component {return true;}- get isActive() {+ get isDefaultLight() {if (this.isBuiltInDefault) {return this.args.defaultTheme && !this.args.defaultTheme.color_scheme_id;}return (this.args.defaultTheme &&- this.args.isDefaultThemeColorScheme(this.args.scheme)+ this.args.isDefaultThemeLightColorScheme(this.args.scheme)+ );+ }++ get isDefaultDark() {+ if (this.isBuiltInDefault) {+ return (+ this.args.defaultDarkTheme &&+ !this.args.defaultDarkTheme.color_scheme_id+ );+ }+ return (+ this.args.defaultTheme &&+ this.args.isDefaultThemeDarkColorScheme(this.args.scheme));}@@ -85,6 +91,35 @@ export default class ColorPaletteListItem extends Component {return htmlSafe(allStyles);}+ get activeBadgeTitle() {+ if (this.isDefaultLight && this.isDefaultDark) {+ return i18n("admin.customize.colors.active_both_badge.title");+ }+ if (this.isDefaultLight) {+ return i18n("admin.customize.colors.active_light_badge.title");+ }+ return i18n("admin.customize.colors.active_dark_badge.title");+ }++ get activeBadgeText() {+ if (this.isDefaultLight && this.isDefaultDark) {+ return i18n("admin.customize.colors.active_both_badge.text");+ }+ if (this.isDefaultLight) {+ return i18n("admin.customize.colors.active_light_badge.text");+ }+ return i18n("admin.customize.colors.active_dark_badge.text");+ }++ @bind+ setAsDefaultLabel(mode) {+ const themeName = this.args.defaultTheme?.name || "Default";++ return i18n(`admin.customize.colors.set_default_${mode}`, {+ theme: themeName,+ });+ }+@actionasync handleAsyncAction(asyncFn, ...args) {this.dMenu.close();@@ -138,12 +173,12 @@ export default class ColorPaletteListItem extends Component {{{/if}}</div>- {{#if this.isActive}}+ {{#if (or this.isDefaultLight this.isDefaultDark)}}<span- title={{i18n "admin.customize.colors.active_badge.title"}}+ title={{this.activeBadgeTitle}}class="theme-card__badge --active">- {{i18n "admin.customize.colors.active_badge.text"}}+ {{this.activeBadgeText}}</span>{{/if}}</div>@@ -209,11 +244,26 @@ export default class ColorPaletteListItem extends Component {this.handleAsyncAction@setAsDefaultThemePalette@scheme+ "light"+ }}+ @icon="far-star"+ @translatedLabel={{fn this.setAsDefaultLabel "light"}}+ class="btn-transparent btn-palette-default"+ disabled={{this.isDefaultLight}}+ />+ </dropdown.item>+ <dropdown.item>+ <DButton+ @action={{fn+ this.handleAsyncAction+ @setAsDefaultThemePalette+ @scheme+ "dark"}}@icon="star"- @translatedLabel={{this.setAsDefaultLabel}}+ @translatedLabel={{fn this.setAsDefaultLabel "dark"}}class="btn-transparent btn-palette-default"- disabled={{this.isActive}}+ disabled={{this.isDefaultDark}}/></dropdown.item>diff --git a/app/assets/javascripts/admin/addon/controllers/admin-customize-colors.js b/app/assets/javascripts/admin/addon/controllers/admin-customize-colors.jsindex 510f17657b6..2bd3bdc4495 100644--- a/app/assets/javascripts/admin/addon/controllers/admin-customize-colors.js+++ b/app/assets/javascripts/admin/addon/controllers/admin-customize-colors.js@@ -19,22 +19,34 @@ export default class AdminCustomizeColorsController extends Controller {@tracked defaultTheme = null;- isDefaultThemeColorScheme = (scheme) => {+ isDefaultThemeLightColorScheme = (scheme) => {return this.defaultTheme?.color_scheme_id === scheme.id;};+ isDefaultThemeDarkColorScheme = (scheme) => {+ return this.defaultTheme?.dark_color_scheme_id === scheme.id;+ };+@tracked _initialSortedSchemes = [];- _initialUserColorSchemeId = undefined;- _initialDefaultThemeColorSchemeId = null;+ _initialUserLightColorSchemeId = undefined;+ _initialUserDarkColorSchemeId = undefined;+ _initialDefaultThemeLightColorSchemeId = null;+ _initialDefaultThemeDarkColorSchemeId = null;_sortedOnce = false;- get canPreviewColorScheme() {+ canPreviewColorScheme(mode) {const usingDefaultTheme = currentThemeId() === this.defaultTheme?.id;const usingDefaultLightScheme =- this._initialUserColorSchemeId === this._initialDefaultThemeColorSchemeId;+ this._initialUserLightColorSchemeId ===+ this._initialDefaultThemeLightColorSchemeId;+ const usingDefaultDarkScheme =+ this._initialUserDarkColorSchemeId ===+ this._initialDefaultThemeDarkColorSchemeId;return (- usingDefaultTheme && usingDefaultLightScheme && !this.isUsingDarkMode+ usingDefaultTheme &&+ ((mode === "dark" && this.isUsingDarkMode && usingDefaultDarkScheme) ||+ (mode === "light" && !this.isUsingDarkMode && usingDefaultLightScheme)));}@@ -43,18 +55,26 @@ export default class AdminCustomizeColorsController extends Controller {}_captureInitialState() {- this._initialUserColorSchemeId = this.session.userColorSchemeId;- this._initialDefaultThemeColorSchemeId = this.defaultTheme?.color_scheme_id;+ this._initialUserLightColorSchemeId = this.session.userColorSchemeId;+ this._initialUserDarkColorSchemeId = this.session.userDarkSchemeId;+ this._initialDefaultThemeLightColorSchemeId =+ this.defaultTheme?.color_scheme_id;+ this._initialDefaultThemeDarkColorSchemeId =+ this.defaultTheme?.dark_color_scheme_id;}get changedThemePreferences() {// can't check against null, because the default scheme ID is null- if (this._initialUserColorSchemeId === undefined && this.defaultTheme) {+ if (+ this._initialUserLightColorSchemeId === undefined &&+ this.defaultTheme+ ) {this._captureInitialState();}const changedColors =- this._initialUserColorSchemeId !== this._initialDefaultThemeColorSchemeId;+ this._initialUserColorSchemeId !==+ this._initialDefaultThemeLightColorSchemeId;const changedTheme = this.defaultTheme?.id !== currentThemeId(this.site);return changedColors || changedTheme;@@ -121,15 +141,16 @@ export default class AdminCustomizeColorsController extends Controller {}schemes.sort((a, b) => {- const defaultId = this.defaultTheme?.color_scheme_id;+ const defaultLightId = this.defaultTheme?.color_scheme_id;+ const defaultDarkId = this.defaultTheme?.dark_color_scheme_id;const isDefaultA = a.is_builtin_default- ? defaultId === null- : a.id === defaultId;+ ? defaultLightId === null || defaultDarkId === null+ : a.id === defaultLightId || a.id === defaultDarkId;const isDefaultB = b.is_builtin_default- ? defaultId === null- : b.id === defaultId;+ ? defaultLightId === null || defaultDarkId === null+ : b.id === defaultLightId || b.id === defaultDarkId;if (isDefaultA !== isDefaultB) {return isDefaultA ? -1 : 1;@@ -186,12 +207,12 @@ export default class AdminCustomizeColorsController extends Controller {}@action- async setAsDefaultThemePalette(scheme) {+ async setAsDefaultThemePalette(scheme, mode) {try {let previewMode;if (scheme.is_builtin_default) {previewMode = "reload";- } else if (this.canPreviewColorScheme) {+ } else if (this.canPreviewColorScheme(mode)) {previewMode = "live";} else {previewMode = "none";@@ -199,9 +220,10 @@ export default class AdminCustomizeColorsController extends Controller {this.defaultTheme = await setDefaultColorScheme(scheme, this.store, {previewMode,+ mode,});- if (!this.canPreviewColorScheme) {+ if (!this.canPreviewColorScheme(mode)) {const schemeName = scheme.description || scheme.name;const themeName = this.defaultTheme.name;this.toasts.success({diff --git a/app/assets/javascripts/admin/addon/controllers/admin-customize-themes-show-index.js b/app/assets/javascripts/admin/addon/controllers/admin-customize-themes-show-index.jsindex 72961091e1c..16627214256 100644--- a/app/assets/javascripts/admin/addon/controllers/admin-customize-themes-show-index.js+++ b/app/assets/javascripts/admin/addon/controllers/admin-customize-themes-show-index.js@@ -80,11 +80,19 @@ export default class AdminCustomizeThemesShowIndexController extends Controller}@discourseComputed("colorSchemeId", "model.color_scheme_id")- colorSchemeChanged(colorSchemeId, existingId) {+ lightColorSchemeChanged(colorSchemeId, existingId) {colorSchemeId = colorSchemeId === null ? null : parseInt(colorSchemeId, 10);+return colorSchemeId !== existingId;}+ @discourseComputed("darkColorSchemeId", "model.dark_color_scheme_id")+ darkColorSchemeChanged(darkColorSchemeId, existingId) {+ darkColorSchemeId =+ darkColorSchemeId === null ? null : parseInt(darkColorSchemeId, 10);+ return darkColorSchemeId !== existingId;+ }+@discourseComputed("availableChildThemes", "model.childThemes.[]", "model")selectableChildThemes(available, childThemes) {if (available) {@@ -307,12 +315,17 @@ export default class AdminCustomizeThemesShowIndexController extends Controller}@action- cancelChangeScheme() {+ cancelChangeLightScheme() {this.set("colorSchemeId", this.get("model.color_scheme_id"));}@action- changeScheme() {+ cancelChangeDarkScheme() {+ this.set("darkColorSchemeId", this.get("model.dark_color_scheme_id"));+ }++ @action+ changeLightScheme() {let schemeId = this.colorSchemeId;this.set("model.color_scheme_id",@@ -321,6 +334,16 @@ export default class AdminCustomizeThemesShowIndexController extends Controllerthis.model.saveChanges("color_scheme_id");}+ @action+ changeDarkScheme() {+ let schemeId = this.darkColorSchemeId;+ this.set(+ "model.dark_color_scheme_id",+ schemeId === null ? null : parseInt(schemeId, 10)+ );+ this.model.saveChanges("dark_color_scheme_id");+ }+@actioneditTheme() {if (this.get("model.remote_theme.is_git")) {@@ -441,7 +464,15 @@ export default class AdminCustomizeThemesShowIndexController extends Controller}@action- editColorScheme() {+ editLightColorScheme() {this.router.transitionTo("adminCustomize.colors.show", this.colorSchemeId);}++ @action+ editDarkColorScheme() {+ this.router.transitionTo(+ "adminCustomize.colors.show",+ this.darkColorSchemeId+ );+ }}diff --git a/app/assets/javascripts/admin/addon/lib/color-scheme-manager.js b/app/assets/javascripts/admin/addon/lib/color-scheme-manager.jsindex 2920282fb46..c2097802619 100644--- a/app/assets/javascripts/admin/addon/lib/color-scheme-manager.js+++ b/app/assets/javascripts/admin/addon/lib/color-scheme-manager.js@@ -115,7 +115,7 @@ export async function applyColorScheme(scheme, options = {}) {*/export async function setDefaultColorScheme(scheme, store, options = {}) {- const { previewMode = "live" } = options;+ const { previewMode = "live", mode = "light" } = options;try {// Determine preview behavior@@ -149,9 +149,13 @@ export async function setDefaultColorScheme(scheme, store, options = {}) {}const schemeId = scheme?.id || null;- defaultTheme.set("color_scheme_id", schemeId);-- await defaultTheme.saveChanges("color_scheme_id");+ if (mode === "light") {+ defaultTheme.set("color_scheme_id", schemeId);+ await defaultTheme.saveChanges("color_scheme_id");+ } else {+ defaultTheme.set("dark_color_scheme_id", schemeId);+ await defaultTheme.saveChanges("dark_color_scheme_id");+ }if (shouldReload) {window.location.reload();diff --git a/app/assets/javascripts/admin/addon/routes/admin-customize-themes-show-index.js b/app/assets/javascripts/admin/addon/routes/admin-customize-themes-show-index.jsindex b1f95eff419..08499897293 100644--- a/app/assets/javascripts/admin/addon/routes/admin-customize-themes-show-index.js+++ b/app/assets/javascripts/admin/addon/routes/admin-customize-themes-show-index.js@@ -21,6 +21,7 @@ export default class AdminCustomizeThemesShowIndexRoute extends DiscourseRoute {parentController,allThemes: parentController.get("model"),colorSchemeId: model.get("color_scheme_id"),+ darkColorSchemeId: model.get("dark_color_scheme_id"),colorSchemes: parentController.get("model.extras.color_schemes"),editingName: false,userLocale: parentController.get("model.extras.locale"),diff --git a/app/assets/javascripts/admin/addon/templates/customize-colors.gjs b/app/assets/javascripts/admin/addon/templates/customize-colors.gjsindex 18d1d7102b2..0dd9e4e8d13 100644--- a/app/assets/javascripts/admin/addon/templates/customize-colors.gjs+++ b/app/assets/javascripts/admin/addon/templates/customize-colors.gjs@@ -56,22 +56,6 @@ export default RouteTemplate(</div>{{/if}}- {{#unless @controller.changedThemePreferences}}- {{! only show one alert at a time, changedThemePreferences takes precedence }}- {{#if @controller.isUsingDarkMode}}- <div class="alert alert-info">- {{htmlSafe- (i18n- "admin.customize.colors.dark_mode_warning"- link=(getUrl- "/admin/site_settings/category/all_results?filter=default dark mode"- )- )- }}- </div>- {{/if}}- {{/unless}}-<AdminFilterControls@array={{@controller.sortedColorSchemes}}@minItemsForFilter={{FILTER_MINIMUM}}@@ -88,7 +72,8 @@ export default RouteTemplate(<ColorPaletteListItem@scheme={{scheme}}@defaultTheme={{@controller.defaultTheme}}- @isDefaultThemeColorScheme={{@controller.isDefaultThemeColorScheme}}+ @isDefaultThemeLightColorScheme={{@controller.isDefaultThemeLightColorScheme}}+ @isDefaultThemeDarkColorScheme={{@controller.isDefaultThemeDarkColorScheme}}@toggleUserSelectable={{@controller.toggleUserSelectable}}@setAsDefaultThemePalette={{@controller.setAsDefaultThemePalette}}@deleteColorScheme={{@controller.deleteColorScheme}}diff --git a/app/assets/javascripts/admin/addon/templates/customize-themes-show-index.gjs b/app/assets/javascripts/admin/addon/templates/customize-themes-show-index.gjsindex b6b8d6d2f47..f5d5ed4d2c2 100644--- a/app/assets/javascripts/admin/addon/templates/customize-themes-show-index.gjs+++ b/app/assets/javascripts/admin/addon/templates/customize-themes-show-index.gjs@@ -120,7 +120,7 @@ export default RouteTemplate({{#unless @controller.model.component}}{{#unless @controller.siteSettings.use_overhauled_theme_color_palette}}<section- class="form-horizontal theme settings control-unit theme-settings__color-scheme"+ class="form-horizontal theme settings control-unit theme-settings__light-color-scheme"><div class="row setting"><div class="setting-label">@@ -138,7 +138,7 @@ export default RouteTemplate({{#if @controller.colorSchemeId}}<DButton@icon="pencil"- @action={{@controller.editColorScheme}}+ @action={{@controller.editLightColorScheme}}@title="admin.customize.theme.edit_color_scheme"/>{{/if}}@@ -150,16 +150,61 @@ export default RouteTemplate(</div><div class="setting-controls">- {{#if @controller.colorSchemeChanged}}+ {{#if @controller.lightColorSchemeChanged}}<DButton- @action={{@controller.changeScheme}}+ @action={{@controller.changeLightScheme}}@icon="check"- class="ok submit-edit"+ class="ok submit-light-edit"/><DButton- @action={{@controller.cancelChangeScheme}}+ @action={{@controller.cancelChangeLightScheme}}@icon="xmark"- class="cancel cancel-edit"+ class="cancel cancel-light-edit"+ />+ {{/if}}+ </div>+ </div>+ </section>+ <section+ class="form-horizontal theme settings control-unit theme-settings__dark-color-scheme"+ >+ <div class="row setting">+ <div class="setting-label">+ {{i18n "admin.customize.theme.dark_color_scheme"}}+ </div>++ <div class="setting-value">+ <div class="color-palette-input-group">+ <ColorPalettes+ @content={{@controller.colorSchemes}}+ @value={{@controller.darkColorSchemeId}}+ @icon="paintbrush"+ @options={{hash filterable=true}}+ />+ {{#if @controller.darkColorSchemeId}}+ <DButton+ @icon="pencil"+ @action={{@controller.editDarkColorScheme}}+ @title="admin.customize.theme.edit_dark_color_scheme"+ />+ {{/if}}+ </div>++ <div class="desc">{{i18n+ "admin.customize.theme.dark_color_scheme_select"+ }}</div>+ </div>+ <div class="setting-controls">+ {{#if @controller.darkColorSchemeChanged}}+ <DButton+ @action={{@controller.changeDarkScheme}}+ @icon="check"+ class="ok submit-dark-edit"+ />+ <DButton+ @action={{@controller.cancelChangeDarkScheme}}+ @icon="xmark"+ class="cancel cancel-dark-edit"/>{{/if}}</div>diff --git a/app/assets/javascripts/discourse/app/controllers/preferences/interface.js b/app/assets/javascripts/discourse/app/controllers/preferences/interface.jsindex e9f07ec1232..42d66d8ad1b 100644--- a/app/assets/javascripts/discourse/app/controllers/preferences/interface.js+++ b/app/assets/javascripts/discourse/app/controllers/preferences/interface.js@@ -100,9 +100,10 @@ export default class InterfaceController extends Controller {return this.siteSettings.available_locales;}- @discourseComputed- defaultDarkSchemeId() {- return this.siteSettings.default_dark_mode_color_scheme_id;+ @discourseComputed("currentThemeId")+ defaultDarkSchemeId(themeId) {+ const theme = this.userSelectableThemes?.findBy("id", themeId);+ return theme?.dark_color_scheme_id || -1;}@discourseComputed@@ -345,18 +346,10 @@ export default class InterfaceController extends Controller {this.enableDarkMode ? null : -1);} else {- // if chosen dark scheme matches site dark scheme, no need to store- if (- this.defaultDarkSchemeId > 0 &&- this.selectedDarkColorSchemeId === this.defaultDarkSchemeId- ) {- this.set("model.user_option.dark_scheme_id", null);- } else {- this.set(- "model.user_option.dark_scheme_id",- this.selectedDarkColorSchemeId- );- }+ this.set(+ "model.user_option.dark_scheme_id",+ this.selectedDarkColorSchemeId+ );}return this.modeldiff --git a/app/assets/javascripts/discourse/app/lib/color-scheme-picker.js b/app/assets/javascripts/discourse/app/lib/color-scheme-picker.jsindex 66b6b342c57..94b428e6376 100644--- a/app/assets/javascripts/discourse/app/lib/color-scheme-picker.js+++ b/app/assets/javascripts/discourse/app/lib/color-scheme-picker.js@@ -28,6 +28,18 @@ export function listColorSchemes(site, options = {}) {}});+ const defaultLightColorScheme = site.get("default_light_color_scheme");+ if (defaultLightColorScheme && !options.darkOnly) {+ const existing = schemes.findBy("id", defaultLightColorScheme.id);+ if (!existing) {+ results.unshift({+ id: defaultLightColorScheme.id,+ name: `${i18n("user.color_schemes.default_description")}`,+ theme_id: defaultLightColorScheme.theme_id,+ colors: defaultLightColorScheme.colors,+ });+ }+ }if (options.darkOnly) {const defaultDarkColorScheme = site.get("default_dark_color_scheme");if (defaultDarkColorScheme) {@@ -35,19 +47,17 @@ export function listColorSchemes(site, options = {}) {if (!existing) {results.unshift({id: defaultDarkColorScheme.id,- name: `${defaultDarkColorScheme.name} ${i18n(- "user.color_schemes.default_dark_scheme"- )}`,+ name: `${i18n("user.color_schemes.default_description")}`,theme_id: defaultDarkColorScheme.theme_id,colors: defaultDarkColorScheme.colors,});}+ } else {+ results.unshift({+ id: -1,+ name: `${i18n("user.color_schemes.default_description")}`,+ });}-- results.unshift({- id: -1,- name: i18n("user.color_schemes.disable_dark_scheme"),- });}return results.length === 0 ? null : results;diff --git a/app/assets/javascripts/discourse/app/lib/theme-selector.js b/app/assets/javascripts/discourse/app/lib/theme-selector.jsindex 9d9aae21547..2110a5bebca 100644--- a/app/assets/javascripts/discourse/app/lib/theme-selector.js+++ b/app/assets/javascripts/discourse/app/lib/theme-selector.js@@ -76,6 +76,7 @@ export function listThemes(site) {name: t.name,id: t.theme_id,color_scheme_id: t.color_scheme_id,+ dark_color_scheme_id: t.dark_color_scheme_id,});});diff --git a/app/assets/javascripts/discourse/tests/acceptance/user-preferences-interface-test.js b/app/assets/javascripts/discourse/tests/acceptance/user-preferences-interface-test.jsindex 3341859f5bc..b9ae28900fb 100644--- a/app/assets/javascripts/discourse/tests/acceptance/user-preferences-interface-test.js+++ b/app/assets/javascripts/discourse/tests/acceptance/user-preferences-interface-test.js@@ -65,23 +65,6 @@ acceptance("User Preferences - Interface", function (needs) {removeCookie("text_size");});- test("does not show option to disable dark mode by default", async function (assert) {- await visit("/u/eviltrout/preferences/interface");- assert.dom(".control-group.dark-mode").doesNotExist("option not visible");- });-- test("shows light/dark color scheme pickers", async function (assert) {- let site = Site.current();- site.set("user_color_schemes", [- { id: 2, name: "Cool Breeze" },- { id: 3, name: "Dark Night", is_dark: true },- ]);-- await visit("/u/eviltrout/preferences/interface");- assert.dom(".light-color-scheme").exists("has regular dropdown");- assert.dom(".dark-color-scheme").exists("has dark color scheme dropdown");- });-test("shows light color scheme default option when theme's color scheme is not user selectable", async function (assert) {let site = Site.current();site.set("user_themes", [@@ -161,14 +144,13 @@ acceptance("User Preferences Color Schemes (with default dark scheme)",function (needs) {needs.user();- needs.settings({ default_dark_mode_color_scheme_id: 1 });needs.pretender((server, helper) => {- server.get("/color-scheme-stylesheet/2.json", () => {+ server.get("/color-scheme-stylesheet/2/2.json", () => {return helper.response({success: "OK",});});- server.get("/color-scheme-stylesheet/3.json", () => {+ server.get("/color-scheme-stylesheet/3/2.json", () => {return helper.response({new_href: "3.css",});@@ -177,13 +159,11 @@ acceptance(return helper.response(userFixtures["/u/charlie.json"]);});});-- test("show option to disable dark mode", async function (assert) {- await visit("/u/eviltrout/preferences/interface");-- assert- .dom(".control-group.dark-mode")- .exists("has the option to disable dark mode");+ needs.hooks.beforeEach(() => {+ let meta = document.createElement("meta");+ meta.name = "discourse_theme_id";+ meta.content = "2";+ document.getElementsByTagName("head")[0].appendChild(meta);});test("no color scheme picker by default", async function (assert) {@@ -293,6 +273,11 @@ acceptance(undefined,"cookie is not set");+ assert.strictEqual(+ cookie("dark_scheme_id"),+ undefined,+ "cookie is not set"+ );assert.dom(".color-scheme-checkbox input:checked").exists("defaults to storing values in user options");@@ -303,6 +288,11 @@ acceptance(undefined,"cookie is unchanged");+ assert.strictEqual(+ cookie("dark_scheme_id"),+ undefined,+ "cookie is unchanged"+ );// Switch to saving changes in cookiesawait click(".color-scheme-checkbox input[type=checkbox]");@@ -316,16 +306,6 @@ acceptance("default dark scheme is included");- await selectKit(".dark-color-scheme .combobox").selectRowByValue(-1);- assert.strictEqual(- cookie("dark_scheme_id"),- undefined,- "cookie is not set before saving"- );-- await savePreferences();- assert.strictEqual(cookie("dark_scheme_id"), "-1", "cookie is set");-await click("button.undo-preview");assert.strictEqual(selectKit(".light-color-scheme .combobox").header().value(),@@ -342,6 +322,14 @@ acceptance(test("preview the color scheme only in current user's profile", async function (assert) {let site = Site.current();+ site.set("user_themes", [+ {+ theme_id: 2,+ name: "Cool Theme",+ color_scheme_id: 3,+ dark_color_scheme_id: 1,+ },+ ]);site.set("default_dark_color_scheme", { id: 1, name: "Dark" });site.set("user_color_schemes", [diff --git a/app/controllers/admin/themes_controller.rb b/app/controllers/admin/themes_controller.rbindex 2e4271ac983..ac662382bd6 100644--- a/app/controllers/admin/themes_controller.rb+++ b/app/controllers/admin/themes_controller.rb@@ -221,7 +221,14 @@ class Admin::ThemesController < Admin::AdminControllerraise Discourse::InvalidAccess.newend- %i[name color_scheme_id user_selectable enabled auto_update].each do |field|+ %i[+ name+ color_scheme_id+ dark_color_scheme_id+ user_selectable+ enabled+ auto_update+ ].each do |field|@theme.public_send("#{field}=", theme_params[field]) if theme_params.key?(field)end@@ -432,6 +439,7 @@ class Admin::ThemesController < Admin::AdminControllerparams.require(:theme).permit(:name,:color_scheme_id,+ :dark_color_scheme_id,:default,:user_selectable,:component,diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rbindex f3a2896755a..942717000e3 100644--- a/app/helpers/application_helper.rb+++ b/app/helpers/application_helper.rb@@ -587,7 +587,7 @@ module ApplicationHelperscheme_idelsecookies[:dark_scheme_id] || current_user&.user_option&.dark_scheme_id ||- SiteSetting.default_dark_mode_color_scheme_id+ (theme_id ? Theme.find_by_id(theme_id) : Theme.find_default)&.dark_color_scheme_id || -1endenddiff --git a/app/models/theme.rb b/app/models/theme.rbindex 2f66fd3fb03..cd5c738bef0 100644--- a/app/models/theme.rb+++ b/app/models/theme.rb@@ -11,6 +11,7 @@ class Theme < ActiveRecord::BaseEDITABLE_SYSTEM_ATTRIBUTES = %w[child_theme_idscolor_scheme_id+ dark_color_scheme_iddefaultlocaletranslations@@ -36,6 +37,7 @@ class Theme < ActiveRecord::Basebelongs_to :userbelongs_to :color_scheme+ belongs_to :dark_color_scheme, class_name: "ColorScheme"alias_method :color_palette, :color_schemehas_many :theme_fields, dependent: :destroy, validate: false@@ -1156,19 +1158,20 @@ end## Table name: themes#-# id :integer not null, primary key-# name :string not null-# user_id :integer not null-# created_at :datetime not null-# updated_at :datetime not null-# compiler_version :integer default(0), not null-# user_selectable :boolean default(FALSE), not null-# hidden :boolean default(FALSE), not null-# color_scheme_id :integer-# remote_theme_id :integer-# component :boolean default(FALSE), not null-# enabled :boolean default(TRUE), not null-# auto_update :boolean default(TRUE), not null+# id :integer not null, primary key+# auto_update :boolean default(TRUE), not null+# compiler_version :integer default(0), not null+# component :boolean default(FALSE), not null+# enabled :boolean default(TRUE), not null+# hidden :boolean default(FALSE), not null+# name :string not null+# user_selectable :boolean default(FALSE), not null+# created_at :datetime not null+# updated_at :datetime not null+# color_scheme_id :integer+# dark_color_scheme_id :integer+# remote_theme_id :integer+# user_id :integer not null## Indexes#diff --git a/app/serializers/site_serializer.rb b/app/serializers/site_serializer.rbindex 44968ce72b3..70e162bba62 100644--- a/app/serializers/site_serializer.rb+++ b/app/serializers/site_serializer.rb@@ -29,6 +29,7 @@ class SiteSerializer < ApplicationSerializer:topic_featured_link_allowed_category_ids,:user_themes,:user_color_schemes,+ :default_light_color_scheme,:default_dark_color_scheme,:censored_regexp,:shared_drafts_category_id,@@ -62,13 +63,14 @@ class SiteSerializer < ApplicationSerializerTheme.where("id = :default OR user_selectable", default: SiteSetting.default_theme_id).order("lower(name)")- .pluck(:id, :name, :color_scheme_id)- .map do |id, n, cs|+ .pluck(:id, :name, :color_scheme_id, :dark_color_scheme_id)+ .map do |id, name, color_scheme_id, dark_color_scheme_id|{theme_id: id,- name: n,+ name: name,default: id == SiteSetting.default_theme_id,- color_scheme_id: cs,+ color_scheme_id: color_scheme_id,+ dark_color_scheme_id: dark_color_scheme_id,}end.as_json@@ -85,9 +87,16 @@ class SiteSerializer < ApplicationSerializerendend+ def default_light_color_scheme+ ColorSchemeSerializer.new(+ ColorScheme.find_by_id(Theme.find_default&.color_scheme_id),+ root: false,+ ).as_json+ end+def default_dark_color_schemeColorSchemeSerializer.new(- ColorScheme.find_by_id(SiteSetting.default_dark_mode_color_scheme_id),+ ColorScheme.find_by_id(Theme.find_default&.dark_color_scheme_id),root: false,).as_jsonenddiff --git a/app/serializers/theme_serializer.rb b/app/serializers/theme_serializer.rbindex 985f1a161db..131961b1a0d 100644--- a/app/serializers/theme_serializer.rb+++ b/app/serializers/theme_serializer.rb@@ -4,6 +4,7 @@ require "base64"class ThemeSerializer < BasicThemeSerializerattributes :color_scheme_id,+ :dark_color_scheme_id,:user_selectable,:auto_update,:remote_theme_id,diff --git a/config/locales/client.en.yml b/config/locales/client.en.ymlindex ee10b6a068c..5fc90a97406 100644--- a/config/locales/client.en.yml+++ b/config/locales/client.en.yml@@ -1547,12 +1547,10 @@ en:color_scheme: "Color Palette"color_schemes:default_description: "Theme default"- disable_dark_scheme: "Same as regular"dark_instructions: "You can preview the dark mode color palette by toggling your device's dark mode."undo: "Reset"- regular: "Regular"+ regular: "Light mode"dark: "Dark mode"- default_dark_scheme: "(site default)"interface_mode: "Mode"interface_mode_instructions: "‘Auto’ uses your system’s preferences for light or dark mode."interface_modes:@@ -6895,9 +6893,12 @@ en:color_scheme_user_selectable: "Color palette can be selected by users"auto_update: "Auto update when Discourse is updated"color_scheme: "Color Palette"+ dark_color_scheme: "Dark Color Palette"edit_color_scheme: "Edit Color Palette"+ edit_dark_color_scheme: "Edit DarkWColor Palette"default_light_scheme: "Light (default)"color_scheme_select: "Select colors to be used by theme"+ dark_color_scheme_select: "Select colors to be used by theme in dark mode"custom_sections: "Custom sections:"theme_components: "Theme Components"add_all_themes: "Add all themes"@@ -7095,10 +7096,10 @@ en:title: "Select base color palette"description: "Base palette:"preference_warning: "You've changed <a href='%{link}'>your personal theme settings</a>, so palette changes may not be visible to you. Visitors that haven't changed their defaults will still see the changes you make here."- dark_mode_warning: "You're currently using dark mode. When setting an active color palette the colors will be applied to the light mode of the theme. If you want to change the default dark mode colors, please edit the <a href='%{link}'>dark mode site setting</a>."title: "Colors"edit: "Edit"- set_default: "Activate on default theme (%{theme})"+ set_default_light: "Set as light palette on default theme (%{theme})"+ set_default_dark: "Set as dark palette on default theme (%{theme})"set_default_success: "%{schemeName} set as active palette for %{themeName}"saved_refreshing: "Saved! Refreshing colors..."from_theme: "From theme: %{name}"@@ -7108,9 +7109,16 @@ en:user_selectable: "User selectable"from_theme: "From theme"no_results: "No color palettes found"- active_badge:- text: "Active"- title: "Active color palette"+ active_light_badge:+ text: "Active light"+ title: "Active light color palette"+ reset: "Reset filters"+ active_dark_badge:+ text: "Active dark"+ title: "Active light color palette"+ active_both_badge:+ text: "Active light and dark"+ title: "Active light and dark color palette"system_palette: "This is a built-in color palette, it cannot be edited or deleted."back_to_colors: "Back to color palettes"long_title: "Color palettes"diff --git a/config/locales/server.en.yml b/config/locales/server.en.ymlindex e724a9478e5..af2d71a10fc 100644--- a/config/locales/server.en.yml+++ b/config/locales/server.en.yml@@ -2227,7 +2227,6 @@ en:desktop_category_page_style: "This setting determines the visual layout of the /categories page on desktop. It includes options such as displaying subcategories with featured topics, showing the latest topics, or presenting top topics. The chosen style will influence how users interact and navigate through categories on the site."mobile_category_page_style: "This setting determines the visual layout of the /categories page on mobile."category_colors: "A list of hexadecimal color values allowed for categories."- default_dark_mode_color_scheme_id: "The color palette used when in dark mode."dark_mode_none: "None"max_image_size_kb: "The maximum image upload size. This must be configured in nginx (client_max_body_size) / apache or proxy as well. Images larger than this and smaller than client_max_body_size will be resized to fit on upload."diff --git a/config/site_settings.yml b/config/site_settings.ymlindex b4d6f467a44..f4fa2d87e6d 100644--- a/config/site_settings.yml+++ b/config/site_settings.yml@@ -367,11 +367,6 @@ basic:default_theme_id:default: -1hidden: true- default_dark_mode_color_scheme_id:- default: -1- type: enum- enum: "ColorSchemeSetting"- client: truerelative_date_duration:client: truedefault: 30diff --git a/db/fixtures/600_themes.rb b/db/fixtures/600_themes.rbindex 1994be3ccdc..75e97b40c9a 100644--- a/db/fixtures/600_themes.rb+++ b/db/fixtures/600_themes.rb@@ -30,10 +30,6 @@ if !theme_existsTheme.foundation_theme.set_default!- if SiteSetting.default_dark_mode_color_scheme_id ==- SiteSetting.defaults[:default_dark_mode_color_scheme_id]- dark_scheme_id = ColorScheme.where(base_scheme_id: "Dark").pick(:id)-- SiteSetting.default_dark_mode_color_scheme_id = dark_scheme_id if dark_scheme_id.present?- end+ dark_scheme_id = ColorScheme.where(base_scheme_id: "Dark").pick(:id)+ Theme.foundation_theme.update!(dark_color_scheme_id: dark_scheme_id) if dark_scheme_id.present?enddiff --git a/db/migrate/20250722074045_add_dark_color_scheme_id_to_themes.rb b/db/migrate/20250722074045_add_dark_color_scheme_id_to_themes.rbnew file mode 100644index 00000000000..59dbe93fdb8--- /dev/null+++ b/db/migrate/20250722074045_add_dark_color_scheme_id_to_themes.rb@@ -0,0 +1,6 @@+# frozen_string_literal: true+class AddDarkColorSchemeIdToThemes < ActiveRecord::Migration[7.2]+ def change+ add_column :themes, :dark_color_scheme_id, :integer, default: nil+ end+enddiff --git a/db/migrate/20250729044139_fill_in_dark_color_scheme_id.rb b/db/migrate/20250729044139_fill_in_dark_color_scheme_id.rbnew file mode 100644index 00000000000..da2a4014ce5--- /dev/null+++ b/db/migrate/20250729044139_fill_in_dark_color_scheme_id.rb@@ -0,0 +1,24 @@+# frozen_string_literal: true+class FillInDarkColorSchemeId < ActiveRecord::Migration[8.0]+ def up+ dark_scheme_id =+ DB.query_single(+ "SELECT value FROM site_settings WHERE name = 'default_dark_mode_color_scheme_id' LIMIT 1",+ ).first++ return if !dark_scheme_id+ execute "DELETE from site_settings where name = 'default_dark_mode_color_scheme_id'"+ if DB.query_single("SELECT 1 FROM color_schemes WHERE id = #{dark_scheme_id}").first.blank?+ return+ end+ execute <<~SQL+ UPDATE themes+ SET dark_color_scheme_id = #{dark_scheme_id}+ WHERE dark_color_scheme_id IS NULL+ SQL+ end++ def down+ raise ActiveRecord::IrreversibleMigration+ end+enddiff --git a/lib/stylesheet/manager.rb b/lib/stylesheet/manager.rbindex 6b1bf8cca33..0e155417b23 100644--- a/lib/stylesheet/manager.rb+++ b/lib/stylesheet/manager.rb@@ -79,10 +79,10 @@ class Stylesheet::ManagerTheme.where("user_selectable OR id = ?", SiteSetting.default_theme_id).pluck(:id,:color_scheme_id,+ :dark_color_scheme_id,)color_schemes = ColorScheme.where(user_selectable: true).to_a- color_schemes << ColorScheme.find_by(id: SiteSetting.default_dark_mode_color_scheme_id)color_schemes << ColorScheme.basecolor_schemes = color_schemes.compact.uniq@@ -90,7 +90,7 @@ class Stylesheet::Managertargets += targets.map { |t| :"#{t}_rtl" }compiled = Set.new- themes.each do |theme_id, color_scheme_id|+ themes.each do |theme_id, light_color_scheme_id, dark_color_scheme_id|manager = self.new(theme_id: theme_id)targets.each do |target|@@ -113,10 +113,10 @@ class Stylesheet::Managerendend- theme_color_scheme = ColorScheme.find_by_id(color_scheme_id)+ theme_color_scheme = ColorScheme.find_by_id(light_color_scheme_id)+ theme_dark_color_scheme = ColorScheme.find_by_id(dark_color_scheme_id)theme = manager.get_theme(theme_id)-- [theme_color_scheme, *color_schemes].compact.uniq.each do |scheme|+ [theme_color_scheme, theme_dark_color_scheme, *color_schemes].compact.uniq.each do |scheme|[true, false].each do |dark|mode = dark ? "dark" : "light"$stderr.puts "precompile target: #{COLOR_SCHEME_STYLESHEET} #{theme.name} (#{scheme.name}) (#{mode})"diff --git a/lib/system_themes_manager.rb b/lib/system_themes_manager.rbindex 881c6ff1933..7a686b4f2c4 100644--- a/lib/system_themes_manager.rb+++ b/lib/system_themes_manager.rb@@ -20,11 +20,13 @@ class SystemThemesManagerelse"#{remote_theme.color_scheme.name} Dark"end- remote_theme- .color_schemes- .where(name: alternative_theme_name)- .first- &.update!(user_selectable: true)++ alternative_color_scheme =+ remote_theme.color_schemes.where(name: alternative_theme_name).first+ alternative_color_scheme&.update!(user_selectable: true)+ if remote_theme.dark_color_scheme.blank? && alternative_color_scheme+ remote_theme.update!(dark_color_scheme: alternative_color_scheme)+ endendremote_theme.update_column(:enabled, true)Stylesheet::Manager.clear_theme_cache!diff --git a/plugins/styleguide/assets/javascripts/discourse/components/toggle-color-mode.gjs b/plugins/styleguide/assets/javascripts/discourse/components/toggle-color-mode.gjsindex fa4300cc63f..9f439fd98e9 100644--- a/plugins/styleguide/assets/javascripts/discourse/components/toggle-color-mode.gjs+++ b/plugins/styleguide/assets/javascripts/discourse/components/toggle-color-mode.gjs@@ -48,6 +48,7 @@ function colorSchemeOverride(type) {export default class ToggleColorMode extends Component {@service keyValueStore;@service siteSettings;+ @service site;@tracked colorSchemeOverride = this.default;@tracked shouldRender = true;@@ -58,9 +59,9 @@ export default class ToggleColorMode extends Component {// If site has a dark color scheme set but user doesn't auto switch in dark mode// we need to load the stylesheet manuallyif (!document.querySelector("link.dark-scheme")) {- if (this.siteSettings.default_dark_mode_color_scheme_id > 0) {+ if (this.site.default_dark_color_scheme.id > 0) {loadColorSchemeStylesheet(- this.siteSettings.default_dark_mode_color_scheme_id,+ this.site.default_dark_color_scheme.id,currentThemeId(),true);diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rbindex 607656ff004..bc6b649ef70 100644--- a/spec/helpers/application_helper_spec.rb+++ b/spec/helpers/application_helper_spec.rb@@ -817,7 +817,7 @@ RSpec.describe ApplicationHelper doendit "returns two color scheme link tags when dark mode is enabled" do- SiteSetting.default_dark_mode_color_scheme_id = ColorScheme.where(name: "Dark").pick(:id)+ Theme.find_default.update!(dark_color_scheme_id: ColorScheme.where(name: "Dark").pick(:id))cs_stylesheets = helper.discourse_color_scheme_stylesheetsexpect(cs_stylesheets).to include("(prefers-color-scheme: dark)")@@ -826,7 +826,7 @@ RSpec.describe ApplicationHelper doit "handles a missing dark color scheme gracefully" doscheme = ColorScheme.create!(name: "pyramid")- SiteSetting.default_dark_mode_color_scheme_id = scheme.id+ Theme.find_default.update!(dark_color_scheme_id: scheme.id)scheme.destroy!cs_stylesheets = helper.discourse_color_scheme_stylesheets@@ -873,7 +873,7 @@ RSpec.describe ApplicationHelper dohelper.request.env[Auth::DefaultCurrentUserProvider::CURRENT_USER_KEY] = user@new_cs = Fabricate(:color_scheme, name: "Custom Color Scheme")- SiteSetting.default_dark_mode_color_scheme_id = ColorScheme.where(name: "Dark").pick(:id)+ Theme.find_default.update!(dark_color_scheme_id: ColorScheme.where(name: "Dark").pick(:id))endit "returns no dark scheme stylesheet when user has disabled that option" do@@ -974,7 +974,7 @@ RSpec.describe ApplicationHelper doendit "doesn't render theme-color meta tag for the dark scheme if none is set" do- SiteSetting.default_dark_mode_color_scheme_id = -1+ Theme.find_default.update!(dark_color_scheme_id: -1)helper.request.cookies.delete("dark_scheme_id")expect(helper.discourse_theme_color_meta_tags).to eq(<<~HTML)@@ -997,7 +997,7 @@ RSpec.describe ApplicationHelper dodescribe "#discourse_color_scheme_meta_tag" dofab!(:color_scheme)- before { SiteSetting.default_dark_mode_color_scheme_id = -1 }+ before { Theme.find_default.update!(dark_color_scheme_id: -1) }it "renders a 'light' color-scheme if no dark scheme is set and the current scheme is light" doColorSchemeRevisor.revise(diff --git a/spec/models/site_spec.rb b/spec/models/site_spec.rbindex f66032259a0..c73b4da69ed 100644--- a/spec/models/site_spec.rb+++ b/spec/models/site_spec.rb@@ -11,13 +11,14 @@ RSpec.describe Site doTheme.where("id = :default OR user_selectable", default: SiteSetting.default_theme_id).order(:name)- .pluck(:id, :name, :color_scheme_id)- .map do |id, n, cs|+ .pluck(:id, :name, :color_scheme_id, :dark_color_scheme_id)+ .map do |id, name, color_scheme_id, dark_color_scheme_id|{"theme_id" => id,- "name" => n,+ "name" => name,"default" => id == SiteSetting.default_theme_id,- "color_scheme_id" => cs,+ "color_scheme_id" => color_scheme_id,+ "dark_color_scheme_id" => dark_color_scheme_id,}enddiff --git a/spec/requests/api/schemas/json/site_response.json b/spec/requests/api/schemas/json/site_response.jsonindex c33f0734255..667ee8df55e 100644--- a/spec/requests/api/schemas/json/site_response.json+++ b/spec/requests/api/schemas/json/site_response.json@@ -510,6 +510,12 @@"integer","null"]+ },+ "dark_color_scheme_id": {+ "type": [+ "integer",+ "null"+ ]}},"required": [@@ -551,6 +557,12 @@]}},+ "default_light_color_scheme": {+ "type": [+ "object",+ "null"+ ]+ },"default_dark_color_scheme": {"type": ["object",@@ -925,6 +937,7 @@"topic_featured_link_allowed_category_ids","user_themes","user_color_schemes",+ "default_light_color_scheme","default_dark_color_scheme","censored_regexp","custom_emoji_translation",diff --git a/spec/requests/application_controller_spec.rb b/spec/requests/application_controller_spec.rbindex bdd66b65d05..ef8bb9e1696 100644--- a/spec/requests/application_controller_spec.rb+++ b/spec/requests/application_controller_spec.rb@@ -668,9 +668,11 @@ RSpec.describe ApplicationController dolet!(:dark_scheme) { ColorScheme.find_by(base_scheme_id: "Dark") }before do- SiteSetting.default_dark_mode_color_scheme_id = dark_scheme.idSiteSetting.interface_color_selector = "sidebar_footer"- Theme.find_by(id: SiteSetting.default_theme_id).update!(color_scheme_id: light_scheme.id)+ Theme.find_default.update!(+ color_scheme_id: light_scheme.id,+ dark_color_scheme_id: dark_scheme.id,+ )endcontext "when light mode is forced" do@@ -1625,7 +1627,7 @@ RSpec.describe ApplicationController dolet!(:dark_scheme) { ColorScheme.find_by(base_scheme_id: "Dark") }before do- SiteSetting.default_dark_mode_color_scheme_id = dark_scheme.id+ Theme.find_default.update!(dark_color_scheme_id: dark_scheme.id)SiteSetting.interface_color_selector = "sidebar_footer"enddiff --git a/spec/serializers/site_serializer_spec.rb b/spec/serializers/site_serializer_spec.rbindex c3f7272b8ed..a4866cc7a08 100644--- a/spec/serializers/site_serializer_spec.rb+++ b/spec/serializers/site_serializer_spec.rb@@ -113,11 +113,11 @@ RSpec.describe SiteSerializer doit "includes default dark mode scheme" doscheme = ColorScheme.last- SiteSetting.default_dark_mode_color_scheme_id = scheme.id+ Theme.find_default.update!(dark_color_scheme_id: scheme.id)serialized = described_class.new(Site.new(guardian), scope: guardian, root: false).as_jsondefault_dark_scheme = expect(serialized[:default_dark_color_scheme][:name]).to eq(scheme.name)- SiteSetting.default_dark_mode_color_scheme_id = -1+ Theme.find_default.update!(dark_color_scheme_id: nil)serialized = described_class.new(Site.new(guardian), scope: guardian, root: false).as_jsonexpect(serialized[:default_dark_color_scheme]).to eq(nil)enddiff --git a/spec/serializers/theme_serializer_spec.rb b/spec/serializers/theme_serializer_spec.rbindex 18320274f80..2423520d2c8 100644--- a/spec/serializers/theme_serializer_spec.rb+++ b/spec/serializers/theme_serializer_spec.rb@@ -24,6 +24,19 @@ RSpec.describe ThemeSerializer doendend+ describe "color schemes" do+ fab!(:theme) { Fabricate(:theme, color_scheme_id: 1, dark_color_scheme_id: 2) }+ let(:serialized) { ThemeSerializer.new(theme.reload).as_json[:theme] }++ it "should include color scheme id" do+ expect(serialized[:color_scheme_id]).to eq(1)+ end++ it "should include dark color scheme id" do+ expect(serialized[:dark_color_scheme_id]).to eq(2)+ end+ end+describe "screenshot_url" dofab!(:theme)let(:serialized) { ThemeSerializer.new(theme.reload).as_json[:theme] }diff --git a/spec/system/admin_color_palettes_features_spec.rb b/spec/system/admin_color_palettes_features_spec.rbindex 556b16e2a3d..c231c675c2f 100644--- a/spec/system/admin_color_palettes_features_spec.rb+++ b/spec/system/admin_color_palettes_features_spec.rb@@ -91,6 +91,46 @@ describe "Admin Color Palettes Features", type: :system doexpect(page).to have_css(".theme-card__badge.--selectable")endend++ it "can set as light and dark default for theme" do+ visit("/admin/customize/colors")++ within("[data-palette-id='#{regular_palette.id}']") { find(".btn-flat").click }++ expect(page).to have_css(".dropdown-menu")++ click_button(+ I18n.t(+ "admin_js.admin.customize.colors.set_default_light",+ { theme: Theme.find_default.name },+ ),+ )++ within("[data-palette-id='#{regular_palette.id}']") do+ expect(page).to have_css(+ ".theme-card__badge.--active",+ text: I18n.t("admin_js.admin.customize.colors.active_light_badge.text").upcase,+ )+ end++ within("[data-palette-id='#{regular_palette.id}']") { find(".btn-flat").click }++ expect(page).to have_css(".dropdown-menu")++ click_button(+ I18n.t(+ "admin_js.admin.customize.colors.set_default_dark",+ { theme: Theme.find_default.name },+ ),+ )++ within("[data-palette-id='#{regular_palette.id}']") do+ expect(page).to have_css(+ ".theme-card__badge.--active",+ text: I18n.t("admin_js.admin.customize.colors.active_both_badge.text").upcase,+ )+ end+ endenddescribe "CSS variables" dodiff --git a/spec/system/admin_customize_themes_spec.rb b/spec/system/admin_customize_themes_spec.rbindex d6879402ce8..fb58ad6b544 100644--- a/spec/system/admin_customize_themes_spec.rb+++ b/spec/system/admin_customize_themes_spec.rb@@ -1,7 +1,7 @@# frozen_string_literal: truedescribe "Admin Customize Themes", type: :system do- fab!(:color_scheme)+ fab!(:color_scheme) { Fabricate(:color_scheme, base_scheme_id: "light") }fab!(:theme) { Fabricate(:theme, name: "Cool theme 1", user_selectable: true) }fab!(:admin) { Fabricate(:admin, locale: "en") }@@ -11,21 +11,38 @@ describe "Admin Customize Themes", type: :system dobefore { sign_in(admin) }describe "when visiting the page to customize a single theme" do- it "should allow admin to update the color scheme of the theme" do+ it "should allow admin to update the light color scheme of the theme" dovisit("/admin/customize/themes/#{theme.id}")- color_scheme_settings = find(".theme-settings__color-scheme")+ color_scheme_settings = find(".theme-settings__light-color-scheme")- expect(color_scheme_settings).to have_no_css(".submit-edit")- expect(color_scheme_settings).to have_no_css(".cancel-edit")+ expect(color_scheme_settings).to have_no_css(".submit-light-edit")+ expect(color_scheme_settings).to have_no_css(".cancel-light-edit")color_scheme_settings.find(".color-palettes").clickcolor_scheme_settings.find(".color-palettes-row[data-value='#{color_scheme.id}']").click- color_scheme_settings.find(".submit-edit").click+ color_scheme_settings.find(".submit-light-edit").clickexpect(color_scheme_settings.find(".setting-value")).to have_content(color_scheme.name)- expect(color_scheme_settings).to have_no_css(".submit-edit")- expect(color_scheme_settings).to have_no_css(".cancel-edit")+ expect(color_scheme_settings).to have_no_css(".submit-light-edit")+ expect(color_scheme_settings).to have_no_css(".cancel-light-edit")+ end++ it "should allow admin to update the dark color scheme of the theme" do+ visit("/admin/customize/themes/#{theme.id}")++ color_scheme_settings = find(".theme-settings__dark-color-scheme")++ expect(color_scheme_settings).not_to have_css(".submit-dark-edit")+ expect(color_scheme_settings).not_to have_css(".cancel-dark-edit")++ color_scheme_settings.find(".color-palettes").click+ color_scheme_settings.find(".color-palettes-row[data-value='#{color_scheme.id}']").click+ color_scheme_settings.find(".submit-dark-edit").click++ expect(color_scheme_settings.find(".setting-value")).to have_content(color_scheme.name)+ expect(color_scheme_settings).not_to have_css(".submit-dark-edit")+ expect(color_scheme_settings).not_to have_css(".cancel-dark-edit")endenddiff --git a/spec/system/interface_color_selector_spec.rb b/spec/system/interface_color_selector_spec.rbindex c708c26f844..647195e770e 100644--- a/spec/system/interface_color_selector_spec.rb+++ b/spec/system/interface_color_selector_spec.rb@@ -39,14 +39,14 @@ describe "Interface color selector", type: :system dobefore doSiteSetting.interface_color_selector = "sidebar_footer"- SiteSetting.default_dark_mode_color_scheme_id = dark_scheme.id+ Theme.find_default.update!(dark_color_scheme_id: dark_scheme.id)SiteSetting.logo = light_mode_imageSiteSetting.logo_dark = dark_mode_imageendit "is not available when there's no default dark scheme" do- SiteSetting.default_dark_mode_color_scheme_id = -1+ Theme.find_default.update!(dark_color_scheme_id: nil)visit("/")@@ -54,7 +54,7 @@ describe "Interface color selector", type: :system doendit "is not available when the default theme's scheme is the same as the site's default dark scheme" do- Theme.find(SiteSetting.default_theme_id).update!(color_scheme_id: dark_scheme.id)+ Theme.find_default.update!(color_scheme_id: dark_scheme.id)visit("/")