You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm not a JS guy so not sure how this can be packaged better - or if it needs to, but I'm using importmaps which is kind of the new default for Rails, so should somehow work with this (and maybe have an option in the installer OR detect whether yarn/npm is used).
Also had to change the imports in the 2 JS files from from "noticed-web_push/web_push" to `from "./web_push/web_push" to resolve to my local copies.
4. Active record encryption
Getting the following error when trying to save the web push subscription:
ActiveRecord::Encryption::Errors::Configuration (Missing Active Record encryption credential: active_record_encryption.deterministic_key):
Makes sense to save this encrypted but if it is a requirement it could maybe be checked in the install script - or it could be made optional (though compromising on security is not good).
Noticed does require rails but only 5.2+ I think, so technically this gem might have to require a more recent rails version itself.
5. ApplicationController
It is weird as it seems you have Noticed::WebPush::ApplicationController but it seems like the controllers are inheriting from my apps ApplicationController as I do have a before_action :require_logged_in_user! which I selectively skip where applicable and it catches for all the gem mounted controller actions.
6. Javascript, again
I actually had to also copy the service_worker.js (copied from the gem) content into my sevice_worker.js file as, at least with import maps, I can't just have an "import" statement.
Again I like the plug & play approach but some of that JS might want to be customized as well - perhaps web_push.start is not the most elegant API/DSL for this.
7. save vs setup subscription
I had to change the Notification.permission == "granted" case to check for existing service worker registration.
As I hit some snags setting everything up (issues with my service worker especially) it happened that Notification access was granted but the service worker was never set up - and saveSubscription would "hang" forever on const registration = await navigator.serviceWorker.ready
8. I would like to customize the "Enable notifications" button
It relies on it's ID so I can probably just add a button with that ID anywhere I like though.
What I really liked though was:
no forcing local certs - I'd rather use a tunnel like ngrok
vapid generator task that let me copy&paste the keys
That was a lot and I might have forgotten some!
But I got it working 🚀 Now I still want to clean things up a little bit. It's quite tricky as there are so many moving pieces especially with the JS and all the routes - I also don't know of any clean ways to pass configuration such as routes from Ruby to JS (without dragging them through the HTML).
The text was updated successfully, but these errors were encountered:
Thanks so much for your input. I'll be working through this as I think about v2 in light of the stuff that DHH is proposing for Rails 8.
I'm currently thinking about splitting this into two a PWA focused engine that will be conceptually consistent with what the Rails 8 changes will be and a noticed-web_push that builds on that for noticed. I see the first as being a stopgap and will go away once you are on Rails 8.
Hi Jonathan,
Thanks for tackling this web push topic it really is quite a beast, hence DHH thinks it's worth going after!
Just wanted to let you know a couple of gotchas I ran into when installing the gem.
1. DB migration
My users table has UUIDs as primary keys and I had to change that in the migration - common issue and actually happened on
noticed
itself as well.2. installer
It failed but I will break out the real issues separately.
So I had to do the following manually:
has_many
to usersroutes.rb
3. yarn
As I'm not using yarn to pull in your scripts, I copied the files from https://github.com/jbennett/noticed-web_push/tree/main/app/assets/javascripts/noticed/web_push to my own
app/javascript
folder.I'm not a JS guy so not sure how this can be packaged better - or if it needs to, but I'm using importmaps which is kind of the new default for Rails, so should somehow work with this (and maybe have an option in the installer OR detect whether yarn/npm is used).
Also had to change the imports in the 2 JS files from
from "noticed-web_push/web_push"
to `from "./web_push/web_push" to resolve to my local copies.4. Active record encryption
Getting the following error when trying to save the web push subscription:
Makes sense to save this encrypted but if it is a requirement it could maybe be checked in the install script - or it could be made optional (though compromising on security is not good).
Noticed does require rails but only 5.2+ I think, so technically this gem might have to require a more recent rails version itself.
5. ApplicationController
It is weird as it seems you have
Noticed::WebPush::ApplicationController
but it seems like the controllers are inheriting from my appsApplicationController
as I do have abefore_action :require_logged_in_user!
which I selectively skip where applicable and it catches for all the gem mounted controller actions.6. Javascript, again
I actually had to also copy the
service_worker.js
(copied from the gem) content into mysevice_worker.js
file as, at least with import maps, I can't just have an "import" statement.Again I like the plug & play approach but some of that JS might want to be customized as well - perhaps
web_push.start
is not the most elegant API/DSL for this.7. save vs setup subscription
I had to change the
Notification.permission == "granted"
case to check for existing service worker registration.As I hit some snags setting everything up (issues with my service worker especially) it happened that Notification access was granted but the service worker was never set up - and
saveSubscription
would "hang" forever onconst registration = await navigator.serviceWorker.ready
8. I would like to customize the "Enable notifications" button
It relies on it's ID so I can probably just add a button with that ID anywhere I like though.
What I really liked though was:
That was a lot and I might have forgotten some!
But I got it working 🚀 Now I still want to clean things up a little bit. It's quite tricky as there are so many moving pieces especially with the JS and all the routes - I also don't know of any clean ways to pass configuration such as routes from Ruby to JS (without dragging them through the HTML).
The text was updated successfully, but these errors were encountered: