Skip to content

Fix default download directory and persist built-in aria2 sessions#75

Merged
GT-610 merged 2 commits into
mainfrom
fix/download-dir
May 4, 2026
Merged

Fix default download directory and persist built-in aria2 sessions#75
GT-610 merged 2 commits into
mainfrom
fix/download-dir

Conversation

@GT-610

@GT-610 GT-610 commented May 4, 2026

Copy link
Copy Markdown
Owner

Summary

  • Use the system Downloads folder as the default download directory when no config value exists, and normalize path joins to avoid malformed Windows paths.
  • Align the built-in aria2 lifecycle with Motrix-style recovery by saving session state on terminal task transitions and shutting down through RPC so completed tasks are not reloaded on the next start.
  • Add saveSession/shutdown RPC support for the built-in instance flow and normalize config/data file path handling.

Testing

  • dart format on the modified Dart files.
  • dart analyze on the modified Dart files: passed.
  • flutter test test\download_task_service_test.dart: passed.
  • flutter analyze: passed for the app code; one existing info-level lint remains in packages/fl_lib outside this change.

Open in Devin Review

Summary by CodeRabbit

  • Bug Fixes

    • Fixed default download directory resolution and normalization across platforms; defaults are now computed asynchronously and persisted when missing or on load failure.
  • Improvements

    • More reliable shutdown: attempts graceful RPC shutdown (with optional force) and waits before killing the process; improved session save behavior.
    • Session persistence optimized to save only for instances with terminal task changes.
    • Safer cross-platform path handling for configuration and downloads.
  • New Features

    • Exposes instance process PID for diagnostics.
    • Added helpers to obtain the default download directory (sync and async).

@coderabbitai

coderabbitai Bot commented May 4, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: cacdc0d5-2559-4e73-94ab-291a0682e208

📥 Commits

Reviewing files that changed from the base of the PR and between 9ace276 and 99ff65c.

📒 Files selected for processing (2)
  • lib/app.dart
  • lib/services/builtin_instance_service.dart
✅ Files skipped from review due to trivial changes (2)
  • lib/app.dart
  • lib/services/builtin_instance_service.dart

📝 Walkthrough

Walkthrough

Async default-download resolution added; path handling switched to package:path; Settings now normalizes and persists downloadDir defaults; Aria2 RPC gained a shutdown method; builtin instance stop attempts RPC save+shutdown with timed waits and kills; session saves are triggered for instances with tasks that transition to terminal states.

Changes

Instance lifecycle, settings, and session persistence

Layer / File(s) Summary
Data Shape / Utilities
lib/utils/default_download_directory.dart
Adds getDefaultDownloadDirectorySync() and async wrapper to resolve a platform-appropriate Downloads directory.
Settings defaults & file location
lib/models/settings.dart
Makes default download-dir resolution async, adds _defaultDownloadDirectory(), normalizes downloadDir with p.normalize, builds settings path with p.join, and ensures defaults are persisted. _applyDefaultSettings became Future<void> and resetToDefaults() awaits default dir.
Core RPC extension
lib/services/aria2_rpc_client.dart
Adds Future<bool> shutdown({bool force = false}) to call aria2.shutdown or aria2.forceShutdown, returning true when RPC result is 'OK', and logs/rethrows on error.
Builtin instance control
lib/services/builtin_instance_service.dart
Replaces string interpolation with p.join for paths, delegates default download dir to utility, appends --save-session-interval=30 and --force-save=false to Aria2 args, adds public pid getter, and updates stopInstance() to cancel streams, attempt _shutdownThroughRpcIfPossible() (saveSession + RPC shutdown) with timeouts, then kill/wait as fallback.
Notification → persistence wiring
lib/services/download_data_service.dart
_collectTaskNotifications now returns Set<String> of instance IDs that had terminal task transitions; refreshTasks captures those IDs and calls _saveSessionsForTerminalTransitions() to call client.saveSession() for affected connected instances.
Cosmetic UI
lib/app.dart
Reformats a Text(...) call for the total-speed Chip to a single-line expression without changing behavior.

Possibly related PRs

  • opt: Remove dead code #73 — Modifies similar service and settings code; potential overlap around pid getter and settings behavior.
  • opt: Cleanup #74 — Also changes Aria2RpcClient and touched settings/app files; likely related to the new RPC shutdown API and settings adjustments.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately captures the two main changes: fixing the default download directory and persisting built-in aria2 sessions through RPC shutdown.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Review rate limit: 9/10 reviews remaining, refill in 6 minutes.

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
lib/services/builtin_instance_service.dart (1)

106-124: 💤 Low value

Synchronous _defaultDownloadDir() duplicates logic from settings.dart.

This method mirrors _defaultDownloadDirectory() in lib/models/settings.dart but is synchronous (doesn't use path_provider). Consider extracting a shared utility to avoid drift between the two implementations.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/services/builtin_instance_service.dart` around lines 106 - 124, Duplicate
logic exists between the synchronous _defaultDownloadDir() and the async
_defaultDownloadDirectory() (which uses path_provider); extract the shared
decision logic into a single utility (e.g., getDefaultDownloadDirectorySync or a
sync helper) and have _defaultDownloadDir() call that helper while refactoring
the async _defaultDownloadDirectory() to reuse the same logic (or call a common
async wrapper that uses path_provider when available). Update references in
BuiltinInstanceService._defaultDownloadDir() and the settings model's
_defaultDownloadDirectory() to call the new shared utility so the behavior stays
consistent and avoids drift.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@lib/services/builtin_instance_service.dart`:
- Around line 106-124: Duplicate logic exists between the synchronous
_defaultDownloadDir() and the async _defaultDownloadDirectory() (which uses
path_provider); extract the shared decision logic into a single utility (e.g.,
getDefaultDownloadDirectorySync or a sync helper) and have _defaultDownloadDir()
call that helper while refactoring the async _defaultDownloadDirectory() to
reuse the same logic (or call a common async wrapper that uses path_provider
when available). Update references in
BuiltinInstanceService._defaultDownloadDir() and the settings model's
_defaultDownloadDirectory() to call the new shared utility so the behavior stays
consistent and avoids drift.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 6df8c363-dce3-40d5-a612-4db79a1246d8

📥 Commits

Reviewing files that changed from the base of the PR and between 2111303 and cc47d3e.

📒 Files selected for processing (4)
  • lib/models/settings.dart
  • lib/services/aria2_rpc_client.dart
  • lib/services/builtin_instance_service.dart
  • lib/services/download_data_service.dart

devin-ai-integration[bot]

This comment was marked as resolved.

@GT-610 GT-610 force-pushed the fix/download-dir branch from cc47d3e to 9ace276 Compare May 4, 2026 04:14
coderabbitai[bot]

This comment was marked as resolved.

@GT-610 GT-610 merged commit 3526dba into main May 4, 2026
3 checks passed
@GT-610 GT-610 deleted the fix/download-dir branch May 4, 2026 04:50
@coderabbitai coderabbitai Bot mentioned this pull request Jun 1, 2026
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