Skip to content

Conversation

Jack251970
Copy link
Member

@Jack251970 Jack251970 commented Apr 2, 2025

Move format function location

Move Flow.Launcher.Infrastructure.Format function to Updater.cs since this function is only used by Updater.cs.

Move ValidateDirectory functions location

Move ValidateDataDirectory() and ValidateDirectory() function in Flow.Launcher.Infrastructure project to FilesFolders.cs since they are functions related to directory and Program and WebSearch plugin use them so we would better to put them in Flow.Launcher.Plugin project for all plugin usage.

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.

Pull Request Overview

This pull request reorganizes directory validation and JSON formatting functions to centralize helper functionality in more appropriate classes. Key changes include:

  • Replacing calls to Helper.ValidateDirectory and Helper.ValidateDataDirectory with FilesFolders methods.
  • Removing the directory validation and JSON formatting functions from Helper.cs.
  • Adding a local JSON formatting helper in Updater.cs for logging purposes.

Reviewed Changes

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

Show a summary per file
File Description
Plugins/Flow.Launcher.Plugin.WebSearch/Main.cs Updates call to validate bundled data directory using FilesFolders.
Plugins/Flow.Launcher.Plugin.Program/Main.cs Updates directory validation call to use FilesFolders instead of Helper.
Flow.Launcher.Plugin/SharedCommands/FilesFolders.cs Introduces new directory validation functions.
Flow.Launcher.Infrastructure/Storage/* Refactors directory validation in various storage classes.
Flow.Launcher.Infrastructure/Helper.cs Removes redundant validation and formatting methods.
Flow.Launcher.Core/Updater.cs Replaces JSON formatting call with a new local function.
Comments suppressed due to low confidence (2)

Flow.Launcher.Core/Updater.cs:55

  • [nitpick] The new local 'Formatted' method duplicates functionality that was previously available in Helper. Consider refactoring to use a common shared utility for JSON formatting to avoid code duplication and ensure consistency across the codebase.
Log.Info(|Updater.UpdateApp|Future Release <{Formatted(newUpdateInfo.FutureReleaseEntry)}>)

Flow.Launcher.Plugin/SharedCommands/FilesFolders.cs:326

  • The file name 'FilesFolders.cs' is inconsistent with the PR description referring to 'FileFolders.cs'. Consider aligning the file name with the intended naming convention for clarity and consistency.
public static void ValidateDirectory(string path)

Copy link

github-actions bot commented Apr 2, 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 2, 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 Apr 2, 2025

📝 Walkthrough

Walkthrough

The pull request refactors directory validation and JSON formatting functionality across multiple modules. The Updater class now includes a new generic Formatted<T> method for logging formatted JSON output. Several methods and a static constructor have been removed from the Helper class, and their responsibilities have been shifted to the newly introduced FilesFolders class. As a result, various storage and plugin components now call validation methods from FilesFolders instead of Helper.

Changes

File(s) Change Summary
Flow.Launcher.Core/Updater.cs Added new private static method Formatted<T>(T t) to serialize objects as indented JSON. Updated logging in UpdateAppAsync to use the new method.
Flow.Launcher.Infrastructure/Helper.cs Removed static constructor, private variable (jsonFormattedSerializerOptions), and methods ValidateDataDirectory, ValidateDirectory, and the extension Formatted<T>, reducing its utility.
Flow.Launcher.Infrastructure/Storage/BinaryStorage.cs, Flow.Launcher.Infrastructure/Storage/FlowLauncherJsonStorage.cs, Flow.Launcher.Infrastructure/Storage/JsonStorage.cs, Flow.Launcher.Infrastructure/Storage/PluginJsonStorage.cs, Plugins/Flow.Launcher.Plugin.Program/Main.cs, Plugins/Flow.Launcher.Plugin.WebSearch/Main.cs Replaced calls to Helper.ValidateDirectory/Helper.ValidateDataDirectory with corresponding calls to FilesFolders.ValidateDirectory/FilesFolders.ValidateDataDirectory. Added new using directives for Flow.Launcher.Plugin.SharedCommands where necessary.
Flow.Launcher.Plugin/SharedCommands/FilesFolders.cs Introduced two new public static methods: ValidateDirectory for checking and creating a directory, and ValidateDataDirectory for synchronizing files between bundled and data directories.

Sequence Diagram(s)

sequenceDiagram
    participant Caller as Caller (Storage/Plugin)
    participant FF as FilesFolders
    Caller->>FF: ValidateDirectory(directoryPath)
    alt Directory exists
        FF-->>Caller: Directory exists
    else Directory missing
        FF->>System: Directory.CreateDirectory(directoryPath)
        FF-->>Caller: Directory created
    end
Loading
sequenceDiagram
    participant Caller as Plugin/Main
    participant FF as FilesFolders
    Caller->>FF: ValidateDataDirectory(bundledDataDir, dataDir)
    FF->>System: Check if dataDir exists
    alt Data directory missing
        FF->>System: Create dataDir
    end
    FF->>System: For each file in bundledDataDir
    alt File missing or outdated
        FF->>System: Copy/overwrite file to dataDir
    end
    FF-->>Caller: Data directory synchronized
Loading

Suggested labels

enhancement, Dev branch only

Suggested reviewers

  • jjw24
  • taooceros
  • onesounds

Poem

Hop along the code line by line,
A little change that makes it shine.
With Helpers gone and FilesFolders in sight,
Our directories now feel just right.
I'm a bunny of code, so light and free,
Celebrating changes with a joyful spree! 🐰


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3b43d45 and 44ba60c.

📒 Files selected for processing (9)
  • Flow.Launcher.Core/Updater.cs (3 hunks)
  • Flow.Launcher.Infrastructure/Helper.cs (0 hunks)
  • Flow.Launcher.Infrastructure/Storage/BinaryStorage.cs (2 hunks)
  • Flow.Launcher.Infrastructure/Storage/FlowLauncherJsonStorage.cs (2 hunks)
  • Flow.Launcher.Infrastructure/Storage/JsonStorage.cs (2 hunks)
  • Flow.Launcher.Infrastructure/Storage/PluginJsonStorage.cs (2 hunks)
  • Flow.Launcher.Plugin/SharedCommands/FilesFolders.cs (1 hunks)
  • Plugins/Flow.Launcher.Plugin.Program/Main.cs (2 hunks)
  • Plugins/Flow.Launcher.Plugin.WebSearch/Main.cs (1 hunks)
💤 Files with no reviewable changes (1)
  • Flow.Launcher.Infrastructure/Helper.cs
🧰 Additional context used
🧬 Code Definitions (5)
Flow.Launcher.Infrastructure/Storage/JsonStorage.cs (1)
Flow.Launcher.Plugin/SharedCommands/FilesFolders.cs (2)
  • FilesFolders (14-367)
  • ValidateDirectory (326-332)
Flow.Launcher.Infrastructure/Storage/FlowLauncherJsonStorage.cs (1)
Flow.Launcher.Plugin/SharedCommands/FilesFolders.cs (2)
  • FilesFolders (14-367)
  • ValidateDirectory (326-332)
Flow.Launcher.Core/Updater.cs (1)
Flow.Launcher.Infrastructure/Helper.cs (1)
  • T (12-22)
Plugins/Flow.Launcher.Plugin.WebSearch/Main.cs (1)
Flow.Launcher.Plugin/SharedCommands/FilesFolders.cs (2)
  • FilesFolders (14-367)
  • ValidateDataDirectory (340-366)
Flow.Launcher.Infrastructure/Storage/BinaryStorage.cs (1)
Flow.Launcher.Plugin/SharedCommands/FilesFolders.cs (2)
  • FilesFolders (14-367)
  • ValidateDirectory (326-332)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: gitStream.cm
🔇 Additional comments (13)
Flow.Launcher.Infrastructure/Storage/JsonStorage.cs (1)

8-8: Implementation change from Helper to FilesFolders.

The change correctly implements the new dependency on FilesFolders and updates the validation call, aligning with the PR objectives to move these validation functions to a more appropriate location.

Also applies to: 41-41

Flow.Launcher.Infrastructure/Storage/BinaryStorage.cs (1)

5-5: Implementation change from Helper to FilesFolders.

The change correctly implements the new dependency on FilesFolders and updates the validation call, following the same pattern as other storage classes.

Also applies to: 25-25

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

15-15: Implementation change from Helper to FilesFolders.

The change correctly implements the new dependency on FilesFolders and updates the directory validation call, which is consistent with the PR's goal of relocating these functions.

Also applies to: 194-194

Flow.Launcher.Core/Updater.cs (3)

20-20: Added dependency for JsonSerializer.

The addition of the System.Text.Json namespace is needed for the new Formatted method implementation.


55-55: Updated method call to use the new Formatted method.

The log statement has been properly updated to use the local Formatted method instead of calling an external Helper method.


156-164: Added Formatted method to replace the Helper.Formatted method.

The implementation correctly moves the JSON formatting functionality from Helper class to Updater class as specified in the PR objectives. The method uses standard JsonSerializer with indented output for better readability.

Two improvements to consider:

  1. The method is generic, making it more versatile than a non-generic version
  2. Since it's only used within this class, making it private is appropriate for encapsulation
Flow.Launcher.Infrastructure/Storage/FlowLauncherJsonStorage.cs (2)

3-3: Added appropriate namespace for FilesFolders.

The addition of the Flow.Launcher.Plugin.SharedCommands namespace provides access to the FilesFolders class where the ValidateDirectory method has been relocated.


12-12: Updated method call to relocated function.

The code now correctly calls FilesFolders.ValidateDirectory() instead of Helper.ValidateDirectory(), aligning with the PR objective of relocating validation functions to a more appropriate location.

Flow.Launcher.Infrastructure/Storage/PluginJsonStorage.cs (2)

3-3: Added appropriate namespace for FilesFolders.

The addition of the Flow.Launcher.Plugin.SharedCommands namespace provides access to the FilesFolders class where the ValidateDirectory method has been relocated.


18-18: Updated method call to relocated function.

The code now correctly calls FilesFolders.ValidateDirectory() instead of Helper.ValidateDirectory(), aligning with the PR objective of relocating validation functions to a more appropriate location.

Plugins/Flow.Launcher.Plugin.WebSearch/Main.cs (1)

182-182: Updated method call to relocated function.

The code now correctly calls FilesFolders.ValidateDataDirectory() instead of Helper.ValidateDataDirectory(), aligning with the PR objective of relocating validation functions to a more appropriate location.

Flow.Launcher.Plugin/SharedCommands/FilesFolders.cs (2)

322-332: Well-documented ValidateDirectory method.

The implementation is clean and properly documented with XML comments. This method appropriately checks if a directory exists and creates it if needed, which aligns with its intended purpose of validating directories.


334-366: Well-implemented ValidateDataDirectory method.

The implementation is thorough and properly documented. The method correctly:

  1. Validates the data directory exists, creating it if needed
  2. Iterates through files in the bundled directory
  3. Handles null filenames
  4. Copies missing files
  5. Updates files with different timestamps

This implementation preserves the functionality while relocating it to a more appropriate class, meeting the PR objectives.

✨ 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.

@Jack251970 Jack251970 changed the title Cleanup Helper.cs in Flow.Launcher.Infrastructure project New API Function ValidateDirectory and ValidateDataDirectory & Cleanup Helper.cs in Flow.Launcher.Infrastructure project Apr 3, 2025
@Jack251970 Jack251970 requested review from Yusyuriv and onesounds April 3, 2025 11:26
@Jack251970
Copy link
Member Author

I think it is good to merge since it only provide more useful static functions.

@Jack251970 Jack251970 merged commit 3771d64 into Flow-Launcher:dev Apr 4, 2025
8 checks passed
@Jack251970 Jack251970 added the enhancement New feature or request label Apr 4, 2025
@Jack251970 Jack251970 added this to the 1.20.0 milestone Apr 4, 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