mirror of
https://github.com/HeyPuter/puter.git
synced 2026-11-05 21:46:51 +00:00
fix(notifications): a browser removed in Puter stays off, and status() checks with Puter on websites (#4458)
This commit is contained in:
1 parent
f8dc10268e
commit
ef99893fc8
12 files changed
+425
-67
No files matched your search
@@ -10,7 +10,7 @@ On a website, the browser asks on your own origin, and pushes arrive through you
|
||||
|
||||
The call resolves as soon as the browser has answered and Puter has its subscription. It doesn't wait for the confirmation. Pushes start once your page hands the confirmation back, usually within seconds. If the confirmation doesn't arrive within 30 seconds, the `onError` of [`onPush()`](/Notifications/onPush/) gets `push_verification_timeout`, or the console does without one, and the next page load tries again.
|
||||
|
||||
The choice sticks. Once enabled, [`onPush()`](/Notifications/onPush/) keeps the subscription current on later page loads without asking again. After [`disable()`](/Notifications/disable/), after the user turns your app off in Puter, or after [`puter.auth.signOut()`](/Auth/signOut/), page loads don't subscribe again until your page calls [`enable()`](/Notifications/enable/) again from a click.
|
||||
The choice sticks. Once enabled, [`onPush()`](/Notifications/onPush/) keeps the subscription current on later page loads without asking again. After [`disable()`](/Notifications/disable/), after the user turns your app off or removes this browser in Puter, or after [`puter.auth.signOut()`](/Auth/signOut/), page loads don't subscribe again until your page calls [`enable()`](/Notifications/enable/) again from a click.
|
||||
|
||||
If the user turned your app off in Puter's settings, the call rejects with `push_revoked`. To ask again, call [`requestPermission()`](/Notifications/requestPermission/) from a click, which opens Puter's permission prompt, and then call [`enable()`](/Notifications/enable/) again.
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ Handles the notifications your app sends with `channel: key` in [`notify()`](/No
|
||||
|
||||
A page with a handler tells Puter when it receives a notification, before your handler runs. When the page is visible and focused, nothing is pushed. When it's hidden or its window isn't focused, the page shows the notification itself, unless another tab of your site is focused. It shows the handler's result, or the notification's own title and text when no handler matches the notification's `channel`. Showing it needs the browser's notification permission, which [`enable()`](/Notifications/enable/) asks for. Otherwise, when no page answers within 5 seconds that it's visible and focused or that it shows the notification itself, Puter sends a push. [Push notifications for your app](/Notifications/push/#when-a-notification-is-pushed) has the full rule.
|
||||
|
||||
The user turns pushes on once with [`enable()`](/Notifications/enable/). After that, each page load's [`onPush()`](/Notifications/onPush/) call keeps this browser's subscription current without asking again. Different keys share that one permission. After [`disable()`](/Notifications/disable/), after the user turns your app off in Puter, or after [`puter.auth.signOut()`](/Auth/signOut/), page loads don't subscribe again until your page calls [`enable()`](/Notifications/enable/) from a click.
|
||||
The user turns pushes on once with [`enable()`](/Notifications/enable/). After that, each page load's [`onPush()`](/Notifications/onPush/) call keeps this browser's subscription current without asking again. Different keys share that one permission. After [`disable()`](/Notifications/disable/), after the user turns your app off or removes this browser in Puter, or after [`puter.auth.signOut()`](/Auth/signOut/), page loads don't subscribe again until your page calls [`enable()`](/Notifications/enable/) from a click.
|
||||
|
||||
## The service worker
|
||||
|
||||
@@ -50,7 +50,7 @@ A [sensitive](/Notifications/notify/#parameters) push carries no `channel`, so n
|
||||
|
||||
#### `options` (Object) (optional)
|
||||
- `serviceWorker` (String): path of the worker that imports `push-sw.js`. Default `/puter-sw.js`.
|
||||
- `onError` (Function): called when the handler throws in the page or runs past 5 seconds there (`push_handler_timeout`, and the notification's own title and text show instead), the live listener stops, keeping the subscription current fails, or the confirmation push after [`enable()`](/Notifications/enable/) doesn't arrive within 30 seconds (`push_verification_timeout`). Without it, errors go to the console. A server without a push service (`push_unavailable`) and an app the user turned off in Puter (`push_revoked`) are not reported here, since [`enable()`](/Notifications/enable/) rejects with them when called.
|
||||
- `onError` (Function): called when the handler throws in the page or runs past 5 seconds there (`push_handler_timeout`, and the notification's own title and text show instead), the live listener stops, keeping the subscription current fails, or the confirmation push after [`enable()`](/Notifications/enable/) doesn't arrive within 30 seconds (`push_verification_timeout`). Without it, errors go to the console. A server without a push service (`push_unavailable`) and an app the user turned off in Puter (`push_revoked`) are not reported here, since [`enable()`](/Notifications/enable/) rejects with them when called. A browser the user removed in Puter isn't reported either, since [`enable()`](/Notifications/enable/) turns pushes back on there.
|
||||
|
||||
## Handler limits
|
||||
|
||||
|
||||
@@ -118,7 +118,7 @@ document.getElementById('enable').addEventListener('click', async () => {
|
||||
|
||||
When nobody is signed in, [`enable()`](/Notifications/enable/) opens the Puter sign-in after the browser's prompt. Sign the user in first, from its own button, so the sign-in window isn't blocked as a popup.
|
||||
|
||||
To turn pushes off in this browser again, call [`disable()`](/Notifications/disable/). Notifications still reach your app live while it's open. Page loads don't turn pushes back on after [`disable()`](/Notifications/disable/), after the user turns your app off in Puter, or after [`puter.auth.signOut()`](/Auth/signOut/). Call [`enable()`](/Notifications/enable/) from a click to turn them on again. Signing out also removes this browser's registration for your app.
|
||||
To turn pushes off in this browser again, call [`disable()`](/Notifications/disable/). Notifications still reach your app live while it's open. Page loads don't turn pushes back on after [`disable()`](/Notifications/disable/), after the user turns your app off or removes this browser in Puter, or after [`puter.auth.signOut()`](/Auth/signOut/). Call [`enable()`](/Notifications/enable/) from a click to turn them on again. Signing out also removes this browser's registration for your app.
|
||||
|
||||
## Sending a notification
|
||||
|
||||
|
||||
@@ -8,6 +8,8 @@ platforms: [websites, apps]
|
||||
|
||||
Removes one of the user's devices, so it gets no more push notifications. Signing out of a session also removes the devices registered from it.
|
||||
|
||||
Removing a `'webpush'` device sticks. The website that subscribed that browser doesn't register it again on page loads. The site turns pushes off in that browser the next time a page with [`onPush()`](/Notifications/onPush/) loads or calls [`status()`](/Notifications/status/). Calling [`enable()`](/Notifications/enable/) on the site turns them back on.
|
||||
|
||||
## Syntax
|
||||
```js
|
||||
puter.notifications.removeDevice(uid)
|
||||
|
||||
@@ -4,9 +4,9 @@ description: Check whether push notifications from your app reach the browser th
|
||||
platforms: [websites, apps]
|
||||
---
|
||||
|
||||
Whether your app's push notifications reach the browser the user is in right now. It never prompts and never changes anything, so call it on page load to decide whether to show your own "Turn on notifications" button, which calls [`enable()`](/Notifications/enable/).
|
||||
Whether your app's push notifications reach the browser the user is in right now. It never prompts, so call it on page load to decide whether to show your own "Turn on notifications" button, which calls [`enable()`](/Notifications/enable/).
|
||||
|
||||
On a website, it's `'on'` when the user turned pushes on in this browser with [`enable()`](/Notifications/enable/), and this browser still holds the subscription. Pushes start once Puter confirms the browser, usually within seconds of [`enable()`](/Notifications/enable/) resolving. Inside the Puter desktop, it's `'on'` when pushes are on in this browser and your app holds the [`notifications:push`](/Notifications/requestPermission/) permission.
|
||||
On a website, it's `'on'` when the user turned pushes on in this browser with [`enable()`](/Notifications/enable/), and this browser still holds the subscription. It then checks that subscription with Puter, and it's `'off'` after the user removes this browser in Puter's settings or turns your app off there. Pushes start once Puter confirms the browser, usually within seconds of [`enable()`](/Notifications/enable/) resolving. Inside the Puter desktop, it's `'on'` when pushes are on in this browser and your app holds the [`notifications:push`](/Notifications/requestPermission/) permission.
|
||||
|
||||
## Syntax
|
||||
```js
|
||||
@@ -25,11 +25,11 @@ A `Promise` that resolves to one of these strings. It never rejects.
|
||||
| Value | Meaning |
|
||||
| --- | --- |
|
||||
| `'on'` | Pushes from your app reach this browser. |
|
||||
| `'off'` | They don't yet. Call [`enable()`](/Notifications/enable/) from a click to turn them on. |
|
||||
| `'off'` | They don't yet. Call [`enable()`](/Notifications/enable/) from a click to turn them on. After the user turned your app off in Puter, [`enable()`](/Notifications/enable/) rejects with `push_revoked`. |
|
||||
| `'blocked'` | The browser blocks notifications, for your site on a website or for Puter inside the desktop. The user unblocks them in the browser's site settings. |
|
||||
| `'unavailable'` | This browser or page can't receive pushes, such as a browser without Web Push, or the server has no push notification service. |
|
||||
|
||||
On a website, the call doesn't ask the server, so it answers `'off'` on a server without a push notification service, and [`enable()`](/Notifications/enable/) then rejects with `push_unavailable`. It also answers `'off'` when nobody is signed in.
|
||||
On a website, it answers `'off'` on a server without a push notification service, and [`enable()`](/Notifications/enable/) then rejects with `push_unavailable`. It also answers `'off'` when nobody is signed in. If the check with Puter fails, it answers `'on'` from this browser's subscription alone.
|
||||
|
||||
## Examples
|
||||
|
||||
|
||||
Reference in new issue
Block a user