mirror of
https://github.com/discourse/discourse.git
synced 2025-09-08 12:06:51 +08:00
Feature: Add service worker registration method to plugin API
This commit is contained in:
parent
46f8a6c97d
commit
b094894c94
9 changed files with 93 additions and 23 deletions
|
@ -29,6 +29,7 @@ class Plugin::Instance
|
|||
:color_schemes,
|
||||
:initializers,
|
||||
:javascripts,
|
||||
:service_workers,
|
||||
:styles,
|
||||
:themes].each do |att|
|
||||
class_eval %Q{
|
||||
|
@ -332,6 +333,13 @@ class Plugin::Instance
|
|||
assets << [full_path, opts]
|
||||
end
|
||||
|
||||
def register_service_worker(file, opts = nil)
|
||||
service_workers << [
|
||||
File.join(File.dirname(path), 'assets', file),
|
||||
opts
|
||||
]
|
||||
end
|
||||
|
||||
def register_color_scheme(name, colors)
|
||||
color_schemes << { name: name, colors: colors }
|
||||
end
|
||||
|
@ -420,6 +428,8 @@ JS
|
|||
|
||||
register_assets! unless assets.blank?
|
||||
|
||||
register_service_workers!
|
||||
|
||||
seed_data.each do |key, value|
|
||||
DiscoursePluginRegistry.register_seed_data(key, value)
|
||||
end
|
||||
|
@ -516,6 +526,12 @@ JS
|
|||
end
|
||||
end
|
||||
|
||||
def register_service_workers!
|
||||
service_workers.each do |asset, opts|
|
||||
DiscoursePluginRegistry.register_service_worker(asset, opts)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def write_asset(path, contents)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue