Skip to content

New API Function from Stopwatch & Improve Program Plugin #3429

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

Merged
merged 6 commits into from
Apr 9, 2025

Conversation

Jack251970
Copy link
Contributor

New API Function from Stopwatch

Added new api functions to helper csharp plugin developers quickly log debug & info message with function executing time.

/// <summary>
/// Log debug message of the time taken to execute a method
/// Message will only be logged in Debug mode
/// </summary>
/// <returns>The time taken to execute the method in milliseconds</returns>
public long StopwatchLogDebug(string className, string message, Action action, [CallerMemberName] string methodName = "");

/// <summary>
/// Log debug message of the time taken to execute a method asynchronously
/// Message will only be logged in Debug mode
/// </summary>
/// <returns>The time taken to execute the method in milliseconds</returns>
public Task<long> StopwatchLogDebugAsync(string className, string message, Func<Task> action, [CallerMemberName] string methodName = "");

/// <summary>
/// Log info message of the time taken to execute a method
/// </summary>
/// <returns>The time taken to execute the method in milliseconds</returns>
public long StopwatchLogInfo(string className, string message, Action action, [CallerMemberName] string methodName = "");

/// <summary>
/// Log info message of the time taken to execute a method asynchronously
/// </summary>
/// <returns>The time taken to execute the method in milliseconds</returns>
public Task<long> StopwatchLogInfoAsync(string className, string message, Func<Task> action, [CallerMemberName] string methodName = "");

Improve Program Plugin

Use api functions instead of project reference in Program plugin.

@prlabeler prlabeler bot added the bug Something isn't working label Apr 8, 2025
@Jack251970 Jack251970 requested a review from Copilot April 8, 2025 13:56
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.

Copy link

github-actions bot commented Apr 8, 2025

@check-spelling-bot Report

🔴 Please review

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

❌ Errors Count
ℹ️ candidate-pattern 1
❌ forbidden-pattern 22
⚠️ non-alpha-in-dictionary 19

See ❌ Event descriptions for more information.

Pattern suggestions ✂️ (1)

You could add these patterns to .github/actions/spelling/patterns.txt:

# Automatically suggested patterns

# hit-count: 3 file-count: 1
# Non-English
[a-zA-Z]*[ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýÿĀāŁłŃńŅņŒœŚśŠšŜŝŸŽžź][a-zA-Z]{3}[a-zA-ZÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýÿĀāŁłŃńŅņŒœŚśŠšŜŝŸŽžź]*

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

gitstream-cm bot commented Apr 8, 2025

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

@Jack251970 Jack251970 requested review from jjw24 and taooceros April 8, 2025 13:58
Copy link
Contributor

coderabbitai bot commented Apr 8, 2025

📝 Walkthrough

Walkthrough

The changes standardize and centralize logging across multiple components by introducing a consistent ClassName field and replacing direct stopwatch calls with new API logging methods. Several classes now use a lazy-initialized IPublicAPI instance for logging execution times. In addition, the stopwatch functionality is simplified by removing cumulative tracking fields and methods. The IPublicAPI interface and its implementation receive new methods for both synchronous and asynchronous logging of elapsed time.

Changes

File(s) Change Summary
Flow.Launcher.Core/…/PluginManager.cs
Flow.Launcher.Core/…/PluginsLoader.cs
Flow.Launcher.Infrastructure/…/ImageLoader.cs
Flow.Launcher/App.xaml.cs
Plugins/…/Main.cs
Added a new ClassName field for consistent logging; replaced direct calls to Stopwatch methods with API calls (e.g. StopwatchLogDebugAsync, StopwatchLogInfoAsync); integrated lazy initialization of IPublicAPI where applicable.
Flow.Launcher.Infrastructure/Stopwatch.cs Removed cumulative tracking fields (Count, Locker) and methods (StartCount, EndCount), simplifying the stopwatch functionality while keeping individual timing methods.
Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs
Flow.Launcher/PublicAPIInstance.cs
Added four new logging methods (StopwatchLogDebug, StopwatchLogDebugAsync, StopwatchLogInfo, StopwatchLogInfoAsync) to enhance logging capabilities with context information.

Sequence Diagram(s)

sequenceDiagram
    participant Caller as Application Component
    participant API as IPublicAPI
    participant Stopwatch as Stopwatch
    Caller->>API: Call StopwatchLogInfoAsync(ClassName, message, action)
    API->>Stopwatch: Invoke NormalAsync(action)
    Stopwatch-->>API: Return elapsed time
    API-->>Caller: Return logged result & execution time
Loading

Possibly related PRs

Suggested labels

enhancement, kind/ux

Suggested reviewers

  • taooceros
  • jjw24
  • onesounds

Poem

Hi, I'm a code rabbit on a run,
Hopping through logs under the sun.
ClassName fields like carrots so sweet,
API calls guide my delicate feet.
Bouncing with joy through each logged beat!

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 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.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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: 0

🧹 Nitpick comments (1)
Flow.Launcher.Infrastructure/Image/ImageLoader.cs (1)

57-64: Improved logging with new API methods.

The code now uses the new StopwatchLogInfoAsync method instead of direct stopwatch/logging calls, providing more consistent logging with execution time tracking.

However, there's a minor redundancy in the log message:

-API.LogInfo(ClassName, $"Number of preload images is <{ImageCache.CacheSize()}>, Images Number: {ImageCache.CacheSize()}, Unique Items {ImageCache.UniqueImagesInCache()}");
+API.LogInfo(ClassName, $"Number of preload images is <{ImageCache.CacheSize()}>, Unique Items {ImageCache.UniqueImagesInCache()}");
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d33e751 and 1af9d06.

📒 Files selected for processing (8)
  • Flow.Launcher.Core/Plugin/PluginManager.cs (3 hunks)
  • Flow.Launcher.Core/Plugin/PluginsLoader.cs (2 hunks)
  • Flow.Launcher.Infrastructure/Image/ImageLoader.cs (4 hunks)
  • Flow.Launcher.Infrastructure/Stopwatch.cs (0 hunks)
  • Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs (1 hunks)
  • Flow.Launcher/App.xaml.cs (3 hunks)
  • Flow.Launcher/PublicAPIInstance.cs (2 hunks)
  • Plugins/Flow.Launcher.Plugin.Program/Main.cs (7 hunks)
💤 Files with no reviewable changes (1)
  • Flow.Launcher.Infrastructure/Stopwatch.cs
🧰 Additional context used
🧬 Code Definitions (5)
Plugins/Flow.Launcher.Plugin.Program/Main.cs (5)
Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs (3)
  • LogDebug (219-219)
  • LogInfo (224-224)
  • LogException (240-240)
Flow.Launcher/PublicAPIInstance.cs (6)
  • LogDebug (205-206)
  • LogInfo (208-209)
  • LogException (217-218)
  • Task (117-117)
  • Task (188-189)
  • Task (191-192)
Flow.Launcher.Core/Plugin/JsonRPCV2Models/JsonRPCPublicAPI.cs (2)
  • LogDebug (143-146)
  • LogInfo (148-151)
Plugins/Flow.Launcher.Plugin.Explorer/ContextMenu.cs (1)
  • LogException (471-474)
Flow.Launcher.Infrastructure/Storage/PluginJsonStorage.cs (1)
  • Task (49-59)
Flow.Launcher.Infrastructure/Image/ImageLoader.cs (2)
Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs (2)
  • LogInfo (224-224)
  • LogException (240-240)
Flow.Launcher/PublicAPIInstance.cs (2)
  • LogInfo (208-209)
  • LogException (217-218)
Flow.Launcher/App.xaml.cs (1)
Flow.Launcher/PublicAPIInstance.cs (1)
  • StopwatchLogInfo (441-442)
Flow.Launcher/PublicAPIInstance.cs (3)
Flow.Launcher.Infrastructure/Stopwatch.cs (2)
  • Stopwatch (7-62)
  • Normal (39-49)
Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs (14)
  • StopwatchLogDebug (482-482)
  • Task (73-73)
  • Task (170-170)
  • Task (178-178)
  • Task (191-191)
  • Task (342-342)
  • Task (391-391)
  • Task (405-405)
  • Task (428-428)
  • Task (455-455)
  • Task (475-475)
  • Task (489-489)
  • Task (501-501)
  • StopwatchLogInfo (495-495)
Flow.Launcher.Infrastructure/Logger/Log.cs (2)
  • Debug (204-207)
  • Debug (210-213)
Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs (1)
Flow.Launcher/PublicAPIInstance.cs (14)
  • StopwatchLogDebug (435-436)
  • Task (117-117)
  • Task (188-189)
  • Task (191-192)
  • Task (194-195)
  • Task (364-365)
  • Task (398-405)
  • Task (407-414)
  • Task (419-420)
  • Task (426-427)
  • Task (432-433)
  • Task (438-439)
  • Task (444-445)
  • StopwatchLogInfo (441-442)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
🔇 Additional comments (29)
Flow.Launcher.Core/Plugin/PluginManager.cs (3)

26-26: Good addition of ClassName field for logging

Adding a static field for the class name makes logging more consistent and maintainable across the codebase.


199-201: Appropriate use of new StopwatchLogDebugAsync API

This implementation correctly replaces the previous direct Stopwatch call with the new API method, using the ClassName field to maintain consistent logging format.


271-272: Good implementation of StopwatchLogDebugAsync

Properly updates the code to use the new API method for measuring query execution time while maintaining the same functionality.

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

37-38: Good addition of ClassName field for standardized logging

Adding a static field for the class name enhances log consistency and readability throughout the application.


140-195: Well-implemented StopwatchLogInfoAsync for startup timing

This change correctly replaces the direct Stopwatch call with the new API method, using the ClassName field to ensure consistent log formatting for application startup timing.


317-330: Appropriate use of StopwatchLogInfo for disposal timing

Good implementation of the synchronous version of the stopwatch logging API for the application dispose process.

Plugins/Flow.Launcher.Plugin.Program/Main.cs (8)

33-34: Good addition of ClassName field for standardized logging

Adding a static field for the class name ensures consistent log formatting and improves code maintainability.


112-113: Good implementation of LogDebug API

Successfully replaced direct Log.Debug call with the API's LogDebug method using the ClassName field for consistent log formats.


191-255: Well-implemented StopwatchLogInfoAsync for program preloading

The implementation correctly uses the new API method to log program preloading execution time, maintaining the same functionality while improving log consistency.


256-257: Good transition to API's LogInfo method

Successfully replaced direct Log.Info calls with API.LogInfo calls using the ClassName field for consistent log formatting.


298-299: Appropriate use of LogException API

Good implementation of the API's LogException method instead of direct Log.Exception call for error handling.


323-324: Consistent use of LogException API

This change maintains consistent error logging patterns throughout the class by using the API's LogException method.


335-336: Well-implemented StopwatchLogInfoAsync for Win32 program indexing

The change correctly uses the new API method to log program indexing execution time, improving log consistency.


340-341: Good implementation of StopwatchLogInfoAsync for UWP program indexing

Successfully implemented the same logging pattern for UWP program indexing, ensuring consistency throughout the codebase.

Flow.Launcher.Core/Plugin/PluginsLoader.cs (2)

19-24: Good implementation of ClassName field and API property

The changes correctly add:

  1. A static field for the class name to standardize logging
  2. A private static field for the API instance
  3. A property with lazy initialization to avoid premature API instance creation

This follows the same pattern used in PluginManager, ensuring consistency across the codebase.


67-116: Appropriate use of StopwatchLogDebug API

The implementation correctly replaces the direct Stopwatch call with the new API method, using the ClassName field to maintain consistent logging format for plugin initialization timing.

Flow.Launcher.Infrastructure/Image/ImageLoader.cs (4)

10-10: Added dependency for dependency injection.

The new CommunityToolkit.Mvvm.DependencyInjection dependency is used for retrieving the IPublicAPI service, aligning with the PR's goal of standardizing API access.


18-22: Good implementation of lazy-initialized API with standardized class name.

The implementation follows best practices with:

  • Clear comment explaining why static constructor initialization is avoided
  • Lazy initialization pattern for the API instance
  • Consistent ClassName field for standardized logging

This approach ensures the API is only initialized when needed, preventing unnecessary resource usage.


80-80: Standardized exception logging.

Updated to use the API's exception logging method which provides consistent formatting with class name context.


175-176: Enhanced exception logging with class context.

Both exceptions are now logged with standardized formatting including the class name for better traceability.

Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs (4)

477-482: New API method for synchronous debug logging with execution time tracking.

Well-documented method that logs debug messages with execution time measurement, following the same pattern as existing logging methods. This method enhances the API by providing standardized performance tracking capabilities for plugin developers.


484-489: New API method for asynchronous debug logging with execution time tracking.

This method provides the asynchronous counterpart to the synchronous version, maintaining a consistent API pattern. The documentation clearly explains that this logs only in debug mode and returns the execution time.


491-495: New API method for synchronous info logging with execution time tracking.

Well-structured method that follows the established pattern but logs at info level instead of debug. This will be useful for logging performance metrics that should always be visible regardless of debug settings.


497-501: New API method for asynchronous info logging with execution time tracking.

Completes the set of stopwatch logging methods with the asynchronous info-level variant. This provides a comprehensive set of options for plugin developers to track and log execution times.

Flow.Launcher/PublicAPIInstance.cs (5)

34-34: Proper aliasing to avoid namespace conflicts.

Good practice using an alias for the Stopwatch class to avoid conflicts with System.Diagnostics.Stopwatch.


435-436: Implementation of synchronous debug stopwatch logging.

Clean implementation using expression-bodied member syntax with proper message formatting that includes class and method context.


438-439: Implementation of asynchronous debug stopwatch logging.

The asynchronous implementation properly delegates to the Stopwatch.DebugAsync method with consistent message formatting.


441-442: Implementation of synchronous info stopwatch logging.

Proper implementation that delegates to Stopwatch.Normal for info-level logging with execution time tracking.


444-445: Implementation of asynchronous info stopwatch logging.

Completes the implementation set with consistent formatting and proper delegation to the underlying Stopwatch.NormalAsync method.

@Jack251970 Jack251970 added enhancement New feature or request and removed bug Something isn't working labels Apr 9, 2025

// We should not initialize API in static constructor because it will create another API instance
private static IPublicAPI api = null;
private static IPublicAPI API => api ??= Ioc.Default.GetRequiredService<IPublicAPI>();
Copy link
Member

Choose a reason for hiding this comment

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

Not an issue for now but we should think about a better way to safeguard this, maybe a design pattern we can use or something.

@jjw24 jjw24 merged commit c730361 into Flow-Launcher:dev Apr 9, 2025
8 checks passed
@jjw24 jjw24 added this to the 1.20.0 milestone Apr 9, 2025
@coderabbitai coderabbitai bot mentioned this pull request May 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants