Commit 0624ca5
authored
Refactor 4 (#80)
* fix: resolve 8 bugs across tray, settings, dialog, and lifecycle
Bug fixes:
- SystemTrayService.updateMenuState now rebuilds tray context menu after
updating labels (menu was stale until next right-click)
- BuiltinInstanceService.dispose() explicitly discards stopInstance() future
instead of fire-and-forget, and removes duplicate _upnpService.shutdown()
call (stopInstance() already handles UPnP shutdown)
- AppearanceDialog: await async setThemeMode/setPrimaryColor calls so
try-catch blocks can actually catch failures; add mounted guard before
showing SnackBar after await
- SettingsPage locale dialog: await setLocale() before Navigator.pop so
save failures are not silently swallowed; add mounted guard
- DebugProvider: replace in-place VNode list mutation (add/removeRange/clear)
with immutable list reassignment to maintain VNode setter contract
- Input: add didUpdateWidget to sync _obscureText when parent changes
obscureText prop
- App: remove duplicate loadSettings() call from _ThemeProviderState.initState
(HomeWrapper._initialize already handles loading with proper await)
* perf: reduce repeated settings reads and remove dead initialization code
Performance:
- Refactor _getConfiguredRpcPort/Secret to accept optional settings map
parameter, eliminating 2 redundant _readSettingsSnapshot() calls in both
_buildArgs() and getBuiltinInstanceConfig() (6 sync file reads → 4)
- Remove unreachable duplicate guards in SystemTrayService.initialize()
(dead code after in-flight await)
* refactor: code quality improvements across settings, widgets, and app
Code quality:
- SettingsPage._buildSettingsGroup: remove no-op identity map
(.map((child) => child))
- Settings._settingsFileName: change from final to static const
- Settings: inline trivial _getDataDirectory() wrapper (single caller)
- CustomAppBar/CardX: remove redundant key forwarding to inner widget
(Flutter handles key reconciliation on the outermost widget)
- App: extract _swapListener<T> helper to deduplicate 3 near-identical
listener swap blocks in didChangeDependencies
* chore: minor cleanup across settings, enums, and virtual window frame
Cleanup:
- Remove unused dart:async import in AutoHideWindowService
- Fix _formatVersionLabel to display full version string (was showing
only patch number, e.g. 'v3' instead of 'v1.2.3')
- Remove redundant inline comments on enum values in enums.dart
(comments restated the value names)
- Simplify VirtualWindowFrame switch to a single conditional expression
(first and third switch arms produced identical output)
* Update packages
* fix: resolve 5 bugs in RPC client, debug provider, and selection pruning
Bug fixes:
- DebugProvider: trim widgets.value alongside lines and _widgetCounts
(widgets list was growing unboundedly while lines was capped at 100)
- Aria2RpcClient._handleWebSocketMessage: add type guard for non-Map
JSON responses (arrays/primitives caused NoSuchMethodError)
- Aria2RpcClient._callHttpRpc: replace _httpClient! force-unwrap with
null check + ConnectionFailedException (prevents crash after close())
- Aria2RpcClient: store WebSocket StreamSubscription in
_webSocketSubscription field; cancel in close() and _connectWebSocket
to prevent callbacks firing on disposed client
- DownloadPage._pruneSelection: skip setState when no keys were removed
(prevents unnecessary rebuild cycles on every data change)
* perf: optimize filter, sort, and pieces grid rendering
Performance:
- DownloadPage._filterTasks: combine category filter, status/type filter,
and search filter into a single retainWhere pass (was creating 3-5
intermediate lists via .where().toList() per filter call)
- DownloadPage._filterTasks: inline sort key computation in comparator
(eliminates O(n) sortKeys map allocation per sort)
- TaskDetailsBtHelpers._buildPiecesGrid: replace Wrap+List.generate with
CustomPaint painter (renders thousands of pieces without creating
individual Container widgets, eliminates O(n) widget allocation)
* refactor: code quality improvements across RPC client, dialogs, and models
Code quality:
- Aria2RpcClient._callHttpRpc: remove redundant response.body.contains
check for 'Unauthorized' (structured JSON check is sufficient)
- Aria2RpcClient.getVersion: delegate to getVersionInfo() to eliminate
duplicate RPC call
- Aria2RpcClient._handleWebSocketError: always wrap errors in
ConnectionFailedException instead of leaking raw error types
- AddTaskDialog: move outputField creation inside two-column branch
(was allocated but unused in single-column path)
- DownloadTask: add key getter ('::') to eliminate
duplicate _taskKey function in download_page.dart and task_list_view.dart
- FilterSelector: inline trivial _getInstanceFilterOptions wrapper
* chore: minor cleanup in task service, utils, and helpers
Cleanup:
- DownloadTaskService: inline trivial _stoppingSeedingTip and
_failedToStopSeedingMessage wrappers (single-line l10n accessors)
- task_utils: use Uri.file() instead of Uri.parse('file://...') for
correct platform-specific file URI construction (handles paths with
spaces and special characters on Linux/macOS)
- TaskDetailsBtHelpers: add explanatory comment to catch(_) block in
parseTorrentMetadata (best-effort parsing returns empty on malformed
torrent data)
* fix: address review findings — guards, error handling, and formatting
Bug fixes:
- TaskDetailsBtHelpers._buildPiecesGrid: add empty pieces guard to
prevent ArgumentError from .clamp(1, 0) when pieces list is empty
- Aria2RpcClient._callHttpRpc: guard data['error'] is Map before
accessing ['message'] to prevent TypeError on malformed responses
- Aria2RpcClient._handleWebSocketMessage: same guard for data['error']
is Map before accessing ['message']
- AppearanceDialog: add try-catch to G and B slider onChangeEnd handlers
(R slider already had error handling, G/B were missing)
Formatting:
- Run dart format on 7 files to comply with project 80-column style:
virtual_window_frame, task_details_bt_helpers, download_page, enums,
download_task_service, system_tray_service, aria2_rpc_client
Skipped findings (not valid):
- _connectWebSocket await subscription cancel: cancel() returns
synchronously for non-pending operations, no race condition risk
- settings_page setLocale try-catch: already has await + context.mounted
guard, setLocale failures propagate as unhandled which is acceptable1 parent b2d285b commit 0624ca5
23 files changed
Lines changed: 331 additions & 293 deletions
File tree
- lib
- kit
- provider
- widgets
- models
- pages
- download_page
- components
- models
- services
- utils
- settings_page
- components
- services
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | 48 | | |
56 | 49 | | |
57 | 50 | | |
| |||
279 | 272 | | |
280 | 273 | | |
281 | 274 | | |
282 | | - | |
283 | | - | |
284 | | - | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
285 | 280 | | |
286 | | - | |
287 | | - | |
288 | | - | |
289 | | - | |
290 | | - | |
291 | 281 | | |
292 | | - | |
293 | | - | |
294 | | - | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
295 | 287 | | |
296 | | - | |
297 | | - | |
298 | | - | |
299 | | - | |
300 | | - | |
301 | 288 | | |
302 | | - | |
303 | | - | |
304 | | - | |
305 | | - | |
306 | | - | |
307 | | - | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
308 | 295 | | |
309 | 296 | | |
310 | 297 | | |
311 | 298 | | |
312 | 299 | | |
313 | 300 | | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
314 | 314 | | |
315 | 315 | | |
316 | 316 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
| 31 | + | |
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
50 | | - | |
| 50 | + | |
51 | 51 | | |
52 | 52 | | |
53 | | - | |
| 53 | + | |
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
| |||
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
64 | | - | |
| 64 | + | |
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
68 | | - | |
| 68 | + | |
69 | 69 | | |
70 | | - | |
71 | | - | |
| 70 | + | |
| 71 | + | |
72 | 72 | | |
73 | 73 | | |
74 | | - | |
| 74 | + | |
| 75 | + | |
75 | 76 | | |
76 | 77 | | |
77 | 78 | | |
78 | | - | |
| 79 | + | |
79 | 80 | | |
80 | 81 | | |
81 | | - | |
82 | 82 | | |
83 | 83 | | |
84 | 84 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | | - | |
34 | 33 | | |
35 | 34 | | |
36 | 35 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
23 | 22 | | |
24 | 23 | | |
25 | 24 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
72 | 80 | | |
73 | 81 | | |
74 | 82 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
35 | 36 | | |
36 | 37 | | |
37 | 38 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
87 | | - | |
| 87 | + | |
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
91 | 91 | | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | 92 | | |
98 | 93 | | |
99 | 94 | | |
| |||
165 | 160 | | |
166 | 161 | | |
167 | 162 | | |
168 | | - | |
| 163 | + | |
169 | 164 | | |
170 | 165 | | |
171 | 166 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
559 | 559 | | |
560 | 560 | | |
561 | 561 | | |
562 | | - | |
563 | | - | |
564 | | - | |
565 | | - | |
566 | | - | |
567 | | - | |
568 | | - | |
569 | | - | |
570 | | - | |
571 | | - | |
572 | | - | |
573 | | - | |
574 | 562 | | |
575 | 563 | | |
576 | 564 | | |
| |||
589 | 577 | | |
590 | 578 | | |
591 | 579 | | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
592 | 593 | | |
593 | 594 | | |
594 | 595 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
91 | | - | |
| 91 | + | |
92 | 92 | | |
93 | 93 | | |
94 | 94 | | |
| |||
220 | 220 | | |
221 | 221 | | |
222 | 222 | | |
223 | | - | |
224 | | - | |
225 | | - | |
226 | | - | |
227 | 223 | | |
228 | 224 | | |
229 | 225 | | |
| |||
0 commit comments