fix(categories): import JSON from Android SAF and persist a single save - #956
fix(categories): import JSON from Android SAF and persist a single save#956TimeToBuildBob wants to merge 2 commits into
Conversation
Android file picks often report .json as octet-stream, so the MIME-only import check silently no-op'd. Import also left category_sets unsynced and save() raced two settings updates, which could write defaults back. ActivityWatch/aw-android#247
Greptile SummaryThe PR makes category imports compatible with Android SAF file metadata and consolidates category persistence into one awaited settings update.
Confidence Score: 5/5The PR appears safe to merge with no concrete changed-code defects identified. The import flow now synchronizes category data before issuing a single awaited settings update, while rejected file parsing and explicit save failures receive visible handling. Important Files Changed
Sequence DiagramsequenceDiagram
participant User
participant UI as Categorization settings
participant Categories as Category store
participant Settings as Settings store
participant Service as ActivityWatch service
User->>UI: Select category JSON
UI->>UI: Check file type and parse export
UI->>Categories: Import categories
Categories->>Categories: Add missing parents and sync primary set
User->>UI: Save
UI->>Categories: await save()
Categories->>Settings: update category sets, active IDs, legacy classes
Settings->>Service: Persist one settings snapshot
Service-->>Settings: Save result
Settings-->>Categories: Resolve
Categories->>Categories: Clear unsaved flag
Reviews (1): Last reviewed commit: "fix(categories): import JSON from Androi..." | Re-trigger Greptile |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #956 +/- ##
==========================================
+ Coverage 49.62% 49.75% +0.12%
==========================================
Files 46 47 +1
Lines 2783 2810 +27
Branches 630 608 -22
==========================================
+ Hits 1381 1398 +17
- Misses 1322 1391 +69
+ Partials 80 21 -59 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…atch#652 aw-server-rust#652 moved --testing on a fresh machine to ~/.cache/activitywatch-testing/log/. The old glob still pointed at the shared activitywatch root, so the rust-master matrix cell failed after tests already passed. Use a nullglob over activitywatch*/log so tagged releases and named profiles both work, and missing logs no longer fail the job.
|
CI red was not the category import: unit tests 35/35 and e2e 7/7 passed. Pushed |
|
CI-green and mergeable (Greptile 5/5) — waiting only on a maintainer click. This PR is ready to merge, but the bot has pull-only access to this repo and can't self-merge — surfacing it here so it isn't lost. The monitoring loop will stop re-flagging it now that this note is posted. |
Problem
v0.14.0b2 user report (ActivityWatch/aw-android#247):
Two independent bugs:
importCategoriesrequiredfile.type == 'application/json'. Android SAF/WebView often reports.jsonasapplication/octet-stream, empty, ortext/plain, so import silentlyconsole.error'd and returned.import()wrotethis.classesbut notcategory_sets.save()then firedsaveCategories()andsaveClasses()as two un-awaitedsettingsStore.update()calls. Those two saves raced: one could persist an empty/default snapshot, reload it, and the other would write defaults back.jsonEqcould also throw on an unserializable key and abort the whole save with no UI error.Fix
.jsonname, or Android-ambiguous types; reject camera/gallery images with a visible alert. Parse errors are visible instead of silent.accept=".json,application/json"so the Android picker from refactor: refactored event viewer (in Query/Search views) into component, changed use of (broken) aw-timeline to vis-timeline #248 prefers JSON.import()creates a primary set if needed, runscreateMissingParents, and syncs into that set before save.save()is async, awaits a singlesaveCategories()(which already writes the legacyclassesfield), and only clears the unsaved flag after success.jsonEqno longer throws the whole save if one key cannot be serialized.Testing
21 passed (including new import-file MIME cases and import→primary-set sync).
Does not close ActivityWatch/aw-android#247 on its own: the Android app still needs an
aw-webuisubmodule bump after this merges.