-
-
Notifications
You must be signed in to change notification settings - Fork 448
Improve Shutdown & Restart & Hibernate in Sys Plugin #3250
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve Shutdown & Restart & Hibernate in Sys Plugin #3250
Conversation
@check-spelling-bot Report🔴 Please reviewSee the 📂 files view, the 📜action log, or 📝 job summary for details.
See ❌ Event descriptions for more information. If the flagged items are 🤯 false positivesIf items relate to a ...
|
Be a legend 🏆 by adding a before and after screenshot of the changes you made, especially if they are around UI/UX. |
📝 WalkthroughWalkthroughThe pull request updates two files in the Flow Launcher Sys plugin. In the main class, new using directives, a constant ( Changes
Sequence Diagram(s)sequenceDiagram
participant U as User
participant M as Main (Plugin)
participant P as PInvoke
participant Proc as Process.Start
U->>M: Request Shutdown/Restart/Logoff
M->>M: Call EnableShutdownPrivilege()
alt Privilege Enabled
M->>P: Invoke ExitWindowsEx with REASON
else Privilege Failed
M->>Proc: Execute shutdown command via Process.Start
end
Suggested labels
Suggested reviewers
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
Plugins/Flow.Launcher.Plugin.Sys/Main.cs (1)
109-145
: Consider closing the token handle to avoid a potential leak.
While this code successfully enables the shutdown privilege, the opened process token should be closed after use. AddingPInvoke.CloseHandle(tokenHandle);
ensures proper resource management.You could apply the following diff (example placement right before
return true
):+ PInvoke.CloseHandle(tokenHandle); return true;
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
Plugins/Flow.Launcher.Plugin.Sys/Main.cs
(11 hunks)Plugins/Flow.Launcher.Plugin.Sys/NativeMethods.txt
(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: gitStream.cm
🔇 Additional comments (12)
Plugins/Flow.Launcher.Plugin.Sys/Main.cs (11)
5-5
: Imports for PInvoke are proper.
No issues found; this import is needed to marshal between managed and unmanaged code.
13-13
: Security namespace import looks good.
This addition is necessary to reference Windows security constants and methods.
25-27
: Reason constant is well-defined and documented.
Declaring a planned, generic shutdown reason helps convey intent for system logs.
169-172
: Shutdown fallback approach is correct.
This ensures graceful handling if privilege elevation fails.
191-194
: Restart fallback approach is consistent.
Code is clear and mirrors the shutdown logic.
213-216
: Advanced boot restore similarly consistent.
No concerns; logic follows same fallback pattern.
235-235
: Log off uses direct PInvoke without fallback.
Logoff in Windows generally doesn’t require elevated shutdown privileges, so a fallback may be unnecessary.
258-262
: Sleep call is clear and appropriate.
SetSuspendState(false, false, false)
correctly triggers system sleep.
272-272
: Hibernate call is clear and appropriate.
SetSuspendState(true, false, false)
properly triggers system hibernation.
284-284
: Index Option command usage.
Launching “srchadmin.dll” via “control.exe” is a known approach for Windows indexing options.
322-322
: Open Recycle Bin command is straightforward.
No concerns with launching Explorer on this shell path.Plugins/Flow.Launcher.Plugin.Sys/NativeMethods.txt (1)
6-12
: New entries align with PInvoke requirements.
All newly declared methods (OpenProcessToken, LookupPrivilegeValue, AdjustTokenPrivileges, etc.) and constants (WIN32_ERROR, TOKEN_PRIVILEGES, SE_SHUTDOWN_NAME) match usage in Main.cs. No issues identified.
Do you know what would happen if you use |
If you use the former, the system in a state where other processes (e.g., firmware) can intervene before power-off and it may leave the system waiting for a manual power-off. Considering that user click to shutdown the computer, I think FL should not wait. If you use the later, the system will performs a hybrid shutdown (Fast Startup). Instead of fully shutting down, Windows hibernates the kernel and driver state. I think FL should not use this mode. |
🥷 Code experts: no user but you matched threshold 10 Jack251970, cibere have most 👩💻 activity in the files. See details
Activity based on git-commit:
Knowledge based on git-blame:
Activity based on git-commit:
Knowledge based on git-blame: To learn more about /:\ gitStream - Visit our Docs |
I am actually pretty curious whether we should have a way to use the hybrid shutdown. It is enabled by default for many computer I think, and for many people they wouldn't need a full shutdown but a fast startup would help. If they want to refresh some hardware state, most likely they will use restart instead of shutdown. I am not sure whether the current shutdown uses fast startup or the full shutdown. Maybe it worth to check. |
The current codes |
Sounds good, let's keep it for now. We can have the fast startup sometimes later. |
Improve Shutdown & Restart & Hibernate in Sys Plugin
Replace them with PInvoke function which can slightly improve execution speed.
Test