Enable installing app as pwa
This commit is contained in:
BIN
app/assets/images/icon-192.png
Normal file
BIN
app/assets/images/icon-192.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.7 KiB |
BIN
app/assets/images/icon-512.png
Normal file
BIN
app/assets/images/icon-512.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 13 KiB |
7
app/controllers/service_worker_controller.rb
Normal file
7
app/controllers/service_worker_controller.rb
Normal file
@@ -0,0 +1,7 @@
|
||||
class ServiceWorkerController < ApplicationController
|
||||
protect_from_forgery except: :service_worker
|
||||
def service_worker
|
||||
end
|
||||
def manifest
|
||||
end
|
||||
end
|
||||
@@ -1,2 +1,3 @@
|
||||
// Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails
|
||||
import "controllers"
|
||||
import "custom/companion"
|
||||
|
||||
11
app/javascript/custom/companion.js
Normal file
11
app/javascript/custom/companion.js
Normal file
@@ -0,0 +1,11 @@
|
||||
if (navigator.serviceWorker) {
|
||||
navigator.serviceWorker
|
||||
.register("/service-worker.js", { scope: "/" })
|
||||
.then(() => navigator.serviceWorker.ready)
|
||||
.then((registration) => {
|
||||
if ("SyncManager" in window) {
|
||||
registration.sync.register("sync-forms");
|
||||
}
|
||||
})
|
||||
.then(() => console.log("[Companion]", "Service worker registered!"));
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
<html lang="<%= I18n.locale %>">
|
||||
<head>
|
||||
<title><%= content_for?(:title) ? yield(:title) : "Terminator" %></title>
|
||||
<link rel="manifest" crossorigin="use-credentials" href="/manifest.json" />
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
<%= csrf_meta_tags %>
|
||||
<%= csp_meta_tag %>
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>Terminator</title>
|
||||
<link rel="manifest" crossorigin="use-credentials" href="/manifest.json" />
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
<%= csrf_meta_tags %>
|
||||
<%= csp_meta_tag %>
|
||||
|
||||
21
app/views/service_worker/manifest.json.erb
Normal file
21
app/views/service_worker/manifest.json.erb
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"short_name": "Zdravo Stopalo",
|
||||
"name": "Zdravo Stopalo",
|
||||
"icons": [
|
||||
{
|
||||
"src": "<%= image_path('icon-192.png')%>",
|
||||
"type": "image/png",
|
||||
"sizes": "192x192"
|
||||
},
|
||||
{
|
||||
"src": "<%= image_path('icon-512.png')%>",
|
||||
"type": "image/png",
|
||||
"sizes": "512x512"
|
||||
}
|
||||
],
|
||||
"start_url": "<%= root_path %>",
|
||||
"background_color": "#FFFFFF",
|
||||
"display": "standalone",
|
||||
"scope": "<%= root_path %>",
|
||||
"theme_color": "#8e2731"
|
||||
}
|
||||
14
app/views/service_worker/service_worker.js
Normal file
14
app/views/service_worker/service_worker.js
Normal file
@@ -0,0 +1,14 @@
|
||||
function onInstall(event) {
|
||||
console.log("[Serviceworker]", "Installing!", event);
|
||||
}
|
||||
|
||||
function onActivate(event) {
|
||||
console.log("[Serviceworker]", "Activating!", event);
|
||||
}
|
||||
|
||||
function onFetch(event) {
|
||||
console.log("[Serviceworker]", "Fetching!", event);
|
||||
}
|
||||
self.addEventListener("install", onInstall);
|
||||
self.addEventListener("activate", onActivate);
|
||||
self.addEventListener("fetch", onFetch);
|
||||
@@ -4,3 +4,4 @@ pin "@hotwired/stimulus", to: "stimulus.min.js"
|
||||
pin "@hotwired/stimulus-loading", to: "stimulus-loading.js"
|
||||
pin "application"
|
||||
pin_all_from "app/javascript/controllers", under: "controllers"
|
||||
pin_all_from "app/javascript/custom", under: "custom"
|
||||
|
||||
@@ -12,6 +12,9 @@ Rails.application.routes.draw do
|
||||
# Can be used by load balancers and uptime monitors to verify that the app is live.
|
||||
get "up" => "rails/health#show", as: :rails_health_check
|
||||
|
||||
# config/routes.rb
|
||||
get "/service-worker.js" => "service_worker#service_worker"
|
||||
get "/manifest.json" => "service_worker#manifest"
|
||||
# Defines the root path route ("/")
|
||||
# root "posts#index"
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user