fix: support file exports in Tauri webview#763
fix: support file exports in Tauri webview#763ErikBjare merged 4 commits intoActivityWatch:masterfrom
Conversation
Adds a cross-platform download utility (src/util/export.ts) that detects Tauri webview at runtime and uses native save dialog + filesystem plugins instead of the browser download pattern which doesn't work in webviews. All 5 export functions (categories JSON, bucket JSON, all buckets JSON, bucket CSV, report JSON/CSV) now use the shared utility. Browser behavior is unchanged — the utility falls back to the existing Blob + createObjectURL pattern in non-Tauri contexts. Requires companion change in aw-tauri to register tauri-plugin-fs and add fs:default permission. Fixes ActivityWatch/aw-tauri#199
There was a problem hiding this comment.
Important
Looks good to me! 👍
Reviewed everything up to ded81bf in 6 seconds. Click for details.
- Reviewed
279lines of code in5files - Skipped
0files when reviewing. - Skipped posting
0draft comments. View those below. - Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
Workflow ID: wflow_WqR67Swj4mCMupVm
You can customize by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.
Greptile SummaryAdds cross-platform file export support for Tauri webview environment. The PR introduces a new download utility that detects the runtime environment and uses native Tauri file dialogs when available, falling back gracefully to standard browser downloads otherwise. Key Changes:
Issues Found:
Confidence Score: 3/5
Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[User clicks export] --> B{Check environment}
B -->|isTauri| C[downloadFileTauri]
B -->|browser| D[downloadFileBrowser]
C --> E{Dynamic import Tauri plugins}
E -->|Success| F[Show native save dialog]
E -->|Fail| G[Catch error, fallback]
F --> H{User selects path?}
H -->|Yes| I[Write file with writeTextFile]
H -->|No| J[Cancel, no action]
G --> D
D --> K[Create Blob + ObjectURL]
K --> L[Trigger browser download]
L --> M[Cleanup URL]
I --> N[File saved]
M --> N
Last reviewed commit: ded81bf |
Additional Comments (1)
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #763 +/- ##
==========================================
- Coverage 26.20% 25.67% -0.53%
==========================================
Files 29 30 +1
Lines 1706 1741 +35
Branches 311 303 -8
==========================================
Hits 447 447
- Misses 1195 1272 +77
+ Partials 64 22 -42 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
The @tauri-apps/plugin-dialog and @tauri-apps/plugin-fs modules are not in package.json since they're only available in the aw-tauri runtime. The dynamic imports with try/catch already handle graceful fallback, but bundlers (webpack, vite) still try to resolve modules at build time. Add webpackIgnore and @vite-ignore magic comments to skip static resolution while keeping the dynamic import pattern intact.
|
Fixed CI failure in bf8ef99. The build was failing because webpack and vite try to statically resolve Fix: added |
…mports webpack4 doesn't support /* webpackIgnore */ magic comments, and rollup ignores /* @vite-ignore */ during production builds. Using new Function() to create a runtime-only dynamic import bypasses static analysis in both bundlers while still working correctly in the Tauri webview at runtime.
|
Follow-up fix in b614261: previous approach (bundler-ignore magic comments) didn't work.
New approach: |
|
Addressed greptile's finding: added guard against empty |
|
The remaining CI failure (
The cleanup steps run with |
Summary
Fixes file export functionality in the Tauri webview (ActivityWatch/aw-tauri#199).
The existing export code uses browser-specific download patterns (
<a download>,data:URIs,URL.createObjectURL) that don't work in Tauri's webview. This PR adds a cross-platform download utility that:window.__TAURI__@tauri-apps/plugin-dialog(native save dialog) +@tauri-apps/plugin-fs(file write)Files changed
src/util/export.ts— New cross-platform download utilitysrc/tauri-plugins.d.ts— Type declarations for Tauri plugin dynamic importssrc/views/settings/CategorizationSettings.vue— Categories export uses utilitysrc/views/Buckets.vue— Bucket JSON/CSV exports use utility (converted direct API links to click handlers)src/views/Report.vue— Report JSON/CSV exports use utilityCompanion change needed
This PR requires a companion change in
aw-taurito registertauri-plugin-fs:tauri-plugin-fs = "2"tosrc-tauri/Cargo.tomldependencies"fs:default"tosrc-tauri/capabilities/default.jsonpermissionslib.rs:.plugin(tauri_plugin_fs::init())I can submit that companion PR if this approach looks good.
Test plan
Important
Adds cross-platform download utility for file exports in Tauri webview, updating several Vue components to use this utility.
src/util/export.tsto handle file exports in Tauri and browser environments.window.__TAURI__.@tauri-apps/plugin-dialogand@tauri-apps/plugin-fsfor file exports in Tauri.src/tauri-plugins.d.tsfor Tauri plugin dynamic imports.CategorizationSettings.vue,Buckets.vue, andReport.vueto use the new download utility for JSON/CSV exports.aw-taurito registertauri-plugin-fsinCargo.tomlandlib.rs.This description was created by
for ded81bf. You can customize this summary. It will automatically update as commits are pushed.