Skip to content

A platform for community discussion. Free, open, simple.

FIX: Don't make Horizon's palettes user-selectable (#34062)

Osama Sayegh507a90e93a6d
diff --git a/lib/system_themes_manager.rb b/lib/system_themes_manager.rb
index 7a686b4f2c4..200e36d8351 100644
--- a/lib/system_themes_manager.rb
+++ b/lib/system_themes_manager.rb
@@ -11,24 +11,19 @@ class SystemThemesManager
theme_dir = "#{Rails.root}/themes/#{theme_name}"
+ is_initial_install = !Theme.exists?(id: theme_id)
+
remote_theme = RemoteTheme.import_theme_from_directory(theme_dir, theme_id: theme_id)
- if remote_theme.color_scheme
- remote_theme.color_scheme.update!(user_selectable: true)
- alternative_theme_name =
- if remote_theme.color_scheme.name =~ / Dark$/
- remote_theme.color_scheme.name.sub(" Dark", "")
- else
- "#{remote_theme.color_scheme.name} Dark"
- end
-
- 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)
+ remote_theme.update_column(:enabled, true)
+
+ if is_initial_install
+ if theme_id == Theme::CORE_THEMES["horizon"]
+ remote_theme.update!(
+ dark_color_scheme: remote_theme.color_schemes.find_by(name: "Horizon Dark"),
+ )
end
end
- remote_theme.update_column(:enabled, true)
+
Stylesheet::Manager.clear_theme_cache!
end
diff --git a/spec/lib/system_themes_manager_spec.rb b/spec/lib/system_themes_manager_spec.rb
index 3d9cbc8fa9e..0f75c230251 100644
--- a/spec/lib/system_themes_manager_spec.rb
+++ b/spec/lib/system_themes_manager_spec.rb
@@ -19,4 +19,21 @@ RSpec.describe SystemThemesManager do
SystemThemesManager.sync!
expect(Theme.horizon_theme.reload.enabled).to be true
end
+
+ it "sets up the default light and dark palettes for Horizon on the initial install" do
+ Theme.delete_all
+
+ expect { SystemThemesManager.sync! }.to change { Theme.system.count }.by(2)
+
+ expect(Theme.horizon_theme.color_scheme.name).to eq("Horizon")
+ expect(Theme.horizon_theme.dark_color_scheme.name).to eq("Horizon Dark")
+
+ Theme.horizon_theme.update!(color_scheme: nil)
+ Theme.horizon_theme.update!(dark_color_scheme: nil)
+
+ expect { SystemThemesManager.sync! }.not_to change { Theme.system.count }
+
+ expect(Theme.horizon_theme.color_scheme).to eq(nil)
+ expect(Theme.horizon_theme.dark_color_scheme).to eq(nil)
+ end
end