mirror of
https://github.com/rickbarrette/simple-aircraft-manager-rails.git
synced 2026-11-17 15:50:36 -05:00
Installed app: offline squawks and pre-flight pages, push notifications, shortcuts
Offline
- Flights and squawks saved offline are tagged with their user and only sent
while that user is signed in; storage is made persistent; Background Sync
sends them with the app closed (Chromium); unsent count on the app badge
- Report Squawk works offline (photos included, one-time key like flights)
- The Fleet page and, for each of your aircraft, the Overview, W&B, Log
Flight and Report Squawk pages and photo are saved ahead of time, so the
app opens and works without signal; copies say when they were saved
- Sign-out clears saved forms, pages and photos (asks first if items wait)
- Offline page rendered by Rails (localized, follows the theme, no inline
script); service worker version follows the build
Install and notify
- Web Push (web-push gem, VAPID keys from env or storage/vapid_keys.json):
grounding squawks, newly overdue items (daily, once each), signing
requests; per-device on/off and test in Profile -> This device; only
browser push service endpoints accepted
- Manifest shortcuts (Log Flight, Report Squawk via /go/...), lang and
localized description; install help on Profile; reload notice after a
release
Also
- Dockerfile: libssl-dev in the build stage (openssl gem); lockfile checksums
- Leftover English and %{_} interpolation names from the localization pass
- Guide and README updated
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
89ed0a76f9
commit
8d5f57da81
54 files changed
+1217
-203
No files matched your search
@@ -2,8 +2,9 @@ import { Controller } from "@hotwired/stimulus"
|
||||
import { t } from "i18n"
|
||||
import { queue } from "controllers/offline_queue"
|
||||
|
||||
// On every page: sends flights logged offline once there's a connection, and
|
||||
// says what happened. A rejected flight stays until it's discarded.
|
||||
// On every page: sends the flights and squawks this user saved offline once
|
||||
// there's a connection, says what happened, and shows the count on the app
|
||||
// icon. A rejected item stays until it's discarded.
|
||||
export default class extends Controller {
|
||||
static targets = [ "banner" ]
|
||||
|
||||
@@ -21,21 +22,21 @@ export default class extends Controller {
|
||||
|
||||
async sync() {
|
||||
let items
|
||||
try { items = await queue.all() } catch (_) { return }
|
||||
if (!items.length) return this.show("")
|
||||
try { items = await queue.mine() } catch (_) { return }
|
||||
if (!items.length) { this.badge(0); return this.show("") }
|
||||
if (!navigator.onLine || this.running) return this.status(items)
|
||||
this.running = true
|
||||
let sent = 0
|
||||
const sent = []
|
||||
try {
|
||||
for (const item of items.filter((i) => !i.error)) {
|
||||
const result = await this.send(item)
|
||||
if (result === "sent") { await queue.remove(item.id); sent++ }
|
||||
if (result === "sent") { await queue.remove(item.id); sent.push(item) }
|
||||
else if (result === "signin") { this.show(t("offline.sign_in")); return }
|
||||
else if (result === "offline") break
|
||||
else { item.error = result; await queue.put(item) }
|
||||
}
|
||||
} finally { this.running = false }
|
||||
this.status(await queue.all(), sent)
|
||||
this.status(await queue.mine(), sent)
|
||||
}
|
||||
|
||||
async send(item) {
|
||||
@@ -56,13 +57,22 @@ export default class extends Controller {
|
||||
return message || t("offline.not_accepted", { status: response.status })
|
||||
}
|
||||
|
||||
status(items, sent = 0) {
|
||||
status(items, sent = []) {
|
||||
const failed = items.filter((i) => i.error)
|
||||
const waiting = items.length - failed.length
|
||||
const waiting = items.filter((i) => !i.error)
|
||||
const parts = []
|
||||
if (sent) parts.push(t("offline.sent", { count: sent }))
|
||||
if (waiting) parts.push(t("offline.waiting", { count: waiting }))
|
||||
for (const kind of [ "flight", "squawk" ]) {
|
||||
const count = (list) => list.filter((i) => (i.kind || "flight") === kind).length
|
||||
if (count(sent)) parts.push(t(`offline.${kind}.sent`, { count: count(sent) }))
|
||||
if (count(waiting)) parts.push(t(`offline.${kind}.waiting`, { count: count(waiting) }))
|
||||
}
|
||||
this.show(parts.join(" "), failed)
|
||||
this.badge(items.length)
|
||||
}
|
||||
|
||||
// The number of unsent items on the installed app's icon.
|
||||
badge(count) {
|
||||
try { count ? navigator.setAppBadge?.(count) : navigator.clearAppBadge?.() } catch (_) { /* not supported */ }
|
||||
}
|
||||
|
||||
show(text, failed = []) {
|
||||
@@ -72,7 +82,7 @@ export default class extends Controller {
|
||||
for (const item of failed) {
|
||||
const date = (item.fields.find(([ n ]) => n === "flight_log[date]") || [])[1] || ""
|
||||
const row = document.createElement("p")
|
||||
row.textContent = `${item.tail} flight ${date} logged offline wasn't accepted: ${item.error} `
|
||||
row.textContent = `${t(`offline.${item.kind || "flight"}.rejected`, { tail: item.tail, date, error: item.error })} `
|
||||
const discard = Object.assign(document.createElement("button"), { type: "button", textContent: t("offline.discard"), className: "btn-secondary btn-sm ml-1" })
|
||||
discard.addEventListener("click", async () => { await queue.remove(item.id); this.sync() })
|
||||
row.append(discard)
|
||||
|
||||
Reference in new issue
Block a user