Skip to content

New API Function from Theme & Improve Theme Model #3420

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 18 commits into from
Apr 8, 2025

Conversation

Jack251970
Copy link
Contributor

@Jack251970 Jack251970 commented Apr 4, 2025

New API Functions from Theme

Add new api functions to support plugin get available themes, get current theme and set current theme.

Improve SettingsPaneThemePage and Sys plugin with those api functions.

/// <summary>
/// Get all available themes
/// </summary>
/// <returns></returns>
public List<ThemeData> GetAvailableThemes();

/// <summary>
/// Get the current theme
/// </summary>
/// <returns></returns>
public ThemeData GetCurrentTheme();

/// <summary>
/// Set the current theme
/// </summary>
/// <param name="theme"></param>
/// <returns></returns>
public void SetCurrentTheme(ThemeData theme);

Test

  • SettingsPaneThemePage and Sys plugin can get current theme and set current theme.

@prlabeler prlabeler bot added the enhancement New feature or request label Apr 4, 2025

This comment has been minimized.

@Jack251970 Jack251970 changed the title New API Function Theme Load & Get & Change New API Function from Theme Apr 4, 2025
Copy link

gitstream-cm bot commented Apr 4, 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 a review from Copilot April 4, 2025 12:16

This comment has been minimized.

Copy link
Contributor

coderabbitai bot commented Apr 4, 2025

📝 Walkthrough

Walkthrough

This pull request refactors and centralizes theme management across the application. It removes the old string-based theme retrieval in favor of a new system that uses a dedicated ThemeData model. API methods for retrieving available themes, getting the current theme, and setting a new theme have been added to both the core and plugin interfaces. The UI components have been updated to call these new APIs, streamlining the process and eliminating redundant state management.

Changes

File(s) Change Summary
Flow.Launcher.Core/Resource/Theme.cs
Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs
Flow.Launcher/PublicAPIInstance.cs
Refactored theme management API: Renamed LoadAvailableThemes to GetAvailableThemes, replaced the string-based GetCurrentTheme with one returning ThemeData, and added SetCurrentTheme to centralize theme handling.
Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs
Plugins/Flow.Launcher.Plugin.Sys/ThemeSelector.cs
Updated UI and plugin logic: Switched from using local theme state (i.e. Theme.ThemeData) to the centralized ThemeData via the API, adjusted method signatures, and removed redundant UI refresh calls.
Flow.Launcher.Plugin/SharedModels/ThemeData.cs Introduced the new ThemeData class: Encapsulates theme properties (file name, name, dark mode, and blur support) along with constructors, equality operators, and method overrides.

Possibly related PRs

Suggested labels

kind/ui

Suggested reviewers

  • jjw24
  • onesounds

Poem

I'm a rabbit in this codey glade,
Hopping through themes in a digital parade,
With ThemeData shining like a star so bright,
API calls make my future feel just right,
Carrots and code—what a delightful sight!
🐇🥕

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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

@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 6 out of 6 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

Flow.Launcher.Plugin/ThemeData.cs:11

  • The comment for the property 'IsDark' (appearing below) incorrectly uses 'Theme file path'. Consider changing it to something like 'Indicates whether the theme is dark' for clarity.
/// Theme file name without extension

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 (2)
Flow.Launcher/PublicAPIInstance.cs (1)

360-368: Clean implementation of theme-related API methods

The implementations of the theme-related API methods are concise and follow good delegation patterns:

  1. GetAvailableThemes() and GetCurrentTheme() directly delegate to the Theme service
  2. SetCurrentTheme(ThemeData theme) appropriately calls theme change logic and refreshes the UI asynchronously

The use of the _ discard for the Task returned by RefreshFrameAsync() indicates that you're not awaiting the operation, which might be intentional, but could potentially lead to race conditions if multiple theme changes occur in quick succession.

Consider using await with Task.Run(() => _theme.RefreshFrameAsync()) to prevent potential UI thread blocking while ensuring the operation completes, or add a comment explaining why the result is discarded.

Flow.Launcher.Plugin/ThemeData.cs (1)

1-39: Well-structured theme data model with proper encapsulation

The ThemeData class is a well-designed model with proper XML documentation and encapsulation through private init-only properties. The constructor parameters align with the property names, making the code more readable.

There's a minor issue with the documentation for the IsDark and HasBlur properties - both have the same XML comment "Theme file path" which is incorrect. They should describe these boolean properties properly.

Correct the XML documentation for the IsDark and HasBlur properties to properly describe their purpose, e.g., "Indicates whether the theme is dark" and "Indicates whether the theme has blur effects".

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 67cc1e2 and 1611ad3.

📒 Files selected for processing (6)
  • Flow.Launcher.Core/Resource/Theme.cs (6 hunks)
  • Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs (1 hunks)
  • Flow.Launcher.Plugin/ThemeData.cs (1 hunks)
  • Flow.Launcher/PublicAPIInstance.cs (2 hunks)
  • Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs (1 hunks)
  • Plugins/Flow.Launcher.Plugin.Sys/ThemeSelector.cs (2 hunks)
🧰 Additional context used
🧬 Code Definitions (4)
Flow.Launcher.Plugin/ThemeData.cs (3)
Flow.Launcher/PublicAPIInstance.cs (1)
  • ThemeData (362-362)
Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs (1)
  • ThemeData (358-358)
Flow.Launcher.Core/Resource/Theme.cs (2)
  • ThemeData (331-363)
  • ThemeData (383-387)
Flow.Launcher/PublicAPIInstance.cs (3)
Flow.Launcher.Core/Resource/Theme.cs (6)
  • Theme (23-902)
  • Theme (51-78)
  • List (389-402)
  • ThemeData (331-363)
  • ThemeData (383-387)
  • ChangeTheme (404-455)
Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs (4)
  • List (141-141)
  • List (352-352)
  • ThemeData (358-358)
  • SetCurrentTheme (365-365)
Flow.Launcher.Plugin/ThemeData.cs (2)
  • ThemeData (8-73)
  • ThemeData (33-39)
Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs (3)
Flow.Launcher/PublicAPIInstance.cs (4)
  • List (175-175)
  • List (360-360)
  • ThemeData (362-362)
  • SetCurrentTheme (364-368)
Flow.Launcher.Core/Resource/Theme.cs (3)
  • List (389-402)
  • ThemeData (331-363)
  • ThemeData (383-387)
Flow.Launcher.Plugin/ThemeData.cs (2)
  • ThemeData (8-73)
  • ThemeData (33-39)
Plugins/Flow.Launcher.Plugin.Sys/ThemeSelector.cs (1)
Flow.Launcher.Core/Resource/Theme.cs (2)
  • ThemeData (331-363)
  • ThemeData (383-387)
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
🔇 Additional comments (20)
Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs (1)

347-365: API enhancement with theme management capabilities

The addition of these three theme-related methods to the IPublicAPI interface is a well-structured enhancement that centralizes theme management operations. The methods are properly documented with XML comments and provide a comprehensive set of operations for theme management: retrieving available themes, getting the current theme, and setting a new theme.

These methods will allow plugins to interact with the theme system in a type-safe manner using the ThemeData class, which is a good improvement over string-based theme handling.

Flow.Launcher/PublicAPIInstance.cs (1)

40-41: Good use of lazy initialization with dependency injection

The implementation uses proper lazy initialization for the Theme property, ensuring the Theme service is only retrieved from the DI container when needed. This is a good practice for managing dependencies and improving performance.

Flow.Launcher.Plugin/ThemeData.cs (3)

41-51: Correct implementation of equality operators

The equality operators are properly implemented, with == delegating to the Equals method and != defined as the logical negation of ==, which is the correct pattern.


53-66: Proper implementation of equality and hash code methods

The Equals and GetHashCode methods are correctly implemented to consider only the FileNameWithoutExtension and Name properties for equality comparison. This follows best practices for implementing equality in C#.


68-72: Simple and effective ToString implementation

The ToString method is appropriately overridden to return the Name property, which is a reasonable string representation for a theme.

Flow.Launcher.Core/Resource/Theme.cs (7)

125-126: Direct access to settings instead of method call

The code now directly accesses _settings.Theme instead of using a method call, which simplifies the code and reduces an extra function call. Good refactoring.


328-329: Simplified theme retrieval in GetCurrentResourceDictionary

Similar to the previous change, the method now directly accesses _settings.Theme which improves code clarity and performance by eliminating an unnecessary method call.


381-387: New GetCurrentTheme method returns a ThemeData object

This method is part of the new theme management API, returning the current theme as a ThemeData object. It appropriately fallbacks to the first available theme if the current theme setting isn't found, providing good error resilience.


389-402: Renamed method with consistent return type

The method was renamed from LoadAvailableThemes to GetAvailableThemes, which better reflects its purpose as a retrieval method rather than a loading method. The implementation remains sound, filtering out base theme files and ordering themes by name for a better user experience.


407-408: Direct access to settings in ChangeTheme method

Similar to previous changes, this directly accesses _settings.Theme instead of using a method call, maintaining consistency with other refactored parts of the code.


595-596: Direct access to settings in RefreshFrameAsync

Another consistent change to directly access _settings.Theme in the SetBlurForWindow method call within the RefreshFrameAsync method.


614-615: Direct access to settings in SetBlurForWindowAsync

Consistent with other changes, this directly passes _settings.Theme to SetBlurForWindow instead of using a method call.

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

19-21: Adoption of centralized API for theme management

The code has been refactored to use the centralized API methods for retrieving theme information instead of maintaining a local state. This is a good improvement for consistency across the application.


25-25: Proper handling of theme selection

The code now correctly passes both the theme and selected theme to the CreateThemeResult method, allowing for proper comparison and styling of the selected theme.


30-34: Improved search implementation with new API

The fuzzy search implementation now works with the new theme data structure, maintaining the same functionality while leveraging the centralized API.


79-82: Simplified theme selection through API

The action now uses the centralized API to set the current theme, which is more maintainable and consistent with the rest of the application.


37-39:

❓ Verification inconclusive

Verify ThemeData equality comparison

The CreateThemeResult method signature has been updated to work with ThemeData objects. However, the comparison at line 43 (theme == selectedTheme) relies on proper equality comparison.


🏁 Script executed:

#!/bin/bash
# Check if ThemeData class overrides equality comparison
rg -A 10 "class ThemeData" --type csharp

Length of output: 689


Review Verification – ThemeData Equality Check

After reviewing Flow.Launcher.Plugin/ThemeData.cs, it appears that the ThemeData class does not override the default equality members (i.e., there’s no custom implementation of Equals, GetHashCode, or overloading of the == operator). As a result, the expression theme == selectedTheme in ThemeSelector.cs (line 43) performs a reference equality check.

  • Action Required: Please verify that reference equality is the intended behavior. If you require a value-based comparison (for example, comparing based on FileNameWithoutExtension and Name), update ThemeData to implement the necessary equality overrides.
Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs (3)

31-32: Centralized theme data retrieval

The code now retrieves available themes through the centralized API rather than directly accessing the theme manager. This is a good improvement for maintainability and consistency.


40-42:

✅ Verification successful

Verify UI refresh after theme change

The code now calls App.API.SetCurrentTheme(value) but no longer explicitly calls _theme.RefreshFrameAsync(). Ensure the API method internally handles UI refresh.


🏁 Script executed:

#!/bin/bash
# Check SetCurrentTheme implementation for UI refresh calls
rg -A 15 "SetCurrentTheme.*ThemeData" --type csharp

Length of output: 1339


Confirmation: The API now handles UI refresh internally
The implementation of App.API.SetCurrentTheme(value) in Flow.Launcher/PublicAPIInstance.cs calls _theme.RefreshFrameAsync(), which confirms that the UI refresh after a theme change is handled internally. No further explicit call is necessary in the settings page.


34-38:

✅ Verification successful

Consider potential ThemeData comparison issue

The Find method uses v => v == App.API.GetCurrentTheme() to find the current theme. If ThemeData is a reference type without proper equality overrides, this comparison might not work correctly.


🏁 Script executed:

#!/bin/bash
# Check implementation of ThemeData equality
rg -B 5 -A 15 "Equals.*override" --type csharp --glob "*ThemeData.cs"

# Alternative check for operator overloading
rg -B 5 -A 15 "operator ==" --type csharp --glob "*ThemeData.cs"

Length of output: 1326


ThemeData equality comparison verified
After reviewing the implementation in Flow.Launcher.Plugin/ThemeData.cs, it’s confirmed that the operator == and the overridden Equals method are properly implemented. This makes the comparison in Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs (lines 34-38) valid and safe.

Jack251970 and others added 2 commits April 4, 2025 20:23
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@Jack251970 Jack251970 requested a review from Copilot April 4, 2025 12:23

This comment has been minimized.

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 6 out of 6 changed files in this pull request and generated no comments.

This comment has been minimized.

@Jack251970 Jack251970 requested a review from Copilot April 4, 2025 12:33
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 6 out of 6 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (2)

Plugins/Flow.Launcher.Plugin.Sys/ThemeSelector.cs:41

  • [nitpick] Consider using theme.Name instead of FileNameWithoutExtension for display consistency, as the UI later appends a star to theme.Name. Align both the displayed and identifier properties to avoid potential confusion.
var themeName = theme.FileNameWithoutExtension;

Flow.Launcher/Core/Resource/Theme.cs:125

  • [nitpick] For consistent theme retrieval logic, consider calling GetCurrentTheme() instead of directly accessing _settings.Theme. This centralizes the current theme logic and reduces potential inconsistencies if the retrieval logic changes in the future.
var themeName = _settings.Theme;

This comment has been minimized.

@Jack251970 Jack251970 requested a review from taooceros April 4, 2025 12:48

This comment has been minimized.

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 (2)
Flow.Launcher/PublicAPIInstance.cs (1)

365-369: Consider using the property for consistency when refreshing the UI.

While the implementation works correctly, consider using the Theme property instead of directly accessing the _theme field when calling RefreshFrameAsync(). This would maintain consistency with how the other methods access the theme service and protect against potential null reference issues.

public void SetCurrentTheme(ThemeData theme)
{
    Theme.ChangeTheme(theme.FileNameWithoutExtension);
-    _ = _theme.RefreshFrameAsync();
+    _ = Theme.RefreshFrameAsync();
}
Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs (1)

360-366: Remove unnecessary returns tag in documentation.

The XML documentation includes a <returns></returns> tag, but since the method returns void, this tag is unnecessary and should be removed.

/// <summary>
/// Set the current theme
/// </summary>
/// <param name="theme"></param>
-/// <returns></returns>
public void SetCurrentTheme(ThemeData theme);
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2e885ea and 0c0461d.

📒 Files selected for processing (2)
  • Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs (1 hunks)
  • Flow.Launcher/PublicAPIInstance.cs (2 hunks)
🧰 Additional context used
🧬 Code Definitions (2)
Flow.Launcher/PublicAPIInstance.cs (3)
Flow.Launcher.Core/Resource/Theme.cs (6)
  • Theme (23-902)
  • Theme (51-78)
  • List (389-402)
  • ThemeData (331-363)
  • ThemeData (383-387)
  • ChangeTheme (404-455)
Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs (4)
  • List (141-141)
  • List (352-352)
  • ThemeData (358-358)
  • SetCurrentTheme (365-365)
Flow.Launcher.Plugin/ThemeData.cs (2)
  • ThemeData (8-73)
  • ThemeData (33-39)
Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs (1)
Flow.Launcher/PublicAPIInstance.cs (4)
  • List (176-176)
  • List (361-361)
  • ThemeData (363-363)
  • SetCurrentTheme (365-369)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: gitStream.cm
🔇 Additional comments (4)
Flow.Launcher/PublicAPIInstance.cs (2)

41-42: Good implementation of lazy initialization with dependency injection.

The Theme property is well-implemented using the null-coalescing assignment operator (??=) to ensure the service is only requested from the IoC container when needed and then cached for future use.


361-364: LGTM! Clean implementation of theme retrieval methods.

These methods provide a clean interface for accessing theme data by delegating to the underlying Theme service.

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

348-353: LGTM! New API method for retrieving available themes.

This method enhances the public API by providing access to all available themes, which aligns with the PR objectives.


354-359: LGTM! New API method for retrieving the current theme.

This method provides a clean way to access the current theme data, which is essential for theme management functionality.

Copy link

gitstream-cm bot commented Apr 5, 2025

🥷 Code experts: onesounds

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

See details

Flow.Launcher.Core/Resource/Theme.cs

Activity based on git-commit:

Jack251970 onesounds
APR
MAR 881 additions & 954 deletions 1159 additions & 895 deletions
FEB 64 additions & 28 deletions 333 additions & 17 deletions
JAN 7 additions & 4 deletions
DEC 2 additions & 96 deletions
NOV 2 additions & 2 deletions

Knowledge based on git-blame:
Jack251970: 65%
Yusyuriv: 2%

Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs

Activity based on git-commit:

Jack251970 onesounds
APR 61 additions & 4 deletions
MAR
FEB 38 additions & 28 deletions
JAN 21 additions & 3 deletions
DEC 8 additions & 73 deletions
NOV 84 additions & 1 deletions

Knowledge based on git-blame:
Jack251970: 26%

Flow.Launcher/PublicAPIInstance.cs

Activity based on git-commit:

Jack251970 onesounds
APR 37 additions & 8 deletions
MAR 21 additions & 19 deletions
FEB 28 additions & 11 deletions
JAN 45 additions & 47 deletions
DEC 25 additions & 32 deletions
NOV 16 additions & 0 deletions

Knowledge based on git-blame:
Jack251970: 28%

Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs

Activity based on git-commit:

Jack251970 onesounds
APR
MAR 111 additions & 111 deletions 155 additions & 87 deletions
FEB 2 additions & 21 deletions 2 additions & 0 deletions
JAN 1 additions & 1 deletions
DEC
NOV 2 additions & 2 deletions

Knowledge based on git-blame:
Yusyuriv: 53%
Jack251970: 16%

Plugins/Flow.Launcher.Plugin.Sys/ThemeSelector.cs

Activity based on git-commit:

Jack251970 onesounds
APR
MAR 141 additions & 120 deletions
FEB
JAN
DEC
NOV

Knowledge based on git-blame:
Jack251970: 58%

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

/// <summary>
/// Theme data model
/// </summary>
public class ThemeData
Copy link
Member

Choose a reason for hiding this comment

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

Everything else LGTM, could you move this to SharedModel directory. Any that is just a model of an object class should go into that directory.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

This comment has been minimized.

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 6 out of 6 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs:38

  • [nitpick] Consider comparing themes using their FileNameWithoutExtension (e.g. v.FileNameWithoutExtension == App.API.GetCurrentTheme().FileNameWithoutExtension) to avoid potential ambiguity from relying solely on the overridden equality operator.
get => _selectedTheme ??= Themes.Find(v => v == App.API.GetCurrentTheme());

This comment has been minimized.

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 (2)
Flow.Launcher.Plugin/SharedModels/ThemeData.cs (2)

57-64: Consider implementing IEquatable for better type-safety and performance.

Implementing the IEquatable<ThemeData> interface would provide better type-safety and could improve performance when comparing theme objects, especially when used in collections.

-public class ThemeData
+public class ThemeData : IEquatable<ThemeData>
 {
     // existing code...

     /// <inheritdoc />
     public override bool Equals(object obj)
     {
         if (obj is not ThemeData other)
             return false;
         return FileNameWithoutExtension == other.FileNameWithoutExtension &&
             Name == other.Name;
     }
+
+    /// <summary>
+    /// Determines whether the specified theme is equal to the current theme.
+    /// </summary>
+    public bool Equals(ThemeData other)
+    {
+        if (other is null)
+            return false;
+        return FileNameWithoutExtension == other.FileNameWithoutExtension &&
+            Name == other.Name;
+    }

33-39: Add parameter validation in the constructor.

Consider adding validation for fileNameWithoutExtension and name parameters to ensure they're not null or empty strings, as these are essential for theme identification.

 public ThemeData(string fileNameWithoutExtension, string name, bool? isDark = null, bool? hasBlur = null)
 {
+    if (string.IsNullOrEmpty(fileNameWithoutExtension))
+        throw new ArgumentException("File name cannot be null or empty", nameof(fileNameWithoutExtension));
+    if (string.IsNullOrEmpty(name))
+        throw new ArgumentException("Theme name cannot be null or empty", nameof(name));
+
     FileNameWithoutExtension = fileNameWithoutExtension;
     Name = name;
     IsDark = isDark;
     HasBlur = hasBlur;
 }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9052f7b and b3aa897.

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

8-77: Well-structured data model with good encapsulation.

The ThemeData class is well-designed with immutable properties, proper documentation, and correct implementation of equality methods. The fixes for the null reference issues in equality operators from previous reviews have been correctly implemented.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@Jack251970 Jack251970 requested a review from Copilot April 8, 2025 08:20
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 6 out of 6 changed files in this pull request and generated 2 comments.

public void SetCurrentTheme(ThemeData theme)
{
Theme.ChangeTheme(theme.FileNameWithoutExtension);
_ = _theme.RefreshFrameAsync();
Copy link
Preview

Copilot AI Apr 8, 2025

Choose a reason for hiding this comment

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

Consider awaiting RefreshFrameAsync() or properly handling its exceptions to prevent silent failures in theme refresh.

Suggested change
_ = _theme.RefreshFrameAsync();
try
{
await _theme.RefreshFrameAsync();
}
catch (Exception ex)
{
// Log the exception or handle it as needed
Log.Error($"Failed to refresh theme: {ex.Message}");
}

Copilot uses AI. Check for mistakes.

Copy link
Member

Choose a reason for hiding this comment

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

@Jack251970 is this applicable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jjw24 I think we can remove _ = _theme.RefreshFrameAsync(); here since ChangeTheme already calls this function.

Copy link
Contributor Author

@Jack251970 Jack251970 Apr 8, 2025

Choose a reason for hiding this comment

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

For me, changing theme from Appreance Page and Sys plugin still work well

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

@Jack251970 Jack251970 changed the title New API Function from Theme New API Function from Theme & Improve Theme Model Apr 8, 2025
@Jack251970 Jack251970 requested a review from Copilot April 8, 2025 08:45
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 6 out of 6 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (1)

Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs:38

  • [nitpick] The equality check relies on the overridden operator== in ThemeData; ensure that this implementation meets all intended scenarios for comparing themes. If more granular control is needed, consider comparing specific key properties instead.
get => _selectedTheme ??= Themes.Find(v => v == App.API.GetCurrentTheme());

This comment has been minimized.

@Jack251970 Jack251970 requested a review from Copilot April 8, 2025 08:51
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 6 out of 6 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs:38

  • [nitpick] The equality check relies on the overloaded operator for ThemeData; for clarity, consider explicitly comparing key properties like FileNameWithoutExtension.
get => _selectedTheme ??= Themes.Find(v => v == App.API.GetCurrentTheme());

@Jack251970
Copy link
Contributor Author

@jjw24 All resolved and I think it is good to go.

@Jack251970 Jack251970 enabled auto-merge April 8, 2025 08:55
@Jack251970 Jack251970 added this to the 1.20.0 milestone Apr 8, 2025
@Jack251970 Jack251970 requested a review from Copilot April 8, 2025 12:10
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 6 out of 6 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (1)

Flow.Launcher/PublicAPIInstance.cs:370

  • Add validation to ensure that the passed 'theme' is not null before calling ChangeTheme, to avoid potential null reference exceptions.
public bool SetCurrentTheme(ThemeData theme) => Theme.ChangeTheme(theme.FileNameWithoutExtension);

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
❌ forbidden-pattern 22
⚠️ 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

🧹 Nitpick comments (1)
Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs (1)

366-373: Good implementation of theme setting with status feedback.

The SetCurrentTheme(ThemeData theme) method properly returns a boolean value to indicate success or failure, which is a best practice compared to void return types for operations that can fail.

Consider expanding the documentation to clarify specific failure scenarios that would result in a false return value, such as invalid theme data, missing theme files, or permission issues.

 /// <summary>
 /// Set the current theme
 /// </summary>
 /// <param name="theme"></param>
 /// <returns>
 /// True if the theme is set successfully, false otherwise.
+/// Failures may occur if the theme is invalid, theme files are missing, or there are permission issues.
 /// </returns>
 public bool SetCurrentTheme(ThemeData theme);
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a3c7be9 and a4c8343.

📒 Files selected for processing (2)
  • Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs (3 hunks)
  • Flow.Launcher/PublicAPIInstance.cs (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • Flow.Launcher/PublicAPIInstance.cs
🔇 Additional comments (3)
Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs (3)

10-11: Appropriate imports for theme-related functionality.

The newly added imports support the theme management functionality being introduced:

  • Flow.Launcher.Plugin.SharedModels contains the ThemeData model used in the new methods
  • JetBrains.Annotations provides utilities like [NotNull] for better code quality

354-358: Well-defined method for retrieving available themes.

The GetAvailableThemes() method aligns with the PR objective to provide an API for retrieving all available themes. The method signature and documentation are clear and straightforward.


360-364: Well-defined method for retrieving the current theme.

The GetCurrentTheme() method aligns with the PR objective to provide an API for retrieving the currently active theme. The method signature and documentation are clear and straightforward.

@Jack251970 Jack251970 merged commit 8cc9f2d into Flow-Launcher:dev Apr 8, 2025
4 checks passed
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