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

Flow Launcher Theme Selector plugin #2448

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

Conversation

Odotocodot
Copy link
Contributor

@Odotocodot Odotocodot commented Nov 30, 2023

A plugin to quickly change the current Flow Launcher theme.

image

If someone has a better suggestion for the default action keyword rather than flowtheme, would love to hear it. Was a bit apprehensive in using theme 🤷‍♂️ .

Summary by CodeRabbit

  • New Features

    • Introduced a new command to set the Flow Launcher theme.
    • Added functionality to manage and select themes based on user input.
  • Enhancements

    • Updated descriptions for the new theme command in the English language file for better clarity.

@jjw24
Copy link
Member

jjw24 commented Nov 30, 2023

Great idea. I think this plugin would be best served by publishing to the Store. We can have a look at exposing the needed methods via the API.

@taooceros
Copy link
Member

Great idea. I think this plugin would be best served by publishing to the Store. We can have a look at exposing the needed methods via the API.

I feel like we can allow this plugin to be built in. Thememanager is pretty internal.

@jjw24
Copy link
Member

jjw24 commented Nov 30, 2023

Well yes and no, it's directly referencing the core project, ideal design is to have even the default plugins as self contained.

@taooceros
Copy link
Member

Well yes and no, it's directly referencing the core project, ideal design is to have even the default plugins as self contained.

Some of our internal stuff uses the plugin interface for receiving query, which I think is a pretty good idea. I am not sure whether exposing everything to the interface is a very good idea. PublicAPI sometimes can be the curse as we may want to maintain backward compatibility.

@jjw24
Copy link
Member

jjw24 commented Mar 28, 2024

Well I think at least this functionality is a good one to enable plugins to use. Remember the more plugins we pack the more we need to maintain and the bigger the size eventually get. More ideal to encourage plugin development.

@taooceros
Copy link
Member

Well I think at least this functionality is a good one to enable plugins to use. Remember the more plugins we pack the more we need to maintain and the bigger the size eventually get. More ideal to encourage plugin development.

well a plugin only takes 400k size...which should be pretty neglectable. and this feature seems to be good to built in.

@taooceros
Copy link
Member

@Odotocodot isn't you also need to add the plugin folder to the solution?

This comment has been minimized.

@jjw24
Copy link
Member

jjw24 commented Apr 6, 2024

Well I think at least this functionality is a good one to enable plugins to use. Remember the more plugins we pack the more we need to maintain and the bigger the size eventually get. More ideal to encourage plugin development.

well a plugin only takes 400k size...which should be pretty neglectable. and this feature seems to be good to built in.

What about putting this functionality in the Sys plugin since it has flow related functionalities like open log file and reload data etc.

@Odotocodot
Copy link
Contributor Author

Sorry ive been busy with uni!

Well I think at least this functionality is a good one to enable plugins to use. Remember the more plugins we pack the more we need to maintain and the bigger the size eventually get. More ideal to encourage plugin development.

well a plugin only takes 400k size...which should be pretty neglectable. and this feature seems to be good to built in.

What about putting this functionality in the Sys plugin since it has flow related functionalities like open log file and reload data etc.

So move to be inside the sys plugin?

@Odotocodot isn't you also need to add the plugin folder to the solution?

Im not sure its needed? or im confused... its be a while

@jjw24
Copy link
Member

jjw24 commented May 17, 2024

So move to be inside the sys plugin?

I would say ideally exposing the methods via the plugin API would be the best so people can build plugin around it, but this change can be complicated, so putting it in the Sys plugin is the next best option.

@Odotocodot
Copy link
Contributor Author

I've moved the theme selector plugin into the sys plugin now, though I have only done the english translation.

Copy link
Contributor

coderabbitai bot commented Jun 17, 2024

Walkthrough

Walkthrough

The updates enhance the Flow.Launcher.Plugin.Sys by integrating theme management capabilities. Key changes include introducing a ThemeSelector class to manage themes, updating the English language file to reflect new commands, adding a project reference to Flow.Launcher.Core, and implementing IDisposable in the Main class for resource management.

Changes

File Path Change Summary
.../Flow.Launcher.Plugin.Sys.csproj Added project reference to Flow.Launcher.Core.csproj.
.../Languages/en.xaml Added and updated strings for a new command to set the Flow Launcher theme.
.../Main.cs Enhanced Main class to handle querying for themes, added IDisposable interface.
.../ThemeSelector.cs Introduced ThemeSelector class to manage and query themes, implementing IDisposable.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Main
    participant ThemeSelector

    User->>Main: Query for theme change
    Main->>ThemeSelector: Initialize and query themes
    ThemeSelector-->>Main: Returns available themes
    Main-->>User: Displays theme options
    User->>Main: Select a theme
    Main->>ThemeSelector: Apply selected theme
    ThemeSelector-->>Main: Theme applied
    Main-->>User: Confirmation of theme change
Loading

Poem

In the realm of Flow Launcher bright, 🌟
Themes now dance with sheer delight. 🎨
With ThemeSelector, choice is near,
Colors and styles, crystal clear. 🖌️
Dispose of old, welcome new,
Flow shines with each theme's hue. ✨


Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 578ad99 and 7a0be2c.

Files ignored due to path filters (1)
  • Plugins/Flow.Launcher.Plugin.Sys/Images/theme_selector.png is excluded by !**/*.png
Files selected for processing (4)
  • Plugins/Flow.Launcher.Plugin.Sys/Flow.Launcher.Plugin.Sys.csproj (1 hunks)
  • Plugins/Flow.Launcher.Plugin.Sys/Languages/en.xaml (2 hunks)
  • Plugins/Flow.Launcher.Plugin.Sys/Main.cs (6 hunks)
  • Plugins/Flow.Launcher.Plugin.Sys/ThemeSelector.cs (1 hunks)
Files skipped from review due to trivial changes (1)
  • Plugins/Flow.Launcher.Plugin.Sys/Flow.Launcher.Plugin.Sys.csproj
Additional comments not posted (9)
Plugins/Flow.Launcher.Plugin.Sys/ThemeSelector.cs (3)

16-20: Initialization of themeSelector in the constructor looks good. It subscribes to the VisibilityChanged event to reload themes when necessary.


45-51: The event handler OnVisibilityChanged is correctly managing theme loading based on visibility and plugin enabled state.


85-91: Proper cleanup in the Dispose method by unsubscribing from the VisibilityChanged event.

Plugins/Flow.Launcher.Plugin.Sys/Languages/en.xaml (1)

53-53: The description for the theme selector command is clear and concise.

Plugins/Flow.Launcher.Plugin.Sys/Main.cs (5)

21-24: The class now correctly implements multiple interfaces and initializes a new ThemeSelector. Good use of encapsulation and separation of concerns.


62-65: The integration of the theme selector in the Query method is well-implemented. It correctly delegates to the ThemeSelector when the query matches the theme keyword.


437-448: The new command for setting the Flow Launcher theme is well integrated. The action correctly changes the query to initiate theme selection.


465-468: Proper resource management in the Dispose method by disposing of the themeSelector.


[!TIP]
Codebase Verification

The keys used in KeywordTitleMappings are:

  • flowlauncher_plugin_sys_shutdown_computer_cmd
  • flowlauncher_plugin_sys_restart_computer_cmd
  • flowlauncher_plugin_sys_restart_advanced_cmd
  • flowlauncher_plugin_sys_log_off_cmd
  • flowlauncher_plugin_sys_lock_cmd
  • flowlauncher_plugin_sys_sleep_cmd
  • flowlauncher_plugin_sys_hibernate_cmd
  • flowlauncher_plugin_sys_indexoption_cmd
  • flowlauncher_plugin_sys_emptyrecyclebin_cmd
  • flowlauncher_plugin_sys_openrecyclebin_cmd
  • flowlauncher_plugin_sys_exit_cmd
  • flowlauncher_plugin_sys_save_all_settings_cmd
  • flowlauncher_plugin_sys_restart_cmd
  • flowlauncher_plugin_sys_setting_cmd
  • flowlauncher_plugin_sys_reload_plugin_data_cmd
  • flowlauncher_plugin_sys_check_for_update_cmd
  • flowlauncher_plugin_sys_open_log_location_cmd
  • flowlauncher_plugin_sys_open_docs_tips_cmd
  • flowlauncher_plugin_sys_open_userdata_location_cmd
  • flowlauncher_plugin_sys_toggle_game_mode_cmd
  • flowlauncher_plugin_sys_theme_selector_cmd

The keys found in the script output are:

  • flowlauncher_plugin_sys_command
  • flowlauncher_plugin_sys_desc
  • flowlauncher_plugin_sys_shutdown_computer_cmd
  • flowlauncher_plugin_sys_restart_computer_cmd
  • flowlauncher_plugin_sys_restart_advanced_cmd
  • flowlauncher_plugin_sys_log_off_cmd
  • flowlauncher_plugin_sys_lock_cmd
  • flowlauncher_plugin_sys_sleep_cmd
  • flowlauncher_plugin_sys_hibernate_cmd
  • flowlauncher_plugin_sys_indexoption_cmd
  • flowlauncher_plugin_sys_emptyrecyclebin_cmd
  • flowlauncher_plugin_sys_openrecyclebin_cmd
  • flowlauncher_plugin_sys_exit_cmd
  • flowlauncher_plugin_sys_save_all_settings_cmd
  • flowlauncher_plugin_sys_restart_cmd
  • flowlauncher_plugin_sys_setting_cmd
  • flowlauncher_plugin_sys_reload_plugin_data_cmd
  • flowlauncher_plugin_sys_check_for_update_cmd
  • flowlauncher_plugin_sys_open_log_location_cmd
  • flowlauncher_plugin_sys_open_docs_tips_cmd
  • flowlauncher_plugin_sys_open_userdata_location_cmd
  • flowlauncher_plugin_sys_toggle_game_mode_cmd
  • flowlauncher_plugin_sys_theme_selector_cmd

All keys from KeywordTitleMappings are present in the resources file.

Analysis chain

Line range hint 115-137: Initialization in the Init method is comprehensive, setting up keyword mappings and the theme selector. Ensure that all keys used here are defined in the resources file to avoid runtime errors.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that all keys used in KeywordTitleMappings are defined in the resources file.

rg "flowlauncher_plugin_sys_" Plugins/Flow.Launcher.Plugin.Sys/Languages/en.xaml

Length of output: 5904


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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

@check-spelling-bot Report

🔴 Please review

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

❌ Errors Count
❌ ignored-expect-variant 1
⚠️ non-alpha-in-dictionary 13

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

Outside diff range and nitpick comments (3)
Plugins/Flow.Launcher.Plugin.Sys/ThemeSelector.cs (2)

11-11: Consider renaming the constant Keyword to something more specific to avoid potential naming conflicts and increase clarity.


56-83: The methods CreateThemeResult are well implemented and provide a clear way to create result objects. Consider adding XML documentation to these methods to improve code maintainability.

Plugins/Flow.Launcher.Plugin.Sys/Languages/en.xaml (1)

30-30: Ensure the command description aligns with the functionality of setting themes. It might be helpful to specify that this command allows for dynamic theme switching.

Comment on lines +22 to +43
public List<Result> Query(Query query)
{
if (query.IsReQuery)
{
LoadThemes();
}

string search = query.Search[(query.Search.IndexOf(Keyword, StringComparison.Ordinal) + Keyword.Length + 1)..];

if (string.IsNullOrWhiteSpace(search))
{
return themes.Select(CreateThemeResult)
.OrderBy(x => x.Title)
.ToList();
}

return themes.Select(theme => (theme, matchResult: context.API.FuzzySearch(search, theme)))
.Where(x => x.matchResult.IsSearchPrecisionScoreMet())
.Select(x => CreateThemeResult(x.theme, x.matchResult.Score, x.matchResult.MatchData))
.OrderBy(x => x.Title)
.ToList();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The Query method handles theme search effectively. However, consider caching the result of query.Search.IndexOf(Keyword, StringComparison.Ordinal) to avoid recalculating it multiple times.

- string search = query.Search[(query.Search.IndexOf(Keyword, StringComparison.Ordinal) + Keyword.Length + 1)..];
+ int keywordIndex = query.Search.IndexOf(Keyword, StringComparison.Ordinal);
+ string search = query.Search[(keywordIndex + Keyword.Length + 1)..];
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
public List<Result> Query(Query query)
{
if (query.IsReQuery)
{
LoadThemes();
}
string search = query.Search[(query.Search.IndexOf(Keyword, StringComparison.Ordinal) + Keyword.Length + 1)..];
if (string.IsNullOrWhiteSpace(search))
{
return themes.Select(CreateThemeResult)
.OrderBy(x => x.Title)
.ToList();
}
return themes.Select(theme => (theme, matchResult: context.API.FuzzySearch(search, theme)))
.Where(x => x.matchResult.IsSearchPrecisionScoreMet())
.Select(x => CreateThemeResult(x.theme, x.matchResult.Score, x.matchResult.MatchData))
.OrderBy(x => x.Title)
.ToList();
}
public List<Result> Query(Query query)
{
if (query.IsReQuery)
{
LoadThemes();
}
int keywordIndex = query.Search.IndexOf(Keyword, StringComparison.Ordinal);
string search = query.Search[(keywordIndex + Keyword.Length + 1)..];
if (string.IsNullOrWhiteSpace(search))
{
return themes.Select(CreateThemeResult)
.OrderBy(x => x.Title)
.ToList();
}
return themes.Select(theme => (theme, matchResult: context.API.FuzzySearch(search, theme)))
.Where(x => x.matchResult.IsSearchPrecisionScoreMet())
.Select(x => CreateThemeResult(x.theme, x.matchResult.Score, x.matchResult.MatchData))
.OrderBy(x => x.Title)
.ToList();
}

Comment on lines +53 to +54
private void LoadThemes()
=> themes = ThemeManager.Instance.LoadAvailableThemes().Select(Path.GetFileNameWithoutExtension);
Copy link
Contributor

Choose a reason for hiding this comment

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

Tip

Codebase Verification

The LoadAvailableThemes method in Flow.Launcher.Core/Resource/Theme.cs currently does not include any exception handling for cases where the theme directories might not be accessible or other potential issues (e.g., IO exceptions). It would be prudent to add exception handling to ensure robustness.

  • Location: Flow.Launcher.Core/Resource/Theme.cs
  • Method: LoadAvailableThemes
Analysis chain

The method LoadThemes efficiently loads themes using LINQ. Ensure ThemeManager.Instance.LoadAvailableThemes() handles exceptions if the themes directory is not accessible.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Check if ThemeManager handles exceptions during theme loading.

cat Plugins/Flow.Launcher.Plugin.Sys/ThemeManager.cs | grep -A 10 "LoadAvailableThemes"

Length of output: 168



Script:

#!/bin/bash
# Locate the file containing the ThemeManager class
fd ThemeManager.cs

# Once located, inspect the LoadAvailableThemes method
ast-grep --lang cs --pattern 'class ThemeManager { $$$ LoadAvailableThemes() { $$$ } $$$ }'

Length of output: 503



Script:

#!/bin/bash
# Search for the LoadAvailableThemes method in the ThemeManager.cs file
rg 'LoadAvailableThemes' Flow.Launcher.Core/Resource/ThemeManager.cs -A 20

Length of output: 74



Script:

#!/bin/bash
# Search for all method definitions in the ThemeManager.cs file
rg '^\s*(public|private|protected|internal)\s+\w+\s+\w+\s*\(' Flow.Launcher.Core/Resource/ThemeManager.cs

Length of output: 107



Script:

#!/bin/bash
# Search for all method definitions across the entire repository to locate the correct method for loading themes
rg '^\s*(public|private|protected|internal)\s+\w+\s+\w+\s*\('

Length of output: 81184



Script:

#!/bin/bash
# Search for the LoadAvailableThemes method across the entire repository
rg 'LoadAvailableThemes'

Length of output: 431



Script:

#!/bin/bash
# Inspect the LoadAvailableThemes method in Flow.Launcher.Core/Resource/Theme.cs
rg 'LoadAvailableThemes' Flow.Launcher.Core/Resource/Theme.cs -A 20

Length of output: 882

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

Successfully merging this pull request may close these issues.

3 participants