Merge branch '10-omoguciti-pwa' into 'master'

Enable installing app as PWA

Closes #10

See merge request kbr4/zsterminator!8
This commit was merged in pull request #22.
This commit is contained in:
2025-06-02 15:11:01 +00:00
11 changed files with 60 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

View File

@@ -0,0 +1,7 @@
class ServiceWorkerController < ApplicationController
protect_from_forgery except: :service_worker
def service_worker
end
def manifest
end
end

View File

@@ -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"

View 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!"));
}

View File

@@ -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 %>

View File

@@ -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 %>

View 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"
}

View 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);

View File

@@ -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"

View File

@@ -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