mirror of
https://github.com/discourse/discourse.git
synced 2025-06-08 00:27:32 +08:00
FEATURE: Enable auto dark mode on new instances (#14208)
This commit is contained in:
@ -18,4 +18,12 @@ if !Theme.exists?
|
|||||||
name = I18n.t('color_schemes.default_theme_name')
|
name = I18n.t('color_schemes.default_theme_name')
|
||||||
default_theme = Theme.create!(name: name, user_id: -1)
|
default_theme = Theme.create!(name: name, user_id: -1)
|
||||||
default_theme.set_default!
|
default_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").pluck_first(:id)
|
||||||
|
|
||||||
|
if dark_scheme_id.present?
|
||||||
|
SiteSetting.default_dark_mode_color_scheme_id = dark_scheme_id
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -203,6 +203,14 @@ class Wizard
|
|||||||
updater.update_setting(:base_font, updater.fields[:body_font])
|
updater.update_setting(:base_font, updater.fields[:body_font])
|
||||||
updater.update_setting(:heading_font, updater.fields[:heading_font])
|
updater.update_setting(:heading_font, updater.fields[:heading_font])
|
||||||
|
|
||||||
|
if updater.fields[:homepage_style] == 'latest'
|
||||||
|
top_menu = "latest|new|unread|top|categories"
|
||||||
|
else
|
||||||
|
top_menu = "categories|latest|new|unread|top"
|
||||||
|
updater.update_setting(:desktop_category_page_style, updater.fields[:homepage_style])
|
||||||
|
end
|
||||||
|
updater.update_setting(:top_menu, top_menu)
|
||||||
|
|
||||||
scheme_name = (
|
scheme_name = (
|
||||||
(updater.fields[:color_scheme] || "") ||
|
(updater.fields[:color_scheme] || "") ||
|
||||||
ColorScheme::LIGHT_THEME_ID
|
ColorScheme::LIGHT_THEME_ID
|
||||||
@ -228,13 +236,9 @@ class Wizard
|
|||||||
theme.set_default!
|
theme.set_default!
|
||||||
end
|
end
|
||||||
|
|
||||||
if updater.fields[:homepage_style] == 'latest'
|
if scheme.is_dark?
|
||||||
top_menu = "latest|new|unread|top|categories"
|
updater.update_setting(:default_dark_mode_color_scheme_id, -1)
|
||||||
else
|
|
||||||
top_menu = "categories|latest|new|unread|top"
|
|
||||||
updater.update_setting(:desktop_category_page_style, updater.fields[:homepage_style])
|
|
||||||
end
|
end
|
||||||
updater.update_setting(:top_menu, top_menu)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -169,7 +169,11 @@ describe Wizard::StepUpdater do
|
|||||||
|
|
||||||
context "styling step" do
|
context "styling step" do
|
||||||
it "updates fonts" do
|
it "updates fonts" do
|
||||||
updater = wizard.create_updater('styling', body_font: 'open_sans', heading_font: 'oswald')
|
updater = wizard.create_updater('styling',
|
||||||
|
body_font: 'open_sans',
|
||||||
|
heading_font: 'oswald',
|
||||||
|
homepage_style: 'latest'
|
||||||
|
)
|
||||||
updater.update
|
updater.update
|
||||||
expect(updater.success?).to eq(true)
|
expect(updater.success?).to eq(true)
|
||||||
expect(wizard.completed_steps?('styling')).to eq(true)
|
expect(wizard.completed_steps?('styling')).to eq(true)
|
||||||
@ -182,7 +186,12 @@ describe Wizard::StepUpdater do
|
|||||||
fab!(:color_scheme) { Fabricate(:color_scheme, name: 'existing', via_wizard: true) }
|
fab!(:color_scheme) { Fabricate(:color_scheme, name: 'existing', via_wizard: true) }
|
||||||
|
|
||||||
it "updates the scheme" do
|
it "updates the scheme" do
|
||||||
updater = wizard.create_updater('styling', color_scheme: 'Dark', body_font: 'arial', heading_font: 'arial', homepage_style: 'latest')
|
updater = wizard.create_updater('styling',
|
||||||
|
color_scheme: 'Dark',
|
||||||
|
body_font: 'arial',
|
||||||
|
heading_font: 'arial',
|
||||||
|
homepage_style: 'latest'
|
||||||
|
)
|
||||||
updater.update
|
updater.update
|
||||||
expect(updater.success?).to eq(true)
|
expect(updater.success?).to eq(true)
|
||||||
expect(wizard.completed_steps?('styling')).to eq(true)
|
expect(wizard.completed_steps?('styling')).to eq(true)
|
||||||
@ -277,12 +286,41 @@ describe Wizard::StepUpdater do
|
|||||||
expect(theme.color_scheme_id).to eq(color_scheme.id)
|
expect(theme.color_scheme_id).to eq(color_scheme.id)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "auto dark mode" do
|
||||||
|
before do
|
||||||
|
dark_scheme = ColorScheme.where(name: "Dark").first
|
||||||
|
SiteSetting.default_dark_mode_color_scheme_id = dark_scheme.id
|
||||||
|
end
|
||||||
|
|
||||||
|
it "does nothing when selected scheme is light" do
|
||||||
|
updater = wizard.create_updater('styling',
|
||||||
|
color_scheme: 'Neutral',
|
||||||
|
body_font: 'arial',
|
||||||
|
heading_font: 'arial',
|
||||||
|
homepage_style: 'latest'
|
||||||
|
)
|
||||||
|
|
||||||
|
expect { updater.update }.not_to change { SiteSetting.default_dark_mode_color_scheme_id }
|
||||||
|
end
|
||||||
|
|
||||||
|
it "unsets auto dark mode site setting when default selected scheme is also dark" do
|
||||||
|
updater = wizard.create_updater('styling',
|
||||||
|
color_scheme: 'Latte',
|
||||||
|
body_font: 'arial',
|
||||||
|
heading_font: 'arial',
|
||||||
|
homepage_style: 'latest'
|
||||||
|
)
|
||||||
|
|
||||||
|
expect { updater.update }.to change { SiteSetting.default_dark_mode_color_scheme_id }.to(-1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context "homepage style" do
|
context "homepage style" do
|
||||||
it "updates the fields correctly" do
|
it "updates the fields correctly" do
|
||||||
updater = wizard.create_updater('styling',
|
updater = wizard.create_updater('styling',
|
||||||
color_scheme: 'Dark',
|
|
||||||
body_font: 'arial',
|
body_font: 'arial',
|
||||||
heading_font: 'arial',
|
heading_font: 'arial',
|
||||||
homepage_style: "categories_and_top_topics"
|
homepage_style: "categories_and_top_topics"
|
||||||
@ -295,7 +333,6 @@ describe Wizard::StepUpdater do
|
|||||||
expect(SiteSetting.desktop_category_page_style).to eq('categories_and_top_topics')
|
expect(SiteSetting.desktop_category_page_style).to eq('categories_and_top_topics')
|
||||||
|
|
||||||
updater = wizard.create_updater('styling',
|
updater = wizard.create_updater('styling',
|
||||||
color_scheme: 'Dark',
|
|
||||||
body_font: 'arial',
|
body_font: 'arial',
|
||||||
heading_font: 'arial',
|
heading_font: 'arial',
|
||||||
homepage_style: "latest"
|
homepage_style: "latest"
|
||||||
|
Reference in New Issue
Block a user