Skip to content
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

Support Logon Task for Faster Startup Experience #3218

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from

Conversation

Jack251970
Copy link
Contributor

Add support for FL to use logon task instead of startup entry for faster strartup experience.

Test

After using logon task for startup, FL launches as fast as PowerToys (the center app in the tray) which uses logon task for startup as well.

Also, it launchers faster than other apps using startup entry, like Microsoft Security Center (You cannot see it here because it has not launched yet.)
Screenshot 2025-01-31 215138

Related issue: #3212.

This comment has been minimized.

Copy link

gitstream-cm bot commented Jan 31, 2025

🥷 Code experts: jjw24, Yusyuriv

jjw24, Yusyuriv have most 👩‍💻 activity in the files.
Yusyuriv, jjw24 have most 🧠 knowledge in the files.

See details

Flow.Launcher.Infrastructure/UserSettings/Settings.cs

Activity based on git-commit:

jjw24 Yusyuriv
JAN
DEC 5 additions & 3 deletions
NOV
OCT
SEP
AUG

Knowledge based on git-blame:
Yusyuriv: 15%
jjw24: 3%

Flow.Launcher/App.xaml.cs

Activity based on git-commit:

jjw24 Yusyuriv
JAN
DEC
NOV
OCT
SEP
AUG

Knowledge based on git-blame:
jjw24: 15%
Yusyuriv: 3%

Flow.Launcher/Flow.Launcher.csproj

Activity based on git-commit:

jjw24 Yusyuriv
JAN
DEC
NOV
OCT
SEP
AUG

Knowledge based on git-blame:
jjw24: 12%

Flow.Launcher/Helper/AutoStartup.cs

Activity based on git-commit:

jjw24 Yusyuriv
JAN
DEC
NOV
OCT
SEP
AUG

Knowledge based on git-blame:
Yusyuriv: 64%

Flow.Launcher/Languages/en.xaml

Activity based on git-commit:

jjw24 Yusyuriv
JAN
DEC 2 additions & 0 deletions
NOV
OCT
SEP
AUG

Knowledge based on git-blame:
jjw24: 8%
Yusyuriv: 6%

Flow.Launcher/Languages/zh-cn.xaml

Activity based on git-commit:

jjw24 Yusyuriv
JAN
DEC 2 additions & 0 deletions
NOV
OCT
SEP
AUG 79 additions & 68 deletions

Knowledge based on git-blame:
jjw24: 51%

Flow.Launcher/Languages/zh-tw.xaml

Activity based on git-commit:

jjw24 Yusyuriv
JAN
DEC 2 additions & 0 deletions
NOV
OCT
SEP
AUG 13 additions & 2 deletions

Knowledge based on git-blame:
jjw24: 97%

Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs

Activity based on git-commit:

jjw24 Yusyuriv
JAN
DEC
NOV
OCT
SEP
AUG

Knowledge based on git-blame:
Yusyuriv: 100%

Flow.Launcher/SettingPages/Views/SettingsPaneGeneral.xaml

Activity based on git-commit:

jjw24 Yusyuriv
JAN
DEC
NOV
OCT
SEP
AUG

Knowledge based on git-blame:
Yusyuriv: 37%

To learn more about /:\ gitStream - Visit our Docs

Copy link

gitstream-cm bot commented Jan 31, 2025

Be a legend 🏆 by adding a before and after screenshot of the changes you made, especially if they are around UI/UX.

Copy link
Contributor

coderabbitai bot commented Jan 31, 2025

📝 Walkthrough

Walkthrough

This pull request introduces a new feature for configuring application startup in Flow Launcher by adding support for Windows Task Scheduler logon tasks. The changes span multiple files, including settings, helper classes, language resources, and UI components. The new functionality allows users to choose between traditional registry-based startup and a logon task-based approach, potentially offering a faster startup experience. The implementation includes comprehensive error handling and multilingual support for the new startup option.

Changes

File Change Summary
Flow.Launcher.Infrastructure/UserSettings/Settings.cs Added UseLogonTaskForStartup boolean property
Flow.Launcher/App.xaml.cs Modified AutoStartup method to use new settings parameter
Flow.Launcher/Flow.Launcher.csproj Added TaskScheduler package reference (v2.11.0)
Flow.Launcher/Helper/AutoStartup.cs Extensive modifications to support logon task management
Flow.Launcher/Languages/en.xaml Added localized string for new startup option
Flow.Launcher/Languages/zh-cn.xaml Added localized string for new startup option
Flow.Launcher/Languages/zh-tw.xaml Added localized string for new startup option
Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs Added UseLogonTaskForStartup property
Flow.Launcher/SettingPages/Views/SettingsPaneGeneral.xaml Added toggle switch for new startup option

Possibly related PRs

Suggested Labels

bug, kind/ui, dependencies, Explorer Plugin

Suggested Reviewers

  • JohnTheGr8
  • taooceros
  • jjw24

Poem

🐰 A Startup Bunny's Ballad 🚀

With logon tasks, we hop so bright,
Launching faster, pure delight!
Registry or scheduler's embrace,
Flow Launcher runs with rabbit grace.
Startup magic, swift and neat! 🌟


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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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: 1

🧹 Nitpick comments (2)
Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs (1)

64-85: Switching startup method is done effectively.
Toggling UseLogonTaskForStartup triggers a quick disable-enable routine to transition smoothly between registry and task-based startup. As a good-to-have, consider refactoring into a single switch function if multiple toggles become too frequent.

Flow.Launcher/SettingPages/Views/SettingsPaneGeneral.xaml (1)

39-44: Consider adding an icon for consistency.

The new card for logon task setting is missing an icon attribute, while other cards in this file use icons. Consider adding an icon for visual consistency.

Apply this diff to add an icon:

-            <cc:Card Title="{DynamicResource useLogonTaskForStartup}">
+            <cc:Card Title="{DynamicResource useLogonTaskForStartup}" Icon="&#xe8fc;">
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6cf7674 and 3f93d18.

📒 Files selected for processing (9)
  • Flow.Launcher.Infrastructure/UserSettings/Settings.cs (1 hunks)
  • Flow.Launcher/App.xaml.cs (1 hunks)
  • Flow.Launcher/Flow.Launcher.csproj (1 hunks)
  • Flow.Launcher/Helper/AutoStartup.cs (3 hunks)
  • Flow.Launcher/Languages/en.xaml (1 hunks)
  • Flow.Launcher/Languages/zh-cn.xaml (2 hunks)
  • Flow.Launcher/Languages/zh-tw.xaml (2 hunks)
  • Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs (2 hunks)
  • Flow.Launcher/SettingPages/Views/SettingsPaneGeneral.xaml (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: gitStream.cm
🔇 Additional comments (16)
Flow.Launcher/Helper/AutoStartup.cs (8)

2-4: Imports look correct for newly introduced functionalities.
No concerns found with these added using statements.

Also applies to: 8-8


15-16: Consider clarifying task naming.
The constants for task name and description look fine. However, ensure that the naming remains consistent across logs and user-facing messages so users can identify the task more easily.


22-27: Centralized check is valid but consider text clarifications.
Comment indicates checking the logon task first, which aligns with the new logic. No immediate issues are found here.


70-85: Disable logic is straightforward and consistent.
The updated signature adds flexibility for disabling either the registry entry or the scheduled task. Looks good.


91-103: Enable logic is well structured.
Similar to the disable method, enabling either logon task or registry-based startup is properly separated by parameter.


111-138: Check administrative privileges for correct run level execution.
The scheduling logic is robust. The conditional for setting RunLevel.Highest is appropriate.


140-153: Unscheduling approach is appropriate.
This routine correctly removes existing tasks by name and handles exceptions gracefully.


155-160: Role check for administrative context is correct.
Implementation using WindowsPrincipal is standard practice. No changes necessary.

Flow.Launcher/App.xaml.cs (1)

122-122: Method call respects user preference for logon task startup.
Passing _settings.UseLogonTaskForStartup into Enable() aligns with the new approach. The existing exception handling ensures graceful fallback if enabling fails.

Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs (2)

45-48: Selective enable logic is correct.
The property setter checks if startup is toggled on and correctly calls AutoStartup.Enable(UseLogonTaskForStartup).


50-54: Disabling multiple startup methods ensures consistency.
Calling Disable(true) followed by Disable(false) is thorough, preventing leftover startup entries.

Flow.Launcher.Infrastructure/UserSettings/Settings.cs (1)

241-241: LGTM!

The new property is well-placed near other startup-related settings and follows the existing code style.

Flow.Launcher/Languages/zh-cn.xaml (1)

50-50: LGTM!

The translation is accurate and appropriately placed in the startup settings section.

Flow.Launcher/Languages/zh-tw.xaml (1)

50-50: LGTM!

The translation is accurate and appropriately placed in the startup settings section.

Flow.Launcher/Languages/en.xaml (1)

49-49: LGTM!

The string resource is well-written, follows naming conventions, and clearly explains the benefit of using a logon task for startup.

Flow.Launcher/Flow.Launcher.csproj (1)

103-103: Verify the TaskScheduler package version.

The package version is fixed at 2.11.0. Let's verify if this is the latest stable version and check for any security advisories.

✅ Verification successful

TaskScheduler package version 2.11.0 is current and secure

The project is using the latest stable version available on NuGet, and no security vulnerabilities were found.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for latest version and security advisories of the TaskScheduler package.

# Check NuGet for latest versions
curl -s https://api.nuget.org/v3/registration5-gz-semver2/taskscheduler/index.json | jq -r '.items[0].upper'

# Check for security advisories
gh api graphql -f query='
{
  securityVulnerabilities(first: 5, ecosystem: NUGET, package: "TaskScheduler") {
    nodes {
      advisory {
        summary
        severity
        publishedAt
      }
      vulnerableVersionRange
      firstPatchedVersion {
        identifier
      }
    }
  }
}'

Length of output: 517


Script:

#!/bin/bash
# Description: Check latest version of TaskScheduler package using alternative NuGet API endpoint
curl -s "https://api.nuget.org/v3-flatcontainer/taskscheduler/index.json" | jq -r '.versions[]' | sort -V | tail -n 1

Length of output: 124

Flow.Launcher/Helper/AutoStartup.cs Outdated Show resolved Hide resolved
Copy link

@check-spelling-bot Report

🔴 Please review

See the 📂 files view, the 📜action log, or 📝 job summary for details.

❌ Errors Count
❌ forbidden-pattern 22
⚠️ ignored-expect-variant 1
⚠️ non-alpha-in-dictionary 19

See ❌ Event descriptions for more information.

If the flagged items are 🤯 false positives

If items relate to a ...

  • binary file (or some other file you wouldn't want to check at all).

    Please add a file path to the excludes.txt file matching the containing file.

    File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.

    ^ refers to the file's path from the root of the repository, so ^README\.md$ would exclude README.md (on whichever branch you're using).

  • well-formed pattern.

    If you can write a pattern that would match it,
    try adding it to the patterns.txt file.

    Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.

    Note that patterns can't match multiline strings.

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: 0

♻️ Duplicate comments (1)
Flow.Launcher/Helper/AutoStartup.cs (1)

44-69: ⚠️ Potential issue

Logic error: returns true even when the task doesn't exist.

If task is null, the method proceeds to return true, which incorrectly signals that the logon task is enabled.

Apply a fix to return false when the task is not found:

 private static bool CheckLogonTask()
 {
     using var taskService = new TaskService();
     var task = taskService.RootFolder.AllTasks.FirstOrDefault(t => t.Name == LogonTaskName);
-    if (task != null)
+    if (task == null)
+    {
+        return false;
+    }
     {
         try
         {
🧹 Nitpick comments (3)
Flow.Launcher/Helper/AutoStartup.cs (3)

22-27: Add error handling for logon task check.

The logon task check should be wrapped in a try-catch block similar to the registry check to ensure robustness.

 // Check if logon task is enabled
-if (CheckLogonTask())
+try
 {
-    return true;
+    if (CheckLogonTask())
+    {
+        return true;
+    }
+}
+catch (Exception e)
+{
+    Log.Error("AutoStartup", $"Ignoring non-critical logon task error (querying if enabled): {e}");
 }

Line range hint 71-111: Add parameter validation.

The methods should validate the state before making changes to avoid potential race conditions.

 public static void Enable(bool logonTask)
 {
+    // Avoid enabling if already enabled with the same method
+    if (IsEnabled && CheckLogonTask() == logonTask)
+    {
+        return;
+    }
+
     try
     {

113-161: Enhance security settings for the scheduled task.

Consider adding these security-related improvements:

  1. Set AllowHardTerminate to false to prevent force-stopping
  2. Enable RunOnlyIfNetworkAvailable if network connectivity is required
  3. Add SecurityDescriptor to restrict task access
 td.Settings.StopIfGoingOnBatteries = false;
 td.Settings.DisallowStartIfOnBatteries = false;
 td.Settings.ExecutionTimeLimit = TimeSpan.Zero;
+td.Settings.AllowHardTerminate = false;
+td.Settings.RunOnlyIfNetworkAvailable = true;
+
+// Restrict access to SYSTEM and Administrators
+td.SecurityDescriptor = "D:(A;;FRFX;;;SY)(A;;FRFX;;;BA)";
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3f93d18 and 3d9a6b2.

📒 Files selected for processing (1)
  • Flow.Launcher/Helper/AutoStartup.cs (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
🔇 Additional comments (1)
Flow.Launcher/Helper/AutoStartup.cs (1)

8-8: LGTM!

The new imports and constants are well-defined and appropriate for the task scheduler functionality.

Also applies to: 15-16

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant