fix(categories): import JSON from Android SAF and persist a single save - #956
Conversation
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 597 608 +11
==========================================
+ Hits 1381 1398 +17
- Misses 1381 1391 +10
Partials 21 21 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
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. |
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 Git-Session-Id: f10637f5-76f0-5f0b-ae4a-7a9d86fab73f
850cdff to
e144738
Compare
|
Rebased onto current The only conflict was the CI log-path fix, which has since landed independently in #962. I dropped the now-redundant PR commit rather than duplicate that change. Targeted category-import tests pass (21/21), lint has no errors, and fresh CI is running. |
|
Fresh CI after the rebase is now fully green, and GitHub still reports the PR mergeable with a clean merge state. The earlier conflict resolution is complete; no further branch change is needed. Waiting only on maintainer merge. |
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.