Skip to content

refactor: Optimize process page#1017

Merged
GT-610 merged 4 commits intolollipopkit:mainfrom
GT-610:ref/process
Jan 21, 2026
Merged

refactor: Optimize process page#1017
GT-610 merged 4 commits intolollipopkit:mainfrom
GT-610:ref/process

Conversation

@GT-610
Copy link
Collaborator

@GT-610 GT-610 commented Jan 21, 2026

  • Remove redundant timer cancel in refresh method
  • Optimize incomplete data check to run only once
  • Change stop process from long-press to icon button in trailing row
  • Remove unused focus highlight feature

Summary by CodeRabbit

Release Notes

  • New Features

    • Added stop button to kill processes directly from the process list.
    • Confirmation dialog prevents accidental process termination.
  • UI/UX Improvements

    • Refined spacing and layout in process list items for better visual consistency.

✏️ Tip: You can customize this high-level summary in your review settings.

… 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
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 21, 2026

📝 Walkthrough

Walkthrough

The 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

Cohort / File(s) Summary
Process list page refactoring
lib/view/page/process.dart
Replaced int? _lastFocusId with bool _checkedIncompleteData to guard one-time validation logic; converted _sortModes to a final list initialized from ProcSortMode.values with conditional pruning on first incomplete-data detection; changed _buildItemTrail() return type from Widget? to Widget, added conditional spacing for CPU/memory data presence, and integrated a stop button (IconButton) that opens a kill confirmation dialog and executes SSH termination command with list refresh

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'refactor: Optimize process page' accurately describes the main changes: refactoring code patterns and optimizing the process page logic with flag-based checks and UI improvements.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

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

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

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 two removeWhere calls.

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 _client is 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

📥 Commits

Reviewing files that changed from the base of the PR and between 347d294 and 16d7ffb.

📒 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.from to create a mutable copy from enum values allows the list to be modified later when pruning unavailable sort options, while still making the reference final.

✏️ 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
@GT-610 GT-610 merged commit d14e974 into lollipopkit:main Jan 21, 2026
1 check passed
@GT-610 GT-610 deleted the ref/process branch January 21, 2026 16:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant