Skip to content

Commit e417e26

Browse files
committed
Add a very basic PWA
1 parent 4eade70 commit e417e26

7 files changed

Lines changed: 76 additions & 26 deletions

File tree

app/views/layouts/application.html.erb

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,19 @@
33
<head>
44
<title><%= content_for?(:html_title) ? yield(:html_title) : "Visualizer" %></title>
55
<meta content="width=device-width, initial-scale=1, viewport-fit=cover" name="viewport">
6+
<meta name="apple-mobile-web-app-capable" content="yes">
7+
<meta name="mobile-web-app-capable" content="yes">
68
<meta content="#ffffff" media="(prefers-color-scheme: light)" name="theme-color">
79
<meta content="#171717" media="(prefers-color-scheme: dark)" name="theme-color">
8-
<%= yield :head %>
910
<%= csrf_meta_tags %>
1011
<%= csp_meta_tag %>
11-
<link href="/apple-touch-icon.png?v=4" rel="apple-touch-icon" sizes="180x180">
12-
<link href="/favicon-32x32.png?v=4" rel="icon" sizes="32x32" type="image/png">
13-
<link href="/favicon-16x16.png?v=4" rel="icon" sizes="16x16" type="image/png">
14-
<link href="/site.webmanifest?v=4" rel="manifest">
15-
<link color="#000000" href="/safari-pinned-tab.svg?v=4" rel="mask-icon">
16-
<link href="/favicon.ico?v=4" rel="shortcut icon">
12+
<%= yield :head %>
13+
<%= tag.link rel: "manifest", href: pwa_manifest_path(format: :json) %>
14+
<link href="/apple-touch-icon.png" rel="apple-touch-icon" sizes="180x180">
15+
<link href="/favicon-32x32.png" rel="icon" sizes="32x32" type="image/png">
16+
<link href="/favicon-16x16.png" rel="icon" sizes="16x16" type="image/png">
17+
<link color="#000000" href="/safari-pinned-tab.svg" rel="mask-icon">
18+
<link href="/favicon.ico" rel="shortcut icon">
1719
<%= stylesheet_link_tag "tailwind", "hljs", "fonts", "data-turbo-track": "reload" %>
1820
<%= javascript_importmap_tags %>
1921
</head>

app/views/pwa/manifest.json.erb

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"id": "visualizer.coffee",
3+
"name": "Visualizer",
4+
"short_name": "Visualizer",
5+
"icons": [
6+
{
7+
"src": "/android-chrome-512x512.png",
8+
"type": "image/png",
9+
"sizes": "512x512"
10+
}
11+
],
12+
"start_url": "/shots",
13+
"display": "standalone",
14+
"scope": "/",
15+
"description": "Visualizer seamlessly integrates with Decent espresso machines, Smart Espresso Profiler, Pressensor, and Beanconqueror. Experience a unified platform that caters to diverse coffee setups and preferences.",
16+
"theme_color": "#ffffff",
17+
"background_color": "#ffffff",
18+
"orientation": "portrait",
19+
"author": "Miha Rekar",
20+
"developer": {
21+
"name": "Miha Rekar",
22+
"url": "https://mr.si/"
23+
},
24+
"screenshots": [
25+
{
26+
"src": "/screenshot_narrow.jpeg",
27+
"type": "image/jpeg",
28+
"sizes": "721x1500",
29+
"form_factor": "narrow"
30+
},
31+
{
32+
"src": "/screenshot_wide.jpeg",
33+
"type": "image/jpeg",
34+
"sizes": "1500x1549",
35+
"form_factor": "wide"
36+
}
37+
]
38+
}

app/views/pwa/service-worker.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
// })

config/routes.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@
102102

103103
post :airtable, to: "airtable#notification"
104104

105+
get "manifest" => "rails/pwa#manifest", as: :pwa_manifest
106+
get "service-worker" => "rails/pwa#service_worker", as: :pwa_service_worker
107+
105108
match "/404", to: "errors#not_found", via: :all
106109
match "/500", to: "errors#internal_server_error", via: :all
107110
get "/up" => "rails/health#show", :as => :rails_health_check

public/screenshot_narrow.jpeg

166 KB
Loading

public/screenshot_wide.jpeg

436 KB
Loading

public/site.webmanifest

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)