Drive Tokens, File Previews, and a Cleaner List/Grid Toggle
Ship notes on token-based Drive calls, practical metadata (size, modified, MIME), and the new toggle that stops fighting your brain.
“Build small, ship quiet, iterate fast.”
— Rev. Brian Scott O’keefe
What shipped
- Token-based Google Drive calls (REST, no GTLR) with cleaner refresh logic.
- Metadata rows in list view: file size (human-readable), last modified (relative + absolute), MIME type (trimmed).
- List/Grid toggle that preserves mode across sessions and stops jarring reflow.
- Preview pipeline tuned for snappier thumbnails and graceful fallbacks.
If you missed the first installment, start with Dev Log #1 for context on tokens and layout goals: /blog/lifeos-scribraria-dev-log-1
.
Token-based Drive calls (quick, durable, boring)
- Access/refresh split: Access tokens power requests; refresh tokens are keyed in the system keychain. Expiration is tracked; refresh happens just-in-time, not constantly.
- URLSession + typed requests: Each Drive endpoint sits behind a tiny request type with robust error mapping (auth, quota, network).
- Backoff & retry: Transient 5xx errors back off with jitter; auth failures short-circuit to a guided re-auth path.
- Privacy guardrails: Scopes are minimal; logs strip tokens; request IDs help me trace without leaking details.
Why it matters: stable tokens mean previews and lists feel instantaneous instead of “sometimes-fast-sometimes-broken.”
File metadata that’s actually useful
- Size: Shown as KB/MB/GB with one decimal (e.g., 12.4 MB).
- Modified: Relative (“2h ago”), with tooltips/secondary text for the full timestamp.
- MIME: Trimmed to a friendly label (e.g., “PDF” instead of
application/pdf
).
- Secondary line pattern:
Owner • Size • Modified
. Responsive rules collapse gracefully on smaller widths.
Planned options: Toggle MIME on/off per user, and a compact “developer mode” to surface raw MIME + Drive IDs for debugging.
A calmer List/Grid toggle
- State that sticks: Your choice persists between launches (UserDefaults for now).
- Zero-jitter switch: The container reserves space, so toggling doesn’t cause big jumps.
- Grid polish: Square thumbs with consistent gutters; long names wrap to two lines and then truncate.
Previews that don’t lie
- Progressive load: Low-res thumb first, then swap in high-res when ready.
- Fallback chain: If a preview fails, we show a deterministic icon (by MIME family) and keep the metadata intact.
- No spinner storm: One spinner per cell if needed; batch prefetch avoids flicker in fast scrolls.
Known issues (and what I did about them)
- Occasional 401 after sleep: Added a wake-resume check that validates tokens before resuming queued requests.
- Over-eager reloads on tab switch: Debounced; navigation now respects cache freshness windows.
- Grid thumbnails on slow networks: Introduced a tiny placeholder palette so the grid doesn’t look empty while loading.
Next sprint (what I’m building immediately)
- Per-view sort & filter memory: Size/Modified/Name, ascending/descending, remembered per folder.
- Inline quick actions: Tap-hold for copy link, rename, and “open in Drive” without losing place.
- Preview extensions: Text, Markdown, and PDF inline readers with smooth paging.
- Diagnostics panel (developer mode): Surface request timing, cache hits, and Drive file IDs.
How you can help (CTA)
Which metadata matters most—size, modified, or MIME?
Tell me in a comment or DM. I’ll tune the default layout and the order of the secondary line based on your answer.
Changelog
2025-09-20
- Implemented token refresh guard & exponential backoff
- Added size/modified/MIME to list cells
- Persisted list/grid toggle; stabilized transitions
- Preview fallback logic + progressive thumbnails
Version / Tooling
- Languages/SDKs: Swift 6, SwiftUI, URLSession (REST), Keychain access
- Tooling: Xcode 16
- APIs: Google Sign-In (token exchange), Google Drive REST v3
- Platforms: iOS + macOS targets
- Data: Local caching for previews and metadata snapshots
— Rev. Brian Scott O’keefe
randomblink
“I build in public so I remember in private.”