Skip to content

Add a Parcel widget for deliveries on their way - #27

Open
masonjmiller wants to merge 1 commit into
kemalandic:mainfrom
masonjmiller:parcel-widget
Open

masonjmiller wants to merge 1 commit into
kemalandic:mainfrom
masonjmiller:parcel-widget

Conversation

@masonjmiller

Copy link
Copy Markdown

A native Parcel widget (Info): the deliveries on their way, from Parcel, the package tracker for Apple platforms. Like the Cameras widget (#22), I built it with Claude.

The Parcel widget on a XENEON EDGE, in a theme with a yellow accent, no gap and square corners: Amazon Basics Cardboard Moving Boxes, in transit with UPS, departed a Jacksonville facility at 3:52 AM and due Tomorrow; and Q8 Emblem, in transit with Pitney Bowes, shipped from Lichfield yesterday

What it does

  • Every delivery Parcel tracks, from any of its hundreds of carriers, in the order that matters:
    • out for delivery and ready for pickup first;
    • then failed attempts and exceptions;
    • then the rest, soonest due first.
  • Each row has:
    • a status badge;
    • the name it was given in Parcel;
    • its status and carrier;
    • the carrier's latest scan, with its time;
    • when it's due: "Today", "Tomorrow", the weekday or the date, with the delivery window when the carrier gives one. A due day that has passed turns yellow.
  • One delivery gets the whole widget, with its last four scans.
  • Show: Active (what's on its way) or Recent (Parcel's recent list, which includes deliveries that have just arrived).
  • Tap opens Parcel, or web.parcelapp.net on a Mac without the app.
  • It follows the theme:
    • fonts and sizes, text colors and corner radius;
    • rows drawn like widget cards and inset by the gap;
    • the accent for deliveries in transit, until another color is picked under Widget Colors.

Setup

Parcel's API is part of Parcel Premium. The key comes from web.parcelapp.net and goes into the widget's settings, which have a Get a Key button. It's kept in the Keychain, not the layout, and shared by every Parcel widget, since it belongs to the account. Saving asks Parcel straight away, so the line under the field says whether the key works.

How

  • ParcelService (ServiceKey.parcel):
    • asks for each list a widget on screen shows;
    • every five minutes for one list, every ten for each when both are showing. Parcel allows 20 requests an hour per key and answers from what its servers already have, so this stays at twelve.
    • waits as long as Retry-After says after a 429 (15 minutes without one);
    • asks nothing while the displays sleep;
    • keeps the last list when a refresh fails, with the reason and its age underneath.
  • ParcelAPI reads replies forgivingly, because the API is unversioned and its values come from carriers:
    • missing, null or wrongly typed fields are absent;
    • a malformed event or delivery is dropped rather than costing the rest;
    • the carrier list is read in both its old shape (code to name) and the current one (code to {"name": …});
    • a reply without a list is an error rather than "nothing on the way".
  • ParcelSchedule handles dates:
    • Expected dates come as Unix timestamps when the carrier gave a full date, time and zone. Otherwise they're local strings, where midnight means the whole day.
    • Event dates are the carrier's own text. It reads the forms seen in Parcel replies: ISO, with or without a zone; "October 7, 2026 2:41 PM EDT"; weekday forms; dotted and slashed dates, where day and month are settled by which reading is nearer today.
    • Anything else is left unread, and the widget leaves out the time rather than guess.
  • ConfigFieldType.parcelKey with ParcelKeyEditor.
  • No new permissions. It reuses the CI code's CITransport, KeychainSecretStore (service ai.pakslab.edgecontrol.parcel) and InMemorySecretStore.
  • WidgetLaunch.excluded gains parcel, since a tap already opens Parcel.

Why not a plugin

I tried that first. Plugin views load from file://, and Parcel's API answers the CORS preflight (the custom api-key header needs one) with a 401 and no Access-Control-Allow-Origin. A web view can't reach it, so it has to be native.

Testing

  • ./Scripts/ci-local.sh all passes:

    • the format check is clean;
    • no compiler warnings;
    • 418 Swift Testing tests in 40 suites.
  • 31 of the tests are new, in three suites:

    • reading replies, against a fixture shaped like Parcel's with made-up deliveries;
    • reading and phrasing dates, pinned to New York;
    • the service: pacing, watchers, a refused key, Retry-After, keeping a stale list, and adding and removing the key.
  • On a XENEON EDGE with a real Parcel Premium account (macOS 27.2):

    • the widget listed two deliveries, from UPS and Pitney Bowes, with Parcel's carrier names;
    • the scan times read as "3:52 AM" and "Yesterday", and the expected date as "Tomorrow";
    • it followed a theme with a custom accent, no gap and square corners (the screenshot).

    I haven't yet seen the one-delivery view, the Recent list, or a real 429 on real data; the tests cover them.

Overlaps with #22

  • defaultsToAccentColor and Theme.widgetPrimaryOrAccent, and the Theme page using them, are copied unchanged from Add a Cameras widget for go2rtc and HLS cameras #22, so whichever lands second merges cleanly. The exception is WidgetLaunch.excluded, where each adds its own widget.
  • Like the other widget PRs, this touches ConfigFieldType, ServiceKey, AppModel, WidgetRegistry, the README's widget count and the guide.

Whichever lands later, I'll rebase.

🤖 Generated with Claude Code

Parcel tracks deliveries from hundreds of carriers, and Parcel Premium comes
with an API key that reads the same deliveries the app shows. The widget
lists them with what each needs: out for delivery and ready for pickup
first, then what needs attention, then the rest by when they're due, each
with its carrier's latest scan and "Today", "Tomorrow" or the day it's due,
with the delivery window when the carrier gives one. A single delivery gets
the whole widget, with its recent scans. A tap opens Parcel.

The key is pasted into the widget's settings and kept in the Keychain,
shared by every Parcel widget since it belongs to the account. Saving asks
Parcel straight away, so the settings say whether the key works.

ParcelService asks for each list a widget shows, active or recent, every
five minutes, or each every ten when both are on screen. Parcel allows 20
requests an hour per key and answers from what its servers already have, so
this stays at twelve. It honours Retry-After on a 429, asks nothing while
the displays sleep, and keeps the last list when a refresh fails, with the
reason and its age underneath.

Parcel passes on what carriers write, so reading is forgiving: null or
missing fields are absent, a malformed event or delivery is dropped rather
than costing the rest, and a reply without a list is an error rather than
"nothing on the way". Expected dates come as timestamps when the carrier
gave a zone and otherwise as local strings, where midnight means the day.
Event dates are carrier text; ParcelSchedule reads the forms seen in Parcel
replies, and the widget leaves a time out rather than guess at one.

It follows the theme throughout: its fonts and sizes, text colors, corner
radius and gap, rows drawn like widget cards, and the accent for deliveries
in transit until another color is picked on the Theme page. That last part
uses the same defaultsToAccentColor and widgetPrimaryOrAccent as the Cameras
widget (kemalandic#22), identical so that whichever lands second merges cleanly. A
tap opens Parcel, so the widget is excluded from Opens on Tap.

It reuses the CI code's transport and Keychain store. The tests use a reply
shaped like Parcel's, with made-up deliveries.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant