File tree Expand file tree Collapse file tree 7 files changed +74
-0
lines changed
generators/rails/app/templates Expand file tree Collapse file tree 7 files changed +74
-0
lines changed Original file line number Diff line number Diff line change
1
+ * Add default PWA files for manifest and service-worker that are served from ` app/views/pwa ` and can be dynamically rendered through erb. Mount these files explicitly at the root with default routes in the generated routes file.
2
+
3
+ * DHH*
4
+
1
5
* Updated system tests to now use headless Chrome by default for the new applications.
2
6
3
7
* DHH*
Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ module Rails
31
31
autoload :Info
32
32
autoload :InfoController
33
33
autoload :MailersController
34
+ autoload :PwaController
34
35
autoload :WelcomeController
35
36
36
37
class << self
Original file line number Diff line number Diff line change 3
3
<head>
4
4
<title><%%= content_for(:title) || "<%= camelized %>" %></title>
5
5
<meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <meta name="apple-mobile-web-app-capable" content="yes">
6
7
<%%= csrf_meta_tags %>
7
8
<%%= csp_meta_tag %>
8
9
9
10
<%%= yield :head %>
10
11
12
+ <link rel="manifest" href="/manifest.json">
11
13
<link rel="icon" href="/icon.png" type="image/png">
12
14
<link rel="apple-touch-icon" href="/icon.png" sizes="512x512">
13
15
<%- if options[:skip_hotwire] || options[:skip_javascript] -%>
Original file line number Diff line number Diff line change
1
+ {
2
+ "name": "<%= camelized %>",
3
+ "icons": [
4
+ {
5
+ "src": "/icon.png",
6
+ "type": "image/png",
7
+ "sizes": "512x512"
8
+ },
9
+ {
10
+ "src": "/icon.png",
11
+ "type": "image/png",
12
+ "sizes": "512x512",
13
+ "purpose": "maskable"
14
+ }
15
+ ],
16
+ "start_url": "/",
17
+ "display": "standalone",
18
+ "scope": "/",
19
+ "description": "<%= camelized %>.",
20
+ "theme_color": "red",
21
+ "background_color": "red"
22
+ }
Original file line number Diff line number Diff line change
1
+ // Add a service worker for processing Web Push notifications:
2
+ //
3
+ // self.addEventListener("push", async (event) => {
4
+ // const { title, options } = await event.data.json()
5
+ // event.waitUntil(self.registration.showNotification(title, options))
6
+ // })
7
+ //
8
+ // self.addEventListener("notificationclick", function(event) {
9
+ // event.notification.close()
10
+ // event.waitUntil(
11
+ // clients.matchAll({ type: "window" }).then((clientList) => {
12
+ // for (let i = 0; i < clientList.length; i++) {
13
+ // let client = clientList[i]
14
+ // let clientPath = (new URL(client.url)).pathname
15
+ //
16
+ // if (clientPath == event.notification.data.path && "focus" in client) {
17
+ // return client.focus()
18
+ // }
19
+ // }
20
+ //
21
+ // if (clients.openWindow) {
22
+ // return clients.openWindow(event.notification.data.path)
23
+ // }
24
+ // })
25
+ // )
26
+ // })
Original file line number Diff line number Diff line change @@ -5,6 +5,10 @@ Rails.application.routes.draw do
5
5
# Can be used by load balancers and uptime monitors to verify that the app is live.
6
6
get "up" => "rails/health#show", as: :rails_health_check
7
7
8
+ # Render dynamic PWA files from app/views/pwa/*
9
+ get "service-worker" => "rails/pwa#service_worker", as: :pwa_service_worker
10
+ get "manifest" => "rails/pwa#manifest", as: :pwa_manifest
11
+
8
12
# Defines the root path route ("/")
9
13
# root "posts#index"
10
14
end
Original file line number Diff line number Diff line change
1
+ # frozen_string_literal: true
2
+
3
+ require "rails/application_controller"
4
+
5
+ class Rails ::PwaController < Rails ::ApplicationController # :nodoc:
6
+ skip_forgery_protection
7
+
8
+ def service_worker
9
+ render template : "pwa/service-worker" , layout : false
10
+ end
11
+
12
+ def manifest
13
+ render template : "pwa/manifest" , layout : false
14
+ end
15
+ end
You can’t perform that action at this time.
0 commit comments