Skip to content

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

DEV: fix live refresh if you have a custom theme selected in dev

Samff90881238ef
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index c01ad86f1e1..fa8e02832ac 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -58,6 +58,16 @@ class ApplicationController < ActionController::Base
layout :set_layout
+ if Rails.env == "development"
+ after_action :remember_theme_key
+
+ def remember_theme_key
+ if @theme_key
+ Stylesheet::Watcher.theme_key = @theme_key if defined? Stylesheet::Watcher
+ end
+ end
+ end
+
def has_escaped_fragment?
SiteSetting.enable_escaped_fragments? && params.key?("_escaped_fragment_")
end
diff --git a/lib/stylesheet/watcher.rb b/lib/stylesheet/watcher.rb
index 952118ba454..a1150e734f9 100644
--- a/lib/stylesheet/watcher.rb
+++ b/lib/stylesheet/watcher.rb
@@ -3,6 +3,14 @@ require 'listen'
module Stylesheet
class Watcher
+ def self.theme_key=(v)
+ @theme_key = v
+ end
+
+ def self.theme_key
+ @theme_key || SiteSetting.default_theme_key
+ end
+
def self.watch(paths = nil)
watcher = new(paths)
watcher.start
@@ -71,7 +79,7 @@ module Stylesheet
{
target: name,
new_href: Stylesheet::Manager.stylesheet_href(name.to_sym),
- theme_key: SiteSetting.default_theme_key
+ theme_key: Stylesheet::Watcher.theme_key
}
end
MessageBus.publish '/file-change', message