supabase_realtime_push 0.1.0
supabase_realtime_push: ^0.1.0 copied to clipboard
Push notifications on Android without Firebase: a native service holds one Supabase Realtime connection and shows the notifications your database lists.
Changelog #
0.1.0 - 2026-12-01 #
- Lock screen privacy: a snapshot notification with
"lockScreen": "hidden"stays off a secure lock screen;"redacted"shows only itspublicTitlethere ("New message") when the user hides sensitive content, and during screen sharing on Android 15+. Any other value counts as"hidden". A failed reply reposts it just as private. The inbox sets neither. lastError(): the service's latest failure (a snapshot that failed, a connection refused before it joined, the foreground refused) and when it happened, ornullonce a snapshot works. It tells an app why nothing arrives whilestatus()saysrunning, withoutadb logcat.- The service reconnects as soon as the network comes back or changes (Wi-Fi
to mobile data), instead of waiting up to 30 s for the next retry. The
plugin now declares
ACCESS_NETWORK_STATE. setFocus(id): while the app is on screen, the notification the user is looking at (the open chat, for instance) leaves the shade and does not ring; it comes back quietly if still unread once they leave.- The periodic check reads the snapshot with the screen on too, so a broadcast Realtime dropped while the socket stayed up no longer leaves the shade stale.
- The large icon cache holds a full default snapshot (20 icons at the largest screen density). With more icons than it held, every snapshot downloaded them all again, and some were posted without their picture.
- A notification posted without its large icon (the download failed or ran out of time) gets it with a later snapshot, quietly. A URL that failed is tried again after 10 minutes instead of on every snapshot.
realtime_push.sql: deleting a device row (unregister, the user deleted) signals that device, so the phone clears its notifications and stops at once instead of at its next snapshot read. Run the script again to get it.- A failed reply keeps the launcher badge number on the "Not sent" repost.
- A channel removed from
start(channels: ...)is deleted from the app's notification settings; listing it again brings back the user's settings. - The Reply action and the "Not sent" header come in Portuguese, Spanish, French, German and Italian too. An app still overrides them, or adds another language, with the same string names in its own resources.
- The default channel name and "connected" notification follow the phone's
language, in the same languages as Reply:
start'schannelName,connectedTitleandconnectedTextnow default to null, which means the plugin's string resources. A string passed tostartstill wins. A config saved by an older version keeps its English names until the app callsstartagain. - README: a trigger on a messages table that calls
realtime_push_send, checked by the SQL tests. - After Android killed the app in the background, opening it again from the
launcher no longer returns the old tap from
launchTap(), so the app does not navigate to that notification a second time. - The reconnect backoff grows even when each attempt joins: a server that accepted the join and dropped the socket soon after got a reconnect, a join and a snapshot about every second while the screen was on.
- After three refusals in a row (
socket failed HTTP 429, the Realtime connection limit, orjoin refused, public channels turned off) the service waits 5 minutes before reconnecting instead of up to 30 s, and the periodic check reads the snapshot meanwhile. A fleet above the limit no longer keeps the server full with retries in waves. The screen turning on or a network change still reconnects at once. - A snapshot cut short when Android stops the service no longer rings again for what it had already posted.
- A notification pushed out of the snapshot by newer ones that comes back at the same revision no longer rings again, nor returns after the user swiped it away.
- A late dismissal of an older revision (the old tap intent after Android killed the app, or a swipe that lands after a newer revision was posted) no longer removes the newer notification from the shade.
- A tap that arrives while nothing listens to
taps(the app subscribes after a sign-in screen, or the listening widget was disposed) is no longer lost: the nextlaunchTap()returns it. - A snapshot entry's optional
"time"(milliseconds since the epoch) shows when the notification arrived, next to its title. The defaultrealtime_push_snapshot_forsends each row'screated_at; running the script again keeps an existing one, so an install that never replaced it gets the time by dropping it first:drop function public.realtime_push_snapshot_for(uuid);, then the script. - A snapshot still in flight when the user signed out, and in as someone
else, is ignored: it could mark the new pair
rejectedor show the previous account's notifications. realtime_push_sendtakes a null body, data or silent as its default instead of raising, so a trigger passing a null column no longer rolls back the write it runs in. Run the script again to get it.- New
PushStatus.unregistered: this install has no device pair (never started, restored from a backup, orstop(forgetDevice: true)).stoppednow means only "turned off bystop()", so an app that restarts the service on launch no longer undoes a user's off switch. AswitchoverPushStatusneeds the new case. startwith anhttp://URL whose host Android blocks cleartext traffic to (the default for apps targeting Android 9+) throwsbad_argumentswith how to allow it, instead of starting a service that never connects.areNotificationsEnabled()tells whether the user turned off the app's notifications or its messages channel, without prompting, andopenNotificationSettings()opens the app's notification settings.- Limits on the snapshot (contract §3): the device reads at most 1 MB of it,
keeps the first 50 notifications, and drops one whose
datais over 4 KB. A snapshot of hundreds of entries held the shade for minutes, so a swipe meanwhile made Android kill the app; a largedatamade every later snapshot ring again for everything. One notification that fails to post no longer stops the others from being remembered. The README's "Your own data" example now haslimit 20. - "Mark as read" on the notification: a snapshot entry with
"markRead": truegets the action, which removes it at once, like a swipe, and calls the newrealtime_push_read, which hands the id to yourrealtime_push_read_for. The default reads the inbox rows of that key, so it leaves every device, and the inbox snapshot offers the action. Run the script again for the new functions; the inbox snapshot offers it oncerealtime_push_snapshot_foris dropped and recreated, as for"time". - A failed snapshot, reply or mark as read logs PostgREST's error code next
to the HTTP status (
snapshot failed: HTTP 404 (42P01)), never its message; the README's Troubleshooting table says what each code means. The device's calls sendContent-Profile: public, so they work whenpublicis not the first schema the Data API exposes. - Security: any app with notification access could rewrite the extras of the Reply action's intent, which must be mutable, and make this app post a notification with any title and body under its name and icon, or send the reply to another conversation. The intent's extras are now sealed with an HMAC keyed by a per-install secret, and a reply whose extras were changed is ignored. Anyone using the Reply action on 0.0.1 is affected and should update.
- The example app registers and starts again on launch when the status is
unregisteredorrejected, as the README asks, marks a tapped notification read, and has a "Send test notification" button. realtime_push_mark_all_read()reads every unread inbox row of the signed-in user in one call, for a "Mark all as read" button; one signal clears every device. Run the script again to get it.realtime_push_send_test(p_title, p_body)lets a signed-in user send themselves a test notification, under the keyrealtime_push:test; a new one replaces the last, and one within 10 s of the last does nothing and returns null. Run the script again to get it.- README: a
pg_cronjob that deletes devices unseen for 90 days, which nothing else cleans up for users who never register again. - Security: a user keeps at most 10 devices.
realtime_push_registerdeletes the caller's device seen least recently beyond that, and signals it, so a script can no longer register thousands of pairs that every notification to that user fans out to. Run the script again to get it. - Security: a device ends with the session it was registered in.
realtime_push_registerstores the JWT'ssession_id, and when Supabase Auth deletes that session (a sign-out with scopeglobalorothers, a password change, a revoked session) the device is deleted and signalled, so a lost phone stops even if its app never runs again. A session that already ended cannot register a device. Devices registered before have no session and are left alone. Run the script again to get it. - Security: a
largeIconwhose host is a private, loopback or link-local IP address is ignored, like a non-https one, so a snapshot cannot make the phone send requests inside the network it is on. The README now says to buildlargeIcononly from storage you control, never from a URL a user typed, which lets its owner see when and from where each recipient got the notification. - Security:
startrefuses a secret key (sb_secret_…) or aservice_roleJWT aspublishableKey, with anArgumentError(bad_argumentson the Android side). Such a key bypasses RLS, and it was shipped in the APK, backed up with the app's settings and sent in the WebSocket URL. - Security:
starttakes anhttp://URL only for local development (localhost,127.0.0.1,::1,10.0.2.2). Over cleartext anyone on the network read the device secret, every notification and the topic. Usehttps://, or the new, insecureallowCleartext: true. A self-hosted server on the LAN reached overhttpnow fails until one of the two. - Without the battery exemption, when Android refuses the foreground (the periodic check or a restart after the app was killed), the service now stays started until its snapshot read ends. It stopped at once, and Android 14+ could freeze the read halfway until the next check, minutes later.
- A snapshot's optional
moreis the number of notifications it left out: the device shows one quiet "+15 more" (translated like Reply) that opens the app, and removes it at 0. The default inbox sets it to the unread keys past the 20 it lists. Run the script again to get it, afterdrop function public.realtime_push_snapshot_for(uuid);if you never replaced the default: the script keeps an existing one, as for"time". - A channel in
start(channels: ...)can be quieter than the default:PushChannel('Offers', importance: PushImportance.low)shows without a sound,PushImportance.mediumrings without popping up. A plain name still works and stays high. Android keeps a channel's importance once created, so changing it later needs a new channel id.
0.0.1 - 2026-11-28 #
- Project scaffold and the Dart ↔ Android ↔ database contract.
- CI scans every PR for leaked secrets (gitleaks) and grades the repository with OpenSSF Scorecard.
- Dart API:
device,start,stop,status, battery exemption, notification permission,launchTapand thetapsstream. - README from setup to the first notification, and an example app that signs in, registers the device and starts the service.
supabase/realtime_push.sql: device registration, the snapshot, the "changed" signal and a ready-made inbox, tested on Postgres 17.- Android service that keeps the Realtime connection and shows the snapshot as notifications.
openConnectedNotificationSettings()opens the settings of the "connected" notification alone, so the user can hide it while the service keeps running.- Needs Flutter 3.44 or later: the Android build relies on Flutter applying the Kotlin plugin to apps without AGP 9's built-in Kotlin.
- Reply from the notification: a snapshot entry with
"reply": truegets a Reply action, the text goes to the newrealtime_push_reply, which hands it to yourrealtime_push_reply_for, and a reply that fails says "Not sent" on the notification and keeps the text. - Notification channels and pictures:
start(channels: {...})declares more channels, a snapshot entry picks one with"channel", and"largeIcon"shows an https picture, such as the sender's avatar, beside the text. start(foregroundService: false)never shows the "connected" notification: without the battery exemption the connection is held while the app is open, and with it closed a periodic check reads the snapshot. That check now also runs after Android kills the service, so notifications keep arriving, late, until the app opens again. The README and the example ask for the exemption when notifications are turned on.
