refactor: Optimize process page#1017
Conversation
… add a data integrity check flag Add the `_checkedIncompleteData` flag to avoid repeatedly checking data integrity Change `_sortModes` to a final variable and initialize it using `List.from` Remove unnecessary calls to `_timer.cancel`
…em operations Move the stop operation of the process item to the tail button, and remove the focus state-related code that is no longer used
📝 WalkthroughWalkthroughThe pull request refactors state management in the process list page, replacing a focused PID tracker with a one-time data-validation flag, adjusts sorting initialization to use a final immutable list, and adds process termination functionality with a confirmation dialog and SSH kill command execution. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In `@lib/view/page/process.dart`: - Around line 160-175: The confirmation dialog currently uses Btn.ok (in the context.showRoundDialog call) which omits a cancel option; replace Btn.ok with Btnx.cancelOk so the dialog shows both Cancel and OK for this destructive action, wiring Cancel to just close the dialog (context.pop()) and OK to perform the existing async work (close the dialog, then await context.showLoadingDialog(fn: () async { await _client?.run('kill ${proc.pid}'); await _refresh(); })), preserving the toList usage and keeping the handlers attached to Btnx.cancelOk. - Around line 153-156: The spacing logic currently adds UIs.width13 twice when proc.cpu != null and proc.mem == null; change the intermediate spacer after the CPU TwoLineText so it only renders when both CPU and MEM exist: replace the condition guarding the first UIs.width13 (currently proc.cpu != null) with proc.cpu != null && proc.mem != null so the spacer between TwoLineText(up: proc.cpu...) and TwoLineText(up: proc.mem...) appears only when both are present, while keeping the final UIs.width13 (proc.cpu != null || proc.mem != null) to add a single spacer before the stop button when either metric is shown. 🧹 Nitpick comments (2)
lib/view/page/process.dart (2)
79-80: Consider combining the tworemoveWherecalls.Both removals can be done in a single call for slightly cleaner code.
♻️ Suggested simplification
- _sortModes.removeWhere((e) => e == ProcSortMode.cpu); - _sortModes.removeWhere((e) => e == ProcSortMode.mem); + _sortModes.removeWhere((e) => e == ProcSortMode.cpu || e == ProcSortMode.mem);
166-171: Consider handling errors from the kill command.If
_clientis null or the kill command fails, the user receives no feedback. Consider adding error handling to inform the user when the operation doesn't succeed.♻️ Suggested improvement
await context.showLoadingDialog( fn: () async { - await _client?.run('kill ${proc.pid}'); - await _refresh(); + final client = _client; + if (client == null) { + context.showSnackBar(libL10n.fail); + return; + } + try { + await client.run('kill ${proc.pid}'); + await _refresh(); + } catch (e) { + context.showSnackBar('${libL10n.fail}: $e'); + } }, );
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
lib/view/page/process.dart
🧰 Additional context used
📓 Path-based instructions (1)
lib/view/**/*.dart
📄 CodeRabbit inference engine (CLAUDE.md)
lib/view/**/*.dart: Prefer widgets/utilities from fl_lib for common UI (e.g., CustomAppBar, context.showRoundDialog, Input, Btnx.cancelOk)
Prefer using libL10n strings before adding new ones to project l10n
Split UI into build, actions, and utils; use extension on to separate concerns
Files:
lib/view/page/process.dart
🧠 Learnings (4)
📓 Common learnings
Learnt from: GT-610 Repo: lollipopkit/flutter_server_box PR: 999 File: lib/data/provider/server/all.dart:0-0 Timestamp: 2026-01-11T10:26:03.064Z Learning: In lib/data/provider/server/all.dart, the `_refreshInProgress` guard was removed because: (1) each server has its own `_isRefreshing` protection in single.dart that prevents concurrent refreshes per server, (2) the coordination overhead in all.dart is minimal (milliseconds) with no harm from concurrent calls, (3) no code awaits the completer, and (4) removing it enables true parallelism where servers refresh independently without artificial serialization at the coordination layer. 📚 Learning: 2026-01-11T06:20:59.076Z
Learnt from: GT-610 Repo: lollipopkit/flutter_server_box PR: 0 File: :0-0 Timestamp: 2026-01-11T06:20:59.076Z Learning: In lib/view/page/server/detail/view.dart, the settings `cpuViewAsProgress`, `moveServerFuncs`, and `displayCpuIndex` are UI/display preferences that are modified through a separate settings page and cannot be changed while viewing the server detail page. Therefore, caching them as `late final` is intentional and acceptable—the values automatically refresh when users navigate away and back to the detail page, reducing redundant `fetch()` calls without compromising user experience. </add_learning> <!-- <review_comment_addressed> Applied to files:
lib/view/page/process.dart
📚 Learning: 2026-01-11T06:20:29.351Z
Learnt from: GT-610 Repo: lollipopkit/flutter_server_box PR: 0 File: :0-0 Timestamp: 2026-01-11T06:20:29.351Z Learning: In lib/view/page/server/detail/view.dart, the settings `cpuViewAsProgress`, `moveServerFuncs`, and `displayCpuIndex` are UI/display preferences that are modified through a separate settings page and cannot be changed while viewing the server detail page. Therefore, caching them as `late final` is intentional and acceptable—the values automatically refresh when users navigate away and back to the detail page, reducing redundant `fetch()` calls without compromising user experience. Applied to files:
lib/view/page/process.dart
📚 Learning: 2026-01-17T04:24:16.501Z
Learnt from: GT-610 Repo: lollipopkit/flutter_server_box PR: 0 File: :0-0 Timestamp: 2026-01-17T04:24:16.501Z Learning: In lib/core/extension/ssh_client.dart and lib/data/provider/container.dart, when executing Docker/Podman commands via SSH, stderr must be included in the output (not set to stderr: false) because the error detection logic relies on stderr messages like "command not found" to properly detect when Docker/Podman is not installed and display appropriate error prompts to users. Applied to files:
lib/view/page/process.dart
🔇 Additional comments (2)
lib/view/page/process.dart (2)
32-32: LGTM on the one-time data validation flag.Good optimization to avoid repeated incomplete data checks on every refresh cycle.
Also applies to: 76-83
38-38: LGTM on the sort modes initialization.Using
List.fromto create a mutable copy from enum values allows the list to be modified later when pruning unavailable sort options, while still making the referencefinal.
✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.
…ation dialog box Adjust the spacing condition between CPU and memory display, and only add spacing when both are present Modify the confirmation dialog for stopping the process, and add a cancel button to provide a better user experience
Combine two separate `removeWhere` calls into one, simplifying the code and enhancing readability
Summary by CodeRabbit
Release Notes
New Features
UI/UX Improvements
✏️ Tip: You can customize this high-level summary in your review settings.