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

Replace original MessageBox with MessageBoxEx & Improve MessageBoxEx display style & Add new public api for using MessageBoxEx #3093

Merged
merged 20 commits into from
Dec 7, 2024

Conversation

Jack251970
Copy link
Contributor

@Jack251970 Jack251970 commented Nov 24, 2024

In #2774, a new message box with dark theme support is introduced.
This PR replaces all System.Windows.MessageBox in Flow.Launcher & Flow.Launcher.Core namespace with the new message box.

Also improve original MessageBoxEx of OK type:
Original:
Screenshot 2024-11-24 162111
Now:
Screenshot 2024-11-24 224420

Move Yes, OK button to the left of No, Cancel button and focus on Yes, OK by default as System.Windows.MessageBox:
Original:
Screenshot 2024-11-24 162121
Now:
Screenshot 2024-11-25 120427

Test already done:

  • All types of MessageBoxEx create & display & interaction.
  • Proxy message box display & interaction in setting proxy panel page: MessageBoxEx.Show(InternationalizationManager.Instance.GetTranslation(message));. (direct call method of MessageBoxEx)
  • Shutdown message box display & interaction in Flow.Launcher.Plugin.Sys: var result = context.API.ShowMsgBox( context.API.GetTranslation("flowlauncher_plugin_sys_dlgtext_shutdown_computer"), context.API.GetTranslation("flowlauncher_plugin_sys_shutdown_computer"),. (api call method of MessageBoxEx)

This comment has been minimized.

Copy link

gitstream-cm bot commented Nov 24, 2024

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 Nov 24, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The changes in this pull request involve a significant update to the message box functionality across various classes in the Flow Launcher application. The standard MessageBox.Show method has been replaced with a custom MessageBoxEx.Show method in multiple locations, enhancing user interaction through a more flexible and consistent message display mechanism. Additionally, new methods have been introduced to the IPublicAPI interface and the PublicAPIInstance class to support various configurations for displaying message boxes, including options for captions, buttons, icons, and default results.

Changes

File Path Change Summary
Flow.Launcher.Core/Configuration/Portable.cs Replaced MessageBox.Show with MessageBoxEx.Show in several methods related to portable mode management.
Flow.Launcher.Core/MessageBoxEx.xaml Updated namespace and restructured UI layout, including button renaming and repositioning.
Flow.Launcher.Core/MessageBoxEx.xaml.cs Implemented MessageBoxEx class with multiple overloads of the Show method for flexible message box displays.
Flow.Launcher.Core/Resource/Internationalization.cs Replaced MessageBox.Show with MessageBoxEx.Show in PromptShouldUsePinyin method.
Flow.Launcher.Core/Resource/Theme.cs Updated error handling in ChangeTheme method to use MessageBoxEx.Show.
Flow.Launcher.Core/Updater.cs Replaced MessageBox.Show with MessageBoxEx.Show in user notifications during the update process.
Flow.Launcher/ActionKeywords.xaml.cs Updated btnDone_OnClick to use MessageBoxEx.Show.
Flow.Launcher/CustomQueryHotkeySetting.xaml.cs Replaced MessageBox with MessageBoxEx for invalid plugin hotkey notifications.
Flow.Launcher/CustomShortcutSetting.xaml.cs Updated error messages related to shortcuts to use MessageBoxEx.Show.
Flow.Launcher/Helper/HotKeyMapper.cs Updated error handling in SetHotkey to use MessageBoxEx.Show.
Flow.Launcher/PriorityChangeWindow.xaml.cs Replaced MessageBox.Show with MessageBoxEx.Show in error messages.
Flow.Launcher/SettingPages/ViewModels/SettingsPaneAboutViewModel.cs Updated AskClearLogFolderConfirmation method to use MessageBoxEx.Show.
Flow.Launcher/SettingPages/ViewModels/SettingsPaneHotkeyViewModel.cs Replaced MessageBox.Show with MessageBoxEx.Show in several methods.
Flow.Launcher/SettingPages/ViewModels/SettingsPaneProxyViewModel.cs Updated OnTestProxyClicked to use MessageBoxEx.Show.
Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs Replaced MessageBox.Show with MessageBoxEx.Show for drop shadow effect notifications.
Flow.Launcher.Core/ExternalPlugins/Environments/AbstractPluginEnvironment.cs Updated Setup method to use MessageBoxEx.Show.
Flow.Launcher.Core/ExternalPlugins/Environments/PythonEnvironment.cs Modified InstallEnvironment to include MessageBoxEx.Show as a parameter.
Flow.Launcher.Core/ExternalPlugins/Environments/TypeScriptEnvironment.cs Updated InstallEnvironment to include MessageBoxEx.Show.
Flow.Launcher.Core/ExternalPlugins/Environments/TypeScriptV2Environment.cs Updated InstallEnvironment to include MessageBoxEx.Show.
Flow.Launcher.Core/Plugin/PluginManager.cs Modified InstallPlugin method to include MessageBoxEx.Show as a parameter.
Flow.Launcher.Core/Plugin/PluginsLoader.cs Replaced MessageBox.Show with MessageBoxEx.Show for error handling.
Flow.Launcher.Plugin/SharedCommands/FilesFolders.cs Enhanced methods to accept a Func<string, MessageBoxResult> parameter for custom message box handling.
Plugins/Flow.Launcher.Plugin.Calculator/Main.cs Updated error handling to use Context.API.ShowMsgBox.
Plugins/Flow.Launcher.Plugin.Explorer/ContextMenu.cs Replaced MessageBox.Show with Context.API.ShowMsgBox.
Plugins/Flow.Launcher.Plugin.Explorer/Search/Everything/EverythingDownloadHelper.cs Updated message box usage to api.ShowMsgBox.
Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs Replaced MessageBox.Show with Context.API.ShowMsgBox.
Plugins/Flow.Launcher.Plugin.Explorer/ViewModels/SettingsViewModel.cs Updated ShowUnselectedMessage to use Context.API.ShowMsgBox.
Plugins/Flow.Launcher.Plugin.Explorer/Views/ActionKeywordSetting.xaml.cs Replaced MessageBox.Show with api.ShowMsgBox.
Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs Updated various methods to use Context.API.ShowMsgBox.
Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs Updated BtnAdd_OnClick to use ViewModel.API.ShowMsgBox.
Plugins/Flow.Launcher.Plugin.Program/ProgramSuffixes.xaml.cs Updated error handling to use context.API.ShowMsgBox.
Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs Updated message box calls to use context.API.ShowMsgBox.
Plugins/Flow.Launcher.Plugin.Sys/Main.cs Replaced System.Windows.MessageBox with context.API.ShowMsgBox.
Plugins/Flow.Launcher.Plugin.WebSearch/SearchSourceSetting.xaml.cs Updated message box calls to use _context.API.ShowMsgBox.
Plugins/Flow.Launcher.Plugin.WebSearch/SearchSourceViewModel.cs Updated error handling to use MessageBoxEx.Show.
Plugins/Flow.Launcher.Plugin.WebSearch/SettingsControl.xaml.cs Updated confirmation dialogs to use _context.API.ShowMsgBox.
Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs Added multiple overloads for ShowMsgBox to the interface.
Flow.Launcher/PublicAPIInstance.cs Added multiple overloads for ShowMsgBox to the class.
Plugins/Flow.Launcher.Plugin.WebSearch/Main.cs Changed _context field from private to internal static.

Suggested labels

bug

Suggested reviewers

  • taooceros

🐰 In the meadow, hopping with glee,
Message boxes now show more clearly!
With MessageBoxEx, the changes are bright,
User prompts shine, oh what a delight!
Error handling's smooth, like a soft bunny's hop,
In the world of Flow Launcher, we just can't stop! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 57cbe10 and 676a5b1.

📒 Files selected for processing (4)
  • Flow.Launcher.Core/MessageBoxEx.xaml.cs (1 hunks)
  • Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs (2 hunks)
  • Plugins/Flow.Launcher.Plugin.WebSearch/Main.cs (1 hunks)
  • Plugins/Flow.Launcher.Plugin.WebSearch/SearchSourceViewModel.cs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs
  • Plugins/Flow.Launcher.Plugin.WebSearch/SearchSourceViewModel.cs
  • Flow.Launcher.Core/MessageBoxEx.xaml.cs
🔇 Additional comments (1)
Plugins/Flow.Launcher.Plugin.WebSearch/Main.cs (1)

16-16: ⚠️ Potential issue

Reconsider making _context static and internal.

The modification of _context to be internal static introduces several concerns:

  1. Thread Safety: Static context shared across instances could lead to race conditions in async operations
  2. Encapsulation: Internal access breaks encapsulation and could create tight coupling with other assemblies
  3. Testability: Static state makes unit testing more difficult
  4. Lifecycle: Static context persists for application lifetime, potentially leading to memory leaks

Consider these alternatives:

-internal static PluginInitContext _context;
+private readonly PluginInitContext _context;

If sharing context is necessary, consider:

  1. Dependency injection
  2. A thread-safe singleton pattern
  3. An event-based communication system

Let's verify the usage pattern that necessitated this change:


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

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

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

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

Other keywords and placeholders

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

CodeRabbit Configuration File (.coderabbit.yaml)

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

Documentation and Community

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

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Outside diff range and nitpick comments (20)
Flow.Launcher/SettingPages/ViewModels/SettingsPaneProxyViewModel.cs (1)

Line range hint 24-52: Consider modernizing the proxy testing implementation.

While the current implementation works, there are several improvements that could enhance the code:

  1. Use HttpClient instead of deprecated HttpWebRequest
  2. Implement async/await pattern to prevent UI blocking
  3. Add timeout configuration to prevent long waits

Here's a suggested modern implementation:

-    [RelayCommand]
-    private void OnTestProxyClicked()
-    {
-        var message = TestProxy();
-        MessageBoxEx.Show(InternationalizationManager.Instance.GetTranslation(message));
-    }
-
-    private string TestProxy()
+    [RelayCommand]
+    private async Task OnTestProxyClickedAsync()
+    {
+        var message = await TestProxyAsync();
+        MessageBoxEx.Show(InternationalizationManager.Instance.GetTranslation(message));
+    }
+
+    private async Task<string> TestProxyAsync()
     {
         if (string.IsNullOrEmpty(Settings.Proxy.Server)) return "serverCantBeEmpty";
         if (Settings.Proxy.Port <= 0) return "portCantBeEmpty";

-        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(_updater.GitHubRepository);
+        using var handler = new HttpClientHandler();
+        var proxy = new WebProxy(Settings.Proxy.Server, Settings.Proxy.Port);
         
-        if (string.IsNullOrEmpty(Settings.Proxy.UserName) || string.IsNullOrEmpty(Settings.Proxy.Password))
-        {
-            request.Proxy = new WebProxy(Settings.Proxy.Server, Settings.Proxy.Port);
-        }
-        else
+        if (!string.IsNullOrEmpty(Settings.Proxy.UserName) && !string.IsNullOrEmpty(Settings.Proxy.Password))
         {
-            request.Proxy = new WebProxy(Settings.Proxy.Server, Settings.Proxy.Port)
-            {
-                Credentials = new NetworkCredential(Settings.Proxy.UserName, Settings.Proxy.Password)
-            };
+            proxy.Credentials = new NetworkCredential(Settings.Proxy.UserName, Settings.Proxy.Password);
         }
+        
+        handler.Proxy = proxy;
+        using var client = new HttpClient(handler) { Timeout = TimeSpan.FromSeconds(10) };

         try
         {
-            var response = (HttpWebResponse)request.GetResponse();
-            return response.StatusCode switch
-            {
-                HttpStatusCode.OK => "proxyIsCorrect",
-                _ => "proxyConnectFailed"
-            };
+            var response = await client.GetAsync(_updater.GitHubRepository);
+            return response.StatusCode == HttpStatusCode.OK ? "proxyIsCorrect" : "proxyConnectFailed";
         }
-        catch
+        catch (Exception)
         {
             return "proxyConnectFailed";
         }
     }
Flow.Launcher/PriorityChangeWindow.xaml.cs (2)

27-27: Consider specifying MessageBoxButton parameter

While the code works, explicitly specifying the MessageBoxButton parameter would improve clarity and maintainability.

-MessageBoxEx.Show(translater.GetTranslation("cannotFindSpecifiedPlugin"));
+MessageBoxEx.Show(translater.GetTranslation("cannotFindSpecifiedPlugin"), MessageBoxButton.OK);

46-48: Simplify message display and specify MessageBoxButton

The code can be simplified by removing the intermediate variable and adding the MessageBoxButton parameter for clarity.

-                string msg = translater.GetTranslation("invalidPriority");
-                MessageBoxEx.Show(msg);
+                MessageBoxEx.Show(translater.GetTranslation("invalidPriority"), MessageBoxButton.OK);
Flow.Launcher/CustomShortcutSetting.xaml.cs (2)

Line range hint 13-15: Consider using consistent string initialization

For consistency, consider using String.Empty for all string initializations. Also, property names could be more descriptive.

-    public string Key { get; set; } = String.Empty;
-    public string Value { get; set; } = String.Empty;
-    private string originalKey { get; } = null;
+    public string ShortcutKey { get; set; } = String.Empty;
+    public string ShortcutValue { get; set; } = String.Empty;
+    private string originalKey { get; } = String.Empty;

Line range hint 71-76: Consider extracting window manipulation logic

The test button click handler directly manipulates the main window multiple times. Consider extracting this logic into a dedicated method in the main window class or a window service.

-    private void BtnTestShortcut_OnClick(object sender, RoutedEventArgs e)
-    {
-        App.API.ChangeQuery(tbExpand.Text);
-        Application.Current.MainWindow.Show();
-        Application.Current.MainWindow.Opacity = 1;
-        Application.Current.MainWindow.Focus();
-    }
+    private void BtnTestShortcut_OnClick(object sender, RoutedEventArgs e)
+    {
+        App.API.ChangeQuery(tbExpand.Text);
+        ShowAndFocusMainWindow();
+    }
+
+    private static void ShowAndFocusMainWindow()
+    {
+        var mainWindow = Application.Current.MainWindow;
+        mainWindow.Show();
+        mainWindow.Opacity = 1;
+        mainWindow.Focus();
+    }
Flow.Launcher/Helper/HotKeyMapper.cs (1)

Line range hint 44-50: Consider enhancing error handling for better user guidance

The current error handling could be improved to:

  1. Log the specific exception for debugging
  2. Provide users with guidance on how to resolve hotkey conflicts

Consider this enhancement:

-        catch (Exception)
+        catch (Exception ex)
         {
+            Log.Error(ex, $"Failed to register hotkey: {hotkeyStr}");
             string errorMsg = string.Format(InternationalizationManager.Instance.GetTranslation("registerHotkeyFailed"), hotkeyStr);
+            errorMsg += Environment.NewLine + InternationalizationManager.Instance.GetTranslation("hotkeyResolutionHint");
             string errorMsgTitle = InternationalizationManager.Instance.GetTranslation("MessageBoxTitle");
             MessageBoxEx.Show(errorMsg, errorMsgTitle);
         }
Flow.Launcher.Core/Updater.cs (3)

20-20: Optimize usage of static import

The static import of MessageBoxEx is not being fully utilized since the code still uses the fully qualified MessageBoxEx.Show. Consider either removing the static import or updating the calls to use just Show().

- using static Flow.Launcher.Core.MessageBoxEx;

57-57: Specify MessageBoxType for clarity

Consider explicitly specifying the message box type for consistent visual appearance across the application.

- MessageBoxEx.Show(api.GetTranslation("update_flowlauncher_already_on_latest"));
+ MessageBoxEx.Show(api.GetTranslation("update_flowlauncher_already_on_latest"), string.Empty, MessageBoxType.Information);

Line range hint 41-97: Consider standardizing notification approach

The class currently mixes two different approaches for user notifications:

  1. api.ShowMsg() for progress updates
  2. MessageBoxEx.Show() for user interactions

Consider standardizing the notification approach for better consistency:

  • Use MessageBoxEx for user interactions requiring responses
  • Use api.ShowMsg for progress/status updates only
Flow.Launcher.Core/MessageBoxEx.xaml (1)

Line range hint 40-62: Consider adding accessibility improvements to the close button

While the close button implementation is solid, consider these accessibility enhancements:

 <Button
     Grid.Column="1"
     Click="Button_Cancel"
+    ToolTip="Close"
+    AutomationProperties.Name="Close"
     Style="{StaticResource TitleBarCloseButtonStyle}">
Flow.Launcher.Core/MessageBoxEx.xaml.cs (1)

Line range hint 36-36: Consider thread-safety improvements for static msgBox field.

The static msgBox field could cause issues in multi-window scenarios where multiple message boxes might be shown simultaneously. Consider:

  1. Making the field instance-based instead of static
  2. Adding thread synchronization if static field must be maintained
Flow.Launcher.Core/Resource/Internationalization.cs (1)

14-14: Consider using a regular import instead of a static import.

While the static import works, using a regular import (using Flow.Launcher.Core) would make it more explicit where MessageBoxEx comes from, improving code readability.

-using static Flow.Launcher.Core.MessageBoxEx;
+using Flow.Launcher.Core;
Flow.Launcher.Core/Configuration/Portable.cs (4)

44-45: Consider specifying MessageBoxType explicitly

While the default OK button is appropriate here, it's better to be explicit about the MessageBoxType for clarity and maintainability.

-                MessageBoxEx.Show("Flow Launcher needs to restart to finish disabling portable mode, " +
-                    "after the restart your portable data profile will be deleted and roaming data profile kept");
+                MessageBoxEx.Show("Flow Launcher needs to restart to finish disabling portable mode, " +
+                    "after the restart your portable data profile will be deleted and roaming data profile kept",
+                    string.Empty, MessageBoxType.OK);

68-69: Consider specifying MessageBoxType explicitly

For consistency with the previous suggestion and clarity of intent, specify the MessageBoxType explicitly.

-                MessageBoxEx.Show("Flow Launcher needs to restart to finish enabling portable mode, " +
-                    "after the restart your roaming data profile will be deleted and portable data profile kept");
+                MessageBoxEx.Show("Flow Launcher needs to restart to finish enabling portable mode, " +
+                    "after the restart your roaming data profile will be deleted and portable data profile kept",
+                    string.Empty, MessageBoxType.OK);

178-179: Consider specifying MessageBoxType explicitly

For consistency with other message boxes in the file, specify the MessageBoxType explicitly.

-                MessageBoxEx.Show("Flow Launcher has detected you disabled portable mode, " +
-                                    "the relevant shortcuts and uninstaller entry have been created");
+                MessageBoxEx.Show("Flow Launcher has detected you disabled portable mode, " +
+                                    "the relevant shortcuts and uninstaller entry have been created",
+                                    string.Empty, MessageBoxType.OK);

190-192: LGTM with minor enhancement suggestion

The message formatting using string.Format and Environment.NewLine is well done. Consider adding explicit MessageBoxType for consistency.

-                MessageBoxEx.Show(string.Format("Flow Launcher detected your user data exists both in {0} and " +
-                                    "{1}. {2}{2}Please delete {1} in order to proceed. No changes have occurred.", 
-                                    DataLocation.PortableDataPath, DataLocation.RoamingDataPath, Environment.NewLine));
+                MessageBoxEx.Show(string.Format("Flow Launcher detected your user data exists both in {0} and " +
+                                    "{1}. {2}{2}Please delete {1} in order to proceed. No changes have occurred.", 
+                                    DataLocation.PortableDataPath, DataLocation.RoamingDataPath, Environment.NewLine),
+                                    string.Empty, MessageBoxType.OK);
Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs (2)

Line range hint 315-397: Consider refactoring font-related properties to reduce duplication.

The font-related properties (SelectedQueryBoxFont, SelectedResultFont, SelectedResultSubFont) share similar logic for font existence checking and fallback behavior. Consider extracting this common logic into a helper method.

Here's a suggested approach:

+ private FontFamily GetFontFamilyWithFallback(string fontName)
+ {
+     var fontExists = Fonts.SystemFontFamilies.Any(
+         fontFamily =>
+             fontFamily.FamilyNames.Values != null &&
+             fontFamily.FamilyNames.Values.Contains(fontName)
+     );
+     return fontExists ? new FontFamily(fontName) : new FontFamily(DefaultFont);
+ }

  public FontFamily SelectedQueryBoxFont
  {
-     get
-     {
-         var fontExists = Fonts.SystemFontFamilies.Any(
-             fontFamily =>
-                 fontFamily.FamilyNames.Values != null &&
-                 fontFamily.FamilyNames.Values.Contains(Settings.QueryBoxFont)
-         );
-         return fontExists switch
-         {
-             true => new FontFamily(Settings.QueryBoxFont),
-             _ => new FontFamily(DefaultFont)
-         };
-     }
+     get => GetFontFamilyWithFallback(Settings.QueryBoxFont);
      set
      {
          Settings.QueryBoxFont = value.ToString();
          ThemeManager.Instance.ChangeTheme(Settings.Theme);
      }
  }

Line range hint 235-282: Consider improving PreviewResults to be more resilient.

The PreviewResults property uses hardcoded paths for plugin images. Consider:

  1. Adding existence checks for plugin image files
  2. Using dependency injection for plugin paths
  3. Moving the sample results to a configuration file

Example approach for file existence check:

  IcoPath = Path.Combine(
      Constant.ProgramDirectory,
      @"Plugins\Flow.Launcher.Plugin.Explorer\Images\explorer.png"
- )
+ ),
+ IcoPathExists = File.Exists(Path.Combine(
+     Constant.ProgramDirectory,
+     @"Plugins\Flow.Launcher.Plugin.Explorer\Images\explorer.png"
+ ))
Flow.Launcher.Core/Resource/Theme.cs (2)

Line range hint 1-15: Add missing import for MessageBoxEx

The code uses MessageBoxEx but is missing the required import statement.

Add the following import at the top of the file:

using System.Windows.Media.Effects;
+using Flow.Launcher.Infrastructure.UI;
using Flow.Launcher.Infrastructure;

MessageBoxEx is properly initialized, but theme loading tests are missing

Based on the verification results:

  • MessageBoxEx is properly implemented as a Window class in MessageBoxEx.xaml.cs with proper initialization and static Show methods
  • However, there are no dedicated test files or test methods for theme loading functionality, particularly for error scenarios

Recommendations:

  • Add unit tests to verify theme loading error handling:
    • Test DirectoryNotFoundException scenario
    • Test XamlParseException scenario
    • Test fallback to default theme behavior
🔗 Analysis chain

Line range hint 113-124: Verify MessageBoxEx initialization and theme loading tests

While the MessageBox replacements are correct, we should ensure:

  1. MessageBoxEx is properly initialized before being used in these error scenarios
  2. Theme loading functionality has adequate test coverage for these error cases

Let's verify the test coverage:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for theme loading tests
rg -l "ChangeTheme.*DirectoryNotFoundException|XamlParseException" --type-add "test:*.{cs,vb}" -t test

# Check MessageBoxEx initialization
ast-grep --pattern 'class $_ {
  $$$
  MessageBoxEx.$$$
  $$$
}'

Length of output: 208


Script:

#!/bin/bash
# Let's check for test files related to Theme
fd "Theme.*Test.*\.cs$"

# Check for any test methods related to theme loading
rg "Test.*Theme" --type cs -A 5

# Check MessageBoxEx usage and initialization patterns
rg "MessageBoxEx" --type cs -A 2

# Check if there are any existing test utilities for MessageBox
rg "TestMessageBox|MockMessageBox|FakeMessageBox" --type cs

Length of output: 11021

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 9e46d3a and c103244.

📒 Files selected for processing (15)
  • Flow.Launcher.Core/Configuration/Portable.cs (6 hunks)
  • Flow.Launcher.Core/MessageBoxEx.xaml (4 hunks)
  • Flow.Launcher.Core/MessageBoxEx.xaml.cs (2 hunks)
  • Flow.Launcher.Core/Resource/Internationalization.cs (2 hunks)
  • Flow.Launcher.Core/Resource/Theme.cs (2 hunks)
  • Flow.Launcher.Core/Updater.cs (4 hunks)
  • Flow.Launcher/ActionKeywords.xaml.cs (2 hunks)
  • Flow.Launcher/CustomQueryHotkeySetting.xaml.cs (2 hunks)
  • Flow.Launcher/CustomShortcutSetting.xaml.cs (2 hunks)
  • Flow.Launcher/Helper/HotKeyMapper.cs (2 hunks)
  • Flow.Launcher/PriorityChangeWindow.xaml.cs (3 hunks)
  • Flow.Launcher/SettingPages/ViewModels/SettingsPaneAboutViewModel.cs (1 hunks)
  • Flow.Launcher/SettingPages/ViewModels/SettingsPaneHotkeyViewModel.cs (5 hunks)
  • Flow.Launcher/SettingPages/ViewModels/SettingsPaneProxyViewModel.cs (1 hunks)
  • Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • Flow.Launcher/SettingPages/ViewModels/SettingsPaneAboutViewModel.cs
🔇 Additional comments (29)
Flow.Launcher/ActionKeywords.xaml.cs (2)

5-5: LGTM: Required namespace for MessageBoxEx

The addition of the Flow.Launcher.Core namespace is necessary for using MessageBoxEx.


47-47: Consider adding error icon for better UX

While the MessageBox replacement is correct, consider using MessageBoxEx.Show with an error icon since this is an error notification.

Let's verify the MessageBoxEx.Show signature and usage:

Flow.Launcher/SettingPages/ViewModels/SettingsPaneProxyViewModel.cs (1)

25-25: LGTM! MessageBox replacement aligns with PR objectives.

The replacement of MessageBox.Show with MessageBoxEx.Show is consistent with the PR's goal of standardizing the message box implementation across the application.

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

8-8: LGTM: Required namespace import for MessageBoxEx

The addition of the Flow.Launcher.Core namespace is necessary and properly placed with other related imports.

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

6-6: LGTM: Using directive properly added

The using directive for Flow.Launcher.Core is correctly placed and necessary for MessageBoxEx usage.


46-46: LGTM: MessageBox replacement maintains functionality

The MessageBox.Show replacement with MessageBoxEx.Show maintains the existing error handling logic while supporting the dark theme requirement.


52-52: LGTM: MessageBox replacement maintains functionality

The MessageBox.Show replacement with MessageBoxEx.Show maintains the existing error handling logic while supporting the dark theme requirement.

Flow.Launcher/Helper/HotKeyMapper.cs (2)

8-8: LGTM: Appropriate namespace change

The addition of Flow.Launcher.Core namespace aligns with the PR objective of replacing System.Windows.MessageBox with MessageBoxEx.


49-49: Verify MessageBoxEx parameters and usage pattern

The MessageBox replacement looks correct, maintaining the error handling flow and localization. Let's verify the MessageBoxEx implementation to ensure we're using it as intended.

✅ Verification successful

Let me generate additional verification to check the MessageBoxEx class definition and its Show method signature, as the previous search didn't reveal the class implementation.


MessageBoxEx usage is correct and follows the implementation pattern

The MessageBoxEx.Show usage in HotKeyMapper.cs with two parameters (errorMsg, errorMsgTitle) matches the second overload of the Show method found in Flow.Launcher.Core/MessageBoxEx.xaml.cs. The usage pattern is consistent with other occurrences throughout the codebase, particularly for showing error messages with localized content.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify MessageBoxEx implementation and usage pattern
# Look for MessageBoxEx definition and other usages to confirm parameter pattern

# Find MessageBoxEx class definition
echo "Looking for MessageBoxEx class definition:"
ast-grep --pattern 'class MessageBoxEx {
  $$$
}'

# Find other MessageBoxEx.Show usages for comparison
echo "Looking for other MessageBoxEx.Show usages:"
rg "MessageBoxEx.Show" -A 2

Length of output: 9051


Script:

#!/bin/bash
# Search for MessageBoxEx class and Show method implementation
ast-grep --pattern 'class MessageBoxEx {
  public static $$ Show($$$) {
    $$$
  }
}'

# Also search for MessageBoxType enum since it was referenced in some usages
ast-grep --pattern 'enum MessageBoxType {
  $$$
}'

# Search for any other Show method overloads
rg "static.*Show.*\(" --type cs

Length of output: 1218

Flow.Launcher/CustomQueryHotkeySetting.xaml.cs (2)

9-9: LGTM: Import statement aligns with MessageBoxEx usage

The addition of the Flow.Launcher.Core namespace import is appropriate for accessing the MessageBoxEx functionality.


66-66: Verify MessageBoxEx parameters for error message

The replacement of MessageBox with MessageBoxEx aligns with the PR objectives. However, since this is an error message, we should verify if specific MessageBoxEx parameters (like icon or buttons) should be set to maintain the same user experience.

✅ Verification successful

MessageBoxEx usage is consistent with error message patterns

Looking at the codebase patterns, the simple MessageBoxEx.Show(message) form is consistently used for error notifications and validation messages. Other error messages like "emptyShortcut", "duplicateShortcut", and "cannotFindSpecifiedPlugin" follow the same pattern. Only confirmation dialogs use additional parameters for MessageBoxType.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other error message patterns using MessageBoxEx
rg "MessageBoxEx.Show.*invalidPluginHotkey" -A 2 -B 2

# Look for similar error handling patterns
ast-grep --pattern 'MessageBoxEx.Show($$$)'

Length of output: 7805

Flow.Launcher/SettingPages/ViewModels/SettingsPaneHotkeyViewModel.cs (3)

10-11: LGTM! Clean import of MessageBoxEx

The static import of MessageBoxEx is appropriate and aligns with the PR objective of replacing System.Windows.MessageBox.


46-46: LGTM! Consistent replacement of MessageBox.Show

The MessageBox replacements are consistent and maintain the same functionality while supporting the new theming capabilities.

Also applies to: 71-71, 92-92, 116-116


50-56: Verify MessageBoxType enum compatibility

The change from MessageBoxButton to MessageBoxType looks correct, but let's verify the enum values match to ensure consistent behavior.

Also applies to: 96-101

✅ Verification successful

MessageBoxType and MessageBoxResult usage is consistent and correct

The verification shows that:

  • MessageBoxType.YesNo is correctly mapped to MessageBoxButton.YesNo in MessageBoxEx.xaml.cs
  • All MessageBoxType.YesNo results are properly handled with MessageBoxResult.Yes checks
  • The specific usage in SettingsPaneHotkeyViewModel.cs follows the same pattern as other files in the codebase
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify MessageBoxType enum values match MessageBoxButton values
# and check all possible return values are handled correctly

# Search for MessageBoxType enum definition
ast-grep --pattern 'enum MessageBoxType {
  $$$
}'

# Search for MessageBoxType usage patterns
rg -A 2 'MessageBoxType\.' 

# Search for return value handling
rg 'if.*result.*MessageBoxResult\.'

Length of output: 4340

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

87-87: LGTM! Well-structured message box implementation

This implementation properly handles all necessary parameters (message, title, type) and correctly processes the user's response for the restart decision.

Flow.Launcher.Core/MessageBoxEx.xaml (4)

2-2: LGTM: Namespace changes are consistent

The namespace changes from Flow.Launcher to Flow.Launcher.Core align well with the architectural organization.

Also applies to: 6-6


63-67: LGTM: Grid layout improvements enhance flexibility

The switch from StackPanel to Grid with explicit row definitions provides better layout control and flexibility.


Line range hint 11-13: Ensure theme switching behavior is tested

The message box uses dynamic resources for theming (PopuBGColor, PopupTextColor, PopupButtonAreaBGColor). Consider adding theme switching tests to verify proper appearance in both light and dark themes.


98-115: Verify MaxWidth constraints for different screen sizes

Both text blocks use a MaxWidth of 400, which should be verified across different screen sizes and DPI settings.

✅ Verification successful

MaxWidth constraint is appropriate for this message box implementation

The MaxWidth of 400 for text blocks is well-designed considering:

  • The parent window has a fixed width of 420px
  • Text blocks have right margin of 26px
  • The window is non-resizable (ResizeMode="NoResize")
  • Window is always centered on screen (WindowStartupLocation="CenterScreen")
  • Content height adjusts automatically (SizeToContent="Height")

The MaxWidth constraint ensures text remains within the window bounds while maintaining readability across different content lengths and screen sizes.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other MaxWidth constraints in XAML files for consistency
rg -l "MaxWidth=\"400\"" --type xaml

# Check for any DPI-aware implementations
rg "SystemParameters.(Dpi|PrimaryScreen)" --type xaml

Length of output: 150


Script:

#!/bin/bash
# Search for other MaxWidth constraints in XAML files using regular ripgrep without file type filter
rg -l "MaxWidth=\"400\""

# Check for any DPI-aware implementations
rg "SystemParameters\.(Dpi|PrimaryScreen)"

# Look for any window sizing or screen-related code
rg "(Window\.(Width|Height|Size)|Screen\.(Width|Height|WorkingArea))"

Length of output: 497


Script:

#!/bin/bash
# Check the MessageBoxEx.xaml file content to understand the window layout and sizing
cat Flow.Launcher.Core/MessageBoxEx.xaml

# Look for any responsive design or window sizing related code in MessageBoxEx
rg -g "MessageBoxEx*" "(Width|Height|Size|Screen)"

Length of output: 8473

Flow.Launcher.Core/MessageBoxEx.xaml.cs (3)

40-48: LGTM! Parameter naming improvements enhance readability.

The renaming of parameters from msg/caption to messageBoxText/title makes the code more self-documenting and consistent with Windows Forms conventions.


83-94: LGTM! Improved display style for simple messages.

The new condition improves the presentation of simple messages by:

  • Using messageBoxText as both description and title when appropriate
  • Maintaining separate title/description display for more complex messages

52-77: Verify default case behavior for MessageBoxType.

The default case returns MessageBoxResult.No without showing any dialog. Please verify if this is the intended behavior for unknown MessageBoxType values.

✅ Verification successful

Let me search for the MessageBoxType enum definition to understand all possible values.


Let me check the actual enum definition to see all possible values.


Default case behavior for MessageBoxType is safe and appropriate.

The default case returning MessageBoxResult.No is correct because:

  1. The MessageBoxType enum is fully defined with all possible values (ConfirmationWithYesNo, ConfirmationWithYesNoCancel, YesNo, Information, Error, Warning)
  2. Since it's a closed enum without flags, the default case can only be hit if there's a future enum value addition
  3. Returning MessageBoxResult.No is a safe fallback that aligns with the conservative approach of not proceeding with an action when the intent is unclear
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any custom MessageBoxType values or handling across the codebase
rg -A 2 "MessageBoxType\." --type cs

Length of output: 3514


Script:

#!/bin/bash
# Search for MessageBoxType enum definition
ast-grep --pattern 'enum MessageBoxType'

Length of output: 5541


Script:

#!/bin/bash
# Get the MessageBoxType enum definition
cat Flow.Launcher.Core/MessageBoxEx.xaml.cs

Length of output: 6807

Flow.Launcher.Core/Resource/Internationalization.cs (1)

128-128: Verify MessageBoxType.YesNo behavior matches MessageBoxButton.YesNo.

The change from MessageBoxButton.YesNo to MessageBoxType.YesNo looks correct. However, let's verify that the enum values in MessageBoxType maintain the same behavior as MessageBoxButton to ensure consistent user experience.

✅ Verification successful

MessageBoxType.YesNo behavior correctly maps to MessageBoxButton.YesNo

Looking at the MessageBoxEx implementation, we can see that MessageBoxType.YesNo is properly mapped to MessageBoxButton.YesNo internally, maintaining the same behavior and user experience. The MessageBoxEx class handles the conversion in its Show method, ensuring consistent button visibility and return values.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify MessageBoxType enum values and usage
# Look for MessageBoxType enum definition and other usages to confirm behavior

# Find MessageBoxType enum definition
ast-grep --pattern 'enum MessageBoxType {
  $$$
}'

# Find other MessageBoxEx.Show calls with YesNo type for comparison
rg 'MessageBoxEx\.Show.*MessageBoxType\.YesNo'

Length of output: 438


Script:

#!/bin/bash
# Let's find the MessageBoxEx class implementation to understand how it handles MessageBoxType
ast-grep --pattern 'class MessageBoxEx {
  $$$
}'

# Also search for any MessageBoxButton usage to compare
rg "MessageBoxButton\." -A 2

# Search for any MessageBoxType definition or references
rg "MessageBoxType\." -A 2

Length of output: 11715

Flow.Launcher.Core/Configuration/Portable.cs (2)

12-12: LGTM: Using directive change aligns with PR objective

The static import of MessageBoxEx is appropriate given the frequent usage throughout the file and aligns with the PR's goal of replacing System.Windows.MessageBox.


163-165: LGTM: Proper usage of MessageBoxType.YesNo

The MessageBoxEx implementation correctly uses MessageBoxType.YesNo and properly handles the user's response.

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

17-18: LGTM! Good use of alias directives.

The addition of clear aliases helps disambiguate between different ThemeManager classes, improving code readability and maintainability.


52-52: LGTM! Successfully replaced MessageBox with MessageBoxEx.

The change aligns with the PR objective to support dark theme while maintaining the existing functionality.

Let's verify that this is the only MessageBox usage in this file:

✅ Verification successful

Confirmed: MessageBox has been completely replaced with MessageBoxEx

The verification shows that there is only one message box usage in the file, and it's correctly using MessageBoxEx.Show(). There are no remaining instances of the old System.Windows.MessageBox, confirming the successful migration.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify no remaining System.Windows.MessageBox usages
rg "MessageBox\.Show" "Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs"

Length of output: 91


Script:

#!/bin/bash
# Let's try a broader search for MessageBox usages
rg -i "messagebox" "Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs"

# Also check for any imports related to MessageBox
rg "using.*MessageBox" "Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs"

# Let's also verify MessageBoxEx usage
rg "MessageBoxEx" "Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs"

Length of output: 493

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

113-113: LGTM: MessageBox replacement for directory not found error

The replacement of MessageBox.Show with MessageBoxEx.Show is correct and maintains the existing internationalization and error handling logic.


123-123: LGTM: MessageBox replacement for XAML parse error

The replacement of MessageBox.Show with MessageBoxEx.Show is correct and maintains the existing internationalization and error handling logic.

Flow.Launcher/PriorityChangeWindow.xaml.cs Show resolved Hide resolved
Flow.Launcher.Core/Updater.cs Show resolved Hide resolved
Flow.Launcher.Core/MessageBoxEx.xaml.cs Outdated Show resolved Hide resolved
@Jack251970 Jack251970 changed the title Replace System.Windows.Message with MessageBoxEx & Improve OK MessageBoxEx display style Replace System.Windows.MessageBox with MessageBoxEx & Improve OK MessageBoxEx display style Nov 25, 2024

This comment has been minimized.

Copy link

gitstream-cm bot commented Nov 25, 2024

🥷 Code experts: Yusyuriv, jjw24

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

See details

Flow.Launcher.Core/Configuration/Portable.cs

Activity based on git-commit:

Yusyuriv VictoriousRaptor
NOV
OCT
SEP
AUG
JUL
JUN

Knowledge based on git-blame:
jjw24: 84%

Flow.Launcher.Core/ExternalPlugins/Environments/AbstractPluginEnvironment.cs

Activity based on git-commit:

Yusyuriv VictoriousRaptor
NOV
OCT
SEP
AUG
JUL
JUN 10 additions & 9 deletions

Knowledge based on git-blame:
jjw24: 56%
Yusyuriv: 5%

Flow.Launcher.Core/ExternalPlugins/Environments/PythonEnvironment.cs

Activity based on git-commit:

Yusyuriv VictoriousRaptor
NOV
OCT
SEP
AUG
JUL
JUN

Knowledge based on git-blame:
jjw24: 76%

Flow.Launcher.Core/ExternalPlugins/Environments/TypeScriptEnvironment.cs

Activity based on git-commit:

Yusyuriv VictoriousRaptor
NOV
OCT
SEP
AUG
JUL
JUN

Knowledge based on git-blame:
jjw24: 73%

Flow.Launcher.Core/ExternalPlugins/Environments/TypeScriptV2Environment.cs

Activity based on git-commit:

Yusyuriv VictoriousRaptor
NOV
OCT
SEP
AUG
JUL
JUN

Knowledge based on git-blame:

Flow.Launcher.Core/Plugin/PluginManager.cs

Activity based on git-commit:

Yusyuriv VictoriousRaptor
NOV
OCT
SEP
AUG 2 additions & 2 deletions
JUL
JUN 21 additions & 11 deletions

Knowledge based on git-blame:
jjw24: 4%
Yusyuriv: 4%

Flow.Launcher.Core/Plugin/PluginsLoader.cs

Activity based on git-commit:

Yusyuriv VictoriousRaptor
NOV
OCT
SEP
AUG
JUL
JUN

Knowledge based on git-blame:
jjw24: 18%

Flow.Launcher.Core/Resource/Internationalization.cs

Activity based on git-commit:

Yusyuriv VictoriousRaptor
NOV
OCT
SEP
AUG 1 additions & 0 deletions
JUL
JUN 9 additions & 8 deletions

Knowledge based on git-blame:
jjw24: 11%
Yusyuriv: 4%

Flow.Launcher.Core/Resource/Theme.cs

Activity based on git-commit:

Yusyuriv VictoriousRaptor
NOV
OCT
SEP
AUG
JUL
JUN 74 additions & 31 deletions

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

Flow.Launcher.Core/Updater.cs

Activity based on git-commit:

Yusyuriv VictoriousRaptor
NOV
OCT
SEP
AUG
JUL
JUN

Knowledge based on git-blame:
jjw24: 12%

Flow.Launcher.Plugin/SharedCommands/FilesFolders.cs

Activity based on git-commit:

Yusyuriv VictoriousRaptor
NOV
OCT
SEP
AUG
JUL
JUN

Knowledge based on git-blame:
jjw24: 58%

Flow.Launcher/ActionKeywords.xaml.cs

Activity based on git-commit:

Yusyuriv VictoriousRaptor
NOV
OCT
SEP
AUG
JUL
JUN

Knowledge based on git-blame:
jjw24: 26%

Flow.Launcher/CustomQueryHotkeySetting.xaml.cs

Activity based on git-commit:

Yusyuriv VictoriousRaptor
NOV
OCT
SEP
AUG
JUL
JUN

Knowledge based on git-blame:
Yusyuriv: 19%
jjw24: 17%

Flow.Launcher/CustomShortcutSetting.xaml.cs

Activity based on git-commit:

Yusyuriv VictoriousRaptor
NOV
OCT
SEP
AUG
JUL
JUN 10 additions & 7 deletions

Knowledge based on git-blame:
Yusyuriv: 14%

Flow.Launcher/Helper/HotKeyMapper.cs

Activity based on git-commit:

Yusyuriv VictoriousRaptor
NOV
OCT
SEP
AUG
JUL
JUN

Knowledge based on git-blame:
Yusyuriv: 65%

Flow.Launcher/PriorityChangeWindow.xaml.cs

Activity based on git-commit:

Yusyuriv VictoriousRaptor
NOV
OCT
SEP
AUG
JUL
JUN

Knowledge based on git-blame:

Flow.Launcher/SettingPages/ViewModels/SettingsPaneAboutViewModel.cs

Activity based on git-commit:

Yusyuriv VictoriousRaptor
NOV
OCT
SEP
AUG
JUL
JUN

Knowledge based on git-blame:
Yusyuriv: 92%

Flow.Launcher/SettingPages/ViewModels/SettingsPaneHotkeyViewModel.cs

Activity based on git-commit:

Yusyuriv VictoriousRaptor
NOV
OCT
SEP
AUG
JUL
JUN 10 additions & 3 deletions

Knowledge based on git-blame:
Yusyuriv: 100%

Flow.Launcher/SettingPages/ViewModels/SettingsPaneProxyViewModel.cs

Activity based on git-commit:

Yusyuriv VictoriousRaptor
NOV
OCT
SEP
AUG
JUL
JUN

Knowledge based on git-blame:
Yusyuriv: 100%

Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs

Activity based on git-commit:

Yusyuriv VictoriousRaptor
NOV
OCT
SEP
AUG
JUL
JUN 9 additions & 6 deletions 30 additions & 48 deletions

Knowledge based on git-blame:
Yusyuriv: 74%

Plugins/Flow.Launcher.Plugin.Calculator/Main.cs

Activity based on git-commit:

Yusyuriv VictoriousRaptor
NOV
OCT
SEP
AUG
JUL
JUN

Knowledge based on git-blame:
jjw24: 36%

Plugins/Flow.Launcher.Plugin.Explorer/ContextMenu.cs

Activity based on git-commit:

Yusyuriv VictoriousRaptor
NOV
OCT
SEP
AUG
JUL
JUN 52 additions & 59 deletions

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

Plugins/Flow.Launcher.Plugin.Explorer/Search/Everything/EverythingDownloadHelper.cs

Activity based on git-commit:

Yusyuriv VictoriousRaptor
NOV
OCT
SEP
AUG
JUL
JUN

Knowledge based on git-blame:

Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs

Activity based on git-commit:

Yusyuriv VictoriousRaptor
NOV
OCT
SEP
AUG
JUL
JUN 38 additions & 1 deletions

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

Plugins/Flow.Launcher.Plugin.Explorer/ViewModels/SettingsViewModel.cs

Activity based on git-commit:

Yusyuriv VictoriousRaptor
NOV
OCT
SEP
AUG
JUL
JUN 39 additions & 5 deletions

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

Plugins/Flow.Launcher.Plugin.Explorer/Views/ActionKeywordSetting.xaml.cs

Activity based on git-commit:

Yusyuriv VictoriousRaptor
NOV
OCT
SEP
AUG
JUL
JUN

Knowledge based on git-blame:
jjw24: 22%

Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs

Activity based on git-commit:

Yusyuriv VictoriousRaptor
NOV
OCT
SEP
AUG
JUL
JUN

Knowledge based on git-blame:
jjw24: 16%

Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs

Activity based on git-commit:

Yusyuriv VictoriousRaptor
NOV
OCT
SEP
AUG
JUL
JUN

Knowledge based on git-blame:
jjw24: 2%

Plugins/Flow.Launcher.Plugin.Program/Flow.Launcher.Plugin.Program.csproj

Activity based on git-commit:

Yusyuriv VictoriousRaptor
NOV
OCT
SEP
AUG
JUL
JUN

Knowledge based on git-blame:
jjw24: 17%
Yusyuriv: 2%

Plugins/Flow.Launcher.Plugin.Program/ProgramSuffixes.xaml.cs

Activity based on git-commit:

Yusyuriv VictoriousRaptor
NOV
OCT
SEP
AUG
JUL
JUN

Knowledge based on git-blame:
jjw24: 6%

Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs

Activity based on git-commit:

Yusyuriv VictoriousRaptor
NOV
OCT
SEP
AUG
JUL
JUN

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

Plugins/Flow.Launcher.Plugin.Sys/Flow.Launcher.Plugin.Sys.csproj

Activity based on git-commit:

Yusyuriv VictoriousRaptor
NOV
OCT
SEP
AUG
JUL
JUN

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

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

Activity based on git-commit:

Yusyuriv VictoriousRaptor
NOV
OCT
SEP
AUG
JUL
JUN

Knowledge based on git-blame:
jjw24: 16%

Plugins/Flow.Launcher.Plugin.WebSearch/SearchSourceSetting.xaml.cs

Activity based on git-commit:

Yusyuriv VictoriousRaptor
NOV
OCT
SEP
AUG
JUL
JUN

Knowledge based on git-blame:
jjw24: 17%

Plugins/Flow.Launcher.Plugin.WebSearch/SearchSourceViewModel.cs

Activity based on git-commit:

Yusyuriv VictoriousRaptor
NOV
OCT
SEP
AUG
JUL
JUN

Knowledge based on git-blame:
jjw24: 82%

Plugins/Flow.Launcher.Plugin.WebSearch/SettingsControl.xaml.cs

Activity based on git-commit:

Yusyuriv VictoriousRaptor
NOV
OCT
SEP
AUG
JUL
JUN

Knowledge based on git-blame:
jjw24: 17%

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

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

🧹 Outside diff range and nitpick comments (25)
Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs (1)

36-36: Consider improving error message clarity

While the MessageBox replacement is correct, the "Invalid" comment suggests this is an error message. Consider making the message more descriptive for better user experience.

Example improvement:

-                MessageBoxEx.Show(msg);  // Invalid
+                MessageBoxEx.Show(msg, "Invalid Program Source", MessageBoxType.Error);
Flow.Launcher.Core/ExternalPlugins/Environments/TypeScriptV2Environment.cs (1)

28-31: Consider improving error handling and async/await usage.

The installation process could benefit from better error handling and async/await pattern:

  1. Using .Wait() on DroplexPackage.Drop could block the UI thread
  2. Installation steps lack try-catch error handling

Consider refactoring to:

-        internal override void InstallEnvironment()
+        internal override async Task InstallEnvironment()
         {
-            FilesFolders.RemoveFolderIfExists(InstallPath, MessageBoxEx.Show);
-            DroplexPackage.Drop(App.nodejs_16_18_0, InstallPath).Wait();
-            PluginsSettingsFilePath = ExecutablePath;
+            try {
+                FilesFolders.RemoveFolderIfExists(InstallPath, MessageBoxEx.Show);
+                await DroplexPackage.Drop(App.nodejs_16_18_0, InstallPath);
+                PluginsSettingsFilePath = ExecutablePath;
+            }
+            catch (Exception ex) {
+                MessageBoxEx.Show($"Failed to install TypeScript v2 environment: {ex.Message}");
+                throw;
+            }
         }
Plugins/Flow.Launcher.Plugin.WebSearch/SearchSourceViewModel.cs (1)

44-46: Consider improving error handling and user experience.

The current error handling could be enhanced in several ways:

  1. Make the error message more user-friendly
  2. Add logging of the actual exception
  3. Provide clear next steps to the user

Consider this improvement:

 catch (Exception ex)
 {
 #if DEBUG
     throw;
 #else
-    Flow.Launcher.Core.MessageBoxEx.Show(string.Format("Copying the selected image file to {0} has failed, changes will now be reverted", destinationFileNameFullPath));
+    Log.Exception("Failed to copy image file", ex);
+    Flow.Launcher.Core.MessageBoxEx.Show(
+        $"Unable to save the custom icon. The original icon will be restored.\n\nDetails: {ex.Message}",
+        "Icon Save Error",
+        MessageBoxButton.OK,
+        MessageBoxImage.Warning);
     UpdateIconAttributes(selectedSearchSource, fullPathToOriginalImage);
 #endif
 }
Plugins/Flow.Launcher.Plugin.Program/ProgramSuffixes.xaml.cs (1)

Line range hint 36-53: Consider improving code maintainability

While the changes are functionally correct, consider these improvements:

  1. Add XML documentation to the BtnAdd_OnClick method describing its validation behavior
  2. Extract the translation keys to constants for better maintainability
+    /// <summary>
+    /// Validates and saves the suffix and protocol settings
+    /// </summary>
     private void BtnAdd_OnClick(object sender, RoutedEventArgs e)
     {
+        private const string SUFFIX_EMPTY_KEY = "flowlauncher_plugin_program_suffixes_cannot_empty";
+        private const string PROTOCOL_EMPTY_KEY = "flowlauncher_plugin_protocols_cannot_empty";
         var suffixes = tbSuffixes.Text.Split(Settings.SuffixSeparator, StringSplitOptions.RemoveEmptyEntries);
         var protocols = tbProtocols.Text.Split(Settings.SuffixSeparator, StringSplitOptions.RemoveEmptyEntries);

         if (suffixes.Length == 0 && UseCustomSuffixes)
         {
-            string warning = context.API.GetTranslation("flowlauncher_plugin_program_suffixes_cannot_empty");
+            string warning = context.API.GetTranslation(SUFFIX_EMPTY_KEY);
             MessageBoxEx.Show(warning);
             return;
         }

         if (protocols.Length == 0 && UseCustomProtocols)
         {
-            string warning = context.API.GetTranslation("flowlauncher_plugin_protocols_cannot_empty");
+            string warning = context.API.GetTranslation(PROTOCOL_EMPTY_KEY);
             MessageBoxEx.Show(warning);
             return;
         }
Plugins/Flow.Launcher.Plugin.Explorer/Search/Everything/EverythingDownloadHelper.cs (1)

9-9: Consider removing unnecessary import

Since we're transitioning away from System.Windows.MessageBox to MessageBoxEx, the System.Windows import appears to be unused and can be removed.

-using System.Windows;
Plugins/Flow.Launcher.Plugin.Explorer/Views/ActionKeywordSetting.xaml.cs (1)

66-66: Consider explicitly specifying MessageBoxEx type

While the MessageBoxEx replacements are correct, consider explicitly specifying the message box type for better code clarity and maintainability. Since these are error messages, they should explicitly use MessageBoxButton.OK.

Example refactor:

-MessageBoxEx.Show(api.GetTranslation("plugin_explorer_globalActionKeywordInvalid"));
+MessageBoxEx.Show(api.GetTranslation("plugin_explorer_globalActionKeywordInvalid"), 
+                 button: MessageBoxButton.OK);

Also applies to: 69-69, 81-81

Plugins/Flow.Launcher.Plugin.WebSearch/SettingsControl.xaml.cs (1)

41-41: Consider adding a meaningful title to the MessageBoxEx dialog.

While the MessageBox replacement is correct, using an empty title (string.Empty) might not provide the best user experience. Consider adding a translated title that provides context about the deletion action.

-                var result = MessageBoxEx.Show(formated, string.Empty, MessageBoxType.YesNo);
+                var title = _context.API.GetTranslation("flowlauncher_plugin_websearch_delete_title");
+                var result = MessageBoxEx.Show(formated, title, MessageBoxType.YesNo);
Plugins/Flow.Launcher.Plugin.WebSearch/SearchSourceSetting.xaml.cs (1)

59-69: Add window titles to MessageBoxEx dialogs for better UX

The MessageBoxEx calls for validation warnings should include descriptive titles to provide better context to users.

Consider updating the calls to include titles:

-MessageBoxEx.Show(warning);
+MessageBoxEx.Show(warning, _api.GetTranslation("flowlauncher_plugin_websearch_validation_title"));
Flow.Launcher.Core/Plugin/PluginsLoader.cs (1)

123-126: Consider improving message formatting

The current message formatting uses multiple string interpolations and Environment.NewLine calls. Consider simplifying it for better readability.

-    MessageBoxEx.Show($"{errorMessage}{Environment.NewLine}{Environment.NewLine}" +
-                    $"{errorPluginString}{Environment.NewLine}{Environment.NewLine}" +
-                    $"Please refer to the logs for more information", "",
+    MessageBoxEx.Show(
+        $"{errorMessage}\n\n{errorPluginString}\n\nPlease refer to the logs for more information",
+        string.Empty,
         MessageBoxButton.OK, MessageBoxImage.Warning);
Plugins/Flow.Launcher.Plugin.Calculator/Main.cs (2)

104-104: Consider improving the error message and handling

While the change to MessageBoxEx aligns with the PR objectives, consider these improvements:

  1. Use a translated message key for consistency with other strings in the file
  2. Provide more informative error details to help users troubleshoot
  3. Consider logging the exception details for debugging

Here's a suggested improvement:

- MessageBoxEx.Show("Copy failed, please try later");
+ string errorMessage = Context.API.GetTranslation("flowlauncher_plugin_calculator_copy_failed");
+ Context.API.LogException("Failed to copy calculator result to clipboard", exception);
+ MessageBoxEx.Show(errorMessage);

Don't forget to add the translation key to the resource files:

{
  "flowlauncher_plugin_calculator_copy_failed": "Failed to copy result to clipboard. Please ensure no other program is blocking clipboard access and try again."
}

Line range hint 114-117: Consider improving general error handling strategy

The current approach of silently catching all exceptions in the Query method could hide important errors from users and make debugging difficult.

Consider:

  1. Catching specific exceptions instead of using a general catch
  2. Logging exceptions for debugging
  3. Showing appropriate error messages to users when expression evaluation fails
  4. Adding unit tests for error scenarios

Would you like me to provide a detailed example of how to implement these improvements?

Flow.Launcher.Core/ExternalPlugins/Environments/AbstractPluginEnvironment.cs (1)

9-12: Consider updating imports for better clarity.

Since we're moving away from System.Windows.MessageBox, we should be more specific with the imports. Replace the broad System.Windows import with System.Windows.MessageBoxResult if that's the only type needed from that namespace.

-using System.Windows;
+using System.Windows.MessageBoxResult;
 using System.Windows.Forms;
 using Flow.Launcher.Core.Resource;
 using static Flow.Launcher.Core.MessageBoxEx;
Flow.Launcher.Plugin/SharedCommands/FilesFolders.cs (4)

24-25: LGTM! Consider improving the error message.

The changes correctly implement dependency injection for the message box display. However, the error message could be more user-friendly.

Consider this improved error message:

-messageBoxExShow(string.Format("Copying path {0} has failed, it will now be deleted for consistency", targetPath));
+messageBoxExShow(string.Format("Failed to copy files to '{0}'. The incomplete copy will be removed to maintain consistency.", targetPath));

Also applies to: 58-58, 66-66


79-81: Consider optimizing the directory comparison.

The current implementation loads all files and directories into memory before comparison. For large directories, this could cause performance issues.

Consider this more efficient approach:

 public static bool VerifyBothFolderFilesEqual(this string fromPath, string toPath, Func<string, MessageBoxResult> messageBoxExShow)
 {
     try
     {
-        var fromDir = new DirectoryInfo(fromPath);
-        var toDir = new DirectoryInfo(toPath);
-
-        if (fromDir.GetFiles("*", SearchOption.AllDirectories).Length != toDir.GetFiles("*", SearchOption.AllDirectories).Length)
-            return false;
-
-        if (fromDir.GetDirectories("*", SearchOption.AllDirectories).Length != toDir.GetDirectories("*", SearchOption.AllDirectories).Length)
-            return false;
-
-        return true;
+        return Directory.EnumerateFileSystemEntries(fromPath, "*", SearchOption.AllDirectories)
+            .Count() == Directory.EnumerateFileSystemEntries(toPath, "*", SearchOption.AllDirectories)
+            .Count();
     }

Also applies to: 101-101


112-113: Enhance error handling with specific failure reasons.

The error message could be more helpful by including the reason for the deletion failure.

Consider this improvement:

-catch (Exception)
+catch (Exception ex)
 {
 #if DEBUG
     throw;
 #else
-    messageBoxExShow(string.Format("Not able to delete folder {0}, please go to the location and manually delete it", path));
+    messageBoxExShow(string.Format("Unable to delete folder '{0}': {1}\nPlease try closing any applications using this folder and delete it manually.", 
+        path, ex.Message));
 #endif
 }

Also applies to: 125-125


Line range hint 1-1: Overall implementation successfully replaces MessageBox.Show.

The changes consistently implement the message box replacement across all methods while maintaining the existing functionality. The suggested improvements focus on:

  1. More user-friendly error messages
  2. Performance optimizations for directory operations
  3. Enhanced error handling with specific failure reasons
  4. Additional security checks for file operations

Consider extracting common error message formatting into a shared utility method to maintain consistency across all message box displays.

Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs (1)

183-183: Consider consolidating duplicate message handling.

Both instances show the same translated message for program source selection. Consider extracting this into a shared helper method to improve maintainability and reduce code duplication.

+private void ShowProgramSourceSelectionMessage()
+{
+    string msg = context.API.GetTranslation("flowlauncher_plugin_program_pls_select_program_source");
+    MessageBoxEx.Show(msg);
+}

Also applies to: 288-288

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

Line range hint 187-194: Consider adding braces for consistency

While the MessageBoxEx implementation is correct, consider adding braces around the if statement body for consistency with other similar blocks in the file.

 if (result == MessageBoxResult.Yes)
+{
     Process.Start("shutdown", "/r /o /t 0");
+}

Line range hint 206-213: Consider adding braces for consistency

While the MessageBoxEx implementation is correct, consider adding braces around the if statement body for consistency with other similar blocks in the file.

 if (result == MessageBoxResult.Yes)
+{
     ExitWindowsEx(EWX_LOGOFF, 0);
+}

283-286: Consider using string interpolation for better readability

While the MessageBoxEx implementation is correct, the error message construction could be more readable using string interpolation.

-            MessageBoxEx.Show($"Error emptying recycle bin, error code: {result}\n" +
-                            "please refer to https://msdn.microsoft.com/en-us/library/windows/desktop/aa378137",
+            MessageBoxEx.Show(
+                $"""
+                Error emptying recycle bin, error code: {result}
+                please refer to https://msdn.microsoft.com/en-us/library/windows/desktop/aa378137
+                """,
                 "Error",
                 MessageBoxButton.OK, MessageBoxImage.Error);
Plugins/Flow.Launcher.Plugin.Explorer/ViewModels/SettingsViewModel.cs (1)

361-361: Consider adding warning icon for better UX

Since this is a warning message shown when no item is selected, consider adding MessageBoxImage.Warning to make the message type more apparent to users.

-            MessageBoxEx.Show(warning);
+            MessageBoxEx.Show(warning, string.Empty, MessageBoxButton.OK, MessageBoxImage.Warning);
Plugins/Flow.Launcher.Plugin.Explorer/ContextMenu.cs (1)

178-183: LGTM! MessageBox replacement is properly implemented

The MessageBoxEx implementation maintains the same functionality while supporting the dark theme as intended. The warning icon is appropriately used for the delete confirmation dialog.

Consider enhancing the delete confirmation message

While the implementation is correct, consider making the delete confirmation message more user-friendly by including the file/folder type in the message.

-                                string.Format(Context.API.GetTranslation("plugin_explorer_delete_folder_link"), record.FullPath),
+                                string.Format(Context.API.GetTranslation("plugin_explorer_delete_folder_link"), 
+                                    isFile ? Context.API.GetTranslation("plugin_explorer_file") : Context.API.GetTranslation("plugin_explorer_folder"),
+                                    record.FullPath),
Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs (3)

270-272: Consider extracting message box logic to a helper method

The message box code for update confirmation is duplicated across multiple methods. Consider extracting this to a helper method to improve maintainability.

+ private bool ConfirmPluginUpdate(string pluginName, string author)
+ {
+     string message = Settings.AutoRestartAfterChanging
+         ? string.Format(Context.API.GetTranslation("plugin_pluginsmanager_update_prompt"),
+             pluginName, author, Environment.NewLine, Environment.NewLine)
+         : string.Format(Context.API.GetTranslation("plugin_pluginsmanager_update_prompt_no_restart"),
+             pluginName, author, Environment.NewLine);
+             
+     return MessageBoxEx.Show(message,
+         Context.API.GetTranslation("plugin_pluginsmanager_update_title"),
+         MessageBoxType.YesNo) == MessageBoxResult.Yes;
+ }

365-367: Consider consistent message box result handling

Some message box checks use == MessageBoxResult.No while others use != MessageBoxResult.Yes. Consider standardizing this across the codebase for consistency.

- if (MessageBoxEx.Show(message,
-     Context.API.GetTranslation("plugin_pluginsmanager_update_title"),
-     MessageBoxType.YesNo) == MessageBoxResult.No)
+ if (MessageBoxEx.Show(message,
+     Context.API.GetTranslation("plugin_pluginsmanager_update_title"),
+     MessageBoxType.YesNo) != MessageBoxResult.Yes)

479-484: Consider adding warning message to resource file

The warning message for unknown sources is hardcoded. Consider moving it to the resource file for better internationalization support.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between c103244 and b30cc4f.

📒 Files selected for processing (25)
  • Flow.Launcher.Core/Configuration/Portable.cs (7 hunks)
  • Flow.Launcher.Core/ExternalPlugins/Environments/AbstractPluginEnvironment.cs (4 hunks)
  • Flow.Launcher.Core/ExternalPlugins/Environments/PythonEnvironment.cs (1 hunks)
  • Flow.Launcher.Core/ExternalPlugins/Environments/TypeScriptEnvironment.cs (1 hunks)
  • Flow.Launcher.Core/ExternalPlugins/Environments/TypeScriptV2Environment.cs (1 hunks)
  • Flow.Launcher.Core/Plugin/PluginManager.cs (1 hunks)
  • Flow.Launcher.Core/Plugin/PluginsLoader.cs (2 hunks)
  • Flow.Launcher.Core/Updater.cs (4 hunks)
  • Flow.Launcher.Plugin/SharedCommands/FilesFolders.cs (10 hunks)
  • Plugins/Flow.Launcher.Plugin.Calculator/Main.cs (2 hunks)
  • Plugins/Flow.Launcher.Plugin.Explorer/ContextMenu.cs (2 hunks)
  • Plugins/Flow.Launcher.Plugin.Explorer/Search/Everything/EverythingDownloadHelper.cs (3 hunks)
  • Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs (6 hunks)
  • Plugins/Flow.Launcher.Plugin.Explorer/ViewModels/SettingsViewModel.cs (2 hunks)
  • Plugins/Flow.Launcher.Plugin.Explorer/Views/ActionKeywordSetting.xaml.cs (3 hunks)
  • Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs (8 hunks)
  • Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs (2 hunks)
  • Plugins/Flow.Launcher.Plugin.Program/Flow.Launcher.Plugin.Program.csproj (1 hunks)
  • Plugins/Flow.Launcher.Plugin.Program/ProgramSuffixes.xaml.cs (2 hunks)
  • Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs (4 hunks)
  • Plugins/Flow.Launcher.Plugin.Sys/Flow.Launcher.Plugin.Sys.csproj (1 hunks)
  • Plugins/Flow.Launcher.Plugin.Sys/Main.cs (6 hunks)
  • Plugins/Flow.Launcher.Plugin.WebSearch/SearchSourceSetting.xaml.cs (5 hunks)
  • Plugins/Flow.Launcher.Plugin.WebSearch/SearchSourceViewModel.cs (1 hunks)
  • Plugins/Flow.Launcher.Plugin.WebSearch/SettingsControl.xaml.cs (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • Flow.Launcher.Core/Configuration/Portable.cs
  • Flow.Launcher.Core/Updater.cs
🔇 Additional comments (38)
Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs (2)

2-2: LGTM: Required namespace import added

The Flow.Launcher.Core namespace import is correctly added to support the MessageBoxEx usage.


36-36: Verify complete MessageBox replacement

Let's ensure all System.Windows.MessageBox usages have been replaced with MessageBoxEx.

✅ Verification successful

All MessageBox.Show calls have been replaced with MessageBoxEx

Based on the search results, there are no remaining instances of System.Windows.MessageBox.Show in the codebase. All message box calls consistently use MessageBoxEx.Show. The change in AddProgramSource.xaml.cs aligns with this pattern.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any remaining System.Windows.MessageBox usages
rg "System\.Windows\.MessageBox\.Show" 

# Search for MessageBoxEx usage pattern
rg "MessageBoxEx\.Show"

Length of output: 11504

Flow.Launcher.Core/ExternalPlugins/Environments/TypeScriptEnvironment.cs (1)

28-28: LGTM! Change aligns with PR objectives.

The addition of MessageBoxEx.Show as a callback parameter to RemoveFolderIfExists correctly implements the PR's goal of replacing System.Windows.MessageBox with the new dark-theme compatible MessageBoxEx.

Let's verify this change is consistent with other similar uses in the codebase:

✅ Verification successful

Verified: MessageBoxEx.Show is consistently used with RemoveFolderIfExists

The verification shows that all instances of RemoveFolderIfExists across the codebase correctly use MessageBoxEx.Show as the callback parameter:

  • Flow.Launcher.Core/Configuration/Portable.cs
  • Flow.Launcher.Core/ExternalPlugins/Environments/TypeScriptV2Environment.cs
  • Flow.Launcher.Core/ExternalPlugins/Environments/TypeScriptEnvironment.cs
  • Flow.Launcher.Core/ExternalPlugins/Environments/PythonEnvironment.cs
  • Flow.Launcher.Core/ExternalPlugins/Environments/AbstractPluginEnvironment.cs

Additionally, no remaining instances of System.Windows.MessageBox were found in the codebase, confirming complete migration to MessageBoxEx.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify consistent usage of MessageBoxEx.Show with RemoveFolderIfExists
# Expected: All RemoveFolderIfExists calls should use MessageBoxEx.Show as callback

# Search for RemoveFolderIfExists usage
rg -A 2 "RemoveFolderIfExists\(" 

# Search for any remaining System.Windows.MessageBox usage that might need updating
rg "System\.Windows\.MessageBox"

Length of output: 2725

Flow.Launcher.Core/ExternalPlugins/Environments/PythonEnvironment.cs (2)

31-31: Verify MessageBoxEx import and usage pattern

The change aligns with the PR objective to replace System.Windows.MessageBox with MessageBoxEx. However, we should verify the import and consistent usage pattern.


Line range hint 31-36: Verify MessageBoxEx compatibility across Windows versions

Given that this code handles Python version compatibility issues (specifically Windows 7), ensure that MessageBoxEx properly displays error messages across all supported Windows versions.

✅ Verification successful

Let me analyze the MessageBoxEx usage specifically to verify its compatibility across Windows versions.


Let me check for any platform-specific dependencies or OS version checks in the MessageBoxEx implementation and its base Window class.


MessageBoxEx is compatible across Windows versions

The analysis shows that MessageBoxEx is a simple WPF Window-based dialog implementation that:

  • Uses standard WPF components without any platform-specific code
  • Has no OS version checks or Windows API dependencies
  • Doesn't implement any special handling for different Windows versions

Since it's built on standard WPF which maintains backward compatibility, the MessageBoxEx implementation will work consistently across supported Windows versions.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for Windows version-specific handling in MessageBoxEx

# Look for any Windows version checks in MessageBoxEx implementation
rg "Windows|OS|Platform" --type cs

# Check for any version-specific UI handling
ast-grep --pattern 'if ($_ == $_ || $_.Contains("Windows")) {
  $$$
}'

Length of output: 89227


Script:

#!/bin/bash
# Check MessageBoxEx implementation and usage
ast-grep --pattern 'class MessageBoxEx {
  $$$
}'

# Check for any version-specific handling in MessageBoxEx
rg -A 5 "MessageBoxEx" Flow.Launcher.Core/MessageBoxEx.xaml.cs

Length of output: 771


Script:

#!/bin/bash
# Check for platform dependencies in MessageBoxEx
rg -l "Platform|Windows" Flow.Launcher.Core/MessageBoxEx.xaml*

# Check for any OS version checks in the file
rg "OSVersion|Environment\." Flow.Launcher.Core/MessageBoxEx.xaml*

# Check for any native Windows API calls
rg "DllImport|extern" Flow.Launcher.Core/MessageBoxEx.xaml*

Length of output: 352

Plugins/Flow.Launcher.Plugin.Sys/Flow.Launcher.Plugin.Sys.csproj (1)

40-40: LGTM! The project reference addition is necessary for MessageBoxEx integration.

The addition of Flow.Launcher.Core project reference is required to access the MessageBoxEx implementation, which aligns with the PR objective of replacing System.Windows.MessageBox.

Let's verify the project reference is valid and the project builds:

✅ Verification successful

Project reference is valid and MessageBoxEx is properly available

The verification confirms:

  • Flow.Launcher.Core project exists at the specified relative path
  • MessageBoxEx implementation is present in Core project (MessageBoxEx.xaml and MessageBoxEx.xaml.cs)
  • Multiple components in Core already utilize MessageBoxEx, indicating it's a stable component
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the Flow.Launcher.Core project exists and contains MessageBoxEx

# Check if the Core project exists at the specified path
if [ -f "Flow.Launcher.Core/Flow.Launcher.Core.csproj" ]; then
    echo "✓ Core project exists"
    
    # Verify MessageBoxEx exists in the Core project
    rg -l "MessageBoxEx" "Flow.Launcher.Core/"
else
    echo "✗ Core project not found at relative path"
fi

Length of output: 772

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

44-44: LGTM! MessageBox replacement aligns with PR objectives.

The change from MessageBox.Show to Flow.Launcher.Core.MessageBoxEx.Show successfully implements the dark theme support as intended.

Plugins/Flow.Launcher.Plugin.Program/Flow.Launcher.Plugin.Program.csproj (1)

57-57: LGTM! Verify minimal dependency requirement.

The addition of Flow.Launcher.Core project reference is necessary to support the MessageBoxEx functionality. However, let's verify if this is the minimal required dependency.

✅ Verification successful

Project reference to Flow.Launcher.Core is justified

The dependency is minimal and necessary as evidenced by:

  • MessageBoxEx is the only type imported from Flow.Launcher.Core (via using static directive)
  • Multiple files in the Program plugin use MessageBoxEx.Show for displaying messages
  • No other types from Flow.Launcher.Core are being used
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if MessageBoxEx is the only type used from Flow.Launcher.Core
# This helps determine if we're pulling in more dependencies than necessary

# Search for all Flow.Launcher.Core type usages in the Program plugin
rg "Flow\.Launcher\.Core\." -g "*.cs" "Plugins/Flow.Launcher.Plugin.Program"

# Search specifically for MessageBoxEx usage
rg "MessageBoxEx\." -g "*.cs" "Plugins/Flow.Launcher.Plugin.Program"

Length of output: 962

Plugins/Flow.Launcher.Plugin.Program/ProgramSuffixes.xaml.cs (2)

4-4: LGTM: Required import for MessageBoxEx

The addition of the Flow.Launcher.Core namespace import is necessary and correctly placed.


43-43: Verify MessageBoxEx behavior with localized strings

The MessageBox replacements align with the PR objectives for dark theme support. However, we should verify:

  1. MessageBoxEx properly handles localized strings
  2. The warning message display behavior remains consistent

Also applies to: 50-50

✅ Verification successful

MessageBoxEx is consistently used for localized strings across the codebase

The verification shows that MessageBoxEx.Show is used extensively throughout the codebase with both direct localized strings and GetTranslation calls, following the same pattern as the changes in ProgramSuffixes.xaml.cs. The warning message display behavior is consistent with other validation scenarios in the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if MessageBoxEx is used consistently with localized strings elsewhere
ast-grep --pattern 'MessageBoxEx.Show($api.GetTranslation($_))'

# Check if MessageBoxEx maintains consistent behavior with the original MessageBox
ast-grep --pattern 'MessageBoxEx.Show($_)'

Length of output: 6567

Plugins/Flow.Launcher.Plugin.Explorer/Search/Everything/EverythingDownloadHelper.cs (2)

25-28: LGTM! MessageBox replacement implemented correctly

The MessageBoxEx implementation maintains the original functionality while improving the UI consistency. The translation keys and logic flow are preserved.


56-56: Verify consistency of OpenPath usage

The modification to pass MessageBoxEx.Show to OpenPath appears correct, but we should ensure this pattern is consistently applied across the codebase.

✅ Verification successful

OpenPath usage is consistent across the codebase

All instances of FilesFolders.OpenPath correctly pass the MessageBoxEx.Show delegate as the second parameter:

  • EverythingDownloadHelper.cs: FilesFolders.OpenPath(installedLocation, MessageBoxEx.Show)
  • Portable.cs: FilesFolders.OpenPath(Constant.RootDirectory, MessageBoxEx.Show)

The method signature in FilesFolders.cs confirms this is the expected usage pattern: public static void OpenPath(string fileOrFolderPath, Func<string, MessageBoxResult> messageBoxExShow)

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other OpenPath calls to verify consistent usage
rg "OpenPath\(" --type cs -B 2 -A 2

Length of output: 1626

Plugins/Flow.Launcher.Plugin.Explorer/Views/ActionKeywordSetting.xaml.cs (2)

6-6: LGTM: Required namespace import added

The addition of Flow.Launcher.Core namespace is necessary for accessing the MessageBoxEx class.


Line range hint 66-81: Verify MessageBoxEx implementation

Let's ensure the MessageBoxEx class is properly implemented and handles these message scenarios correctly.

✅ Verification successful

MessageBoxEx implementation is properly configured and functional

The MessageBoxEx class is correctly implemented in Flow.Launcher.Core with:

  • Full support for different message box types (Information, Warning, Error, etc.)
  • Proper button handling (OK, Yes/No, Yes/No/Cancel)
  • Correct image display for different message types
  • Proper window styling and layout
  • Proper handling of message box results

The implementation is being used correctly in the Explorer plugin's ActionKeywordSetting.xaml.cs file.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify MessageBoxEx implementation and usage

# Check if MessageBoxEx exists and supports message box types
ast-grep --pattern 'class MessageBoxEx {
  $$$
  Show($$$) {
    $$$
  }
  $$$
}'

# Check for other similar MessageBox replacements
rg "MessageBox\.Show" -l

Length of output: 110


Script:

#!/bin/bash
# Let's try a different approach to locate MessageBoxEx

# Find files containing MessageBoxEx
rg "MessageBoxEx" -l

# Search for MessageBoxEx class definition with a more flexible pattern
ast-grep --pattern 'class MessageBoxEx'

# Look for any files with MessageBox in their name
fd MessageBox

# Check imports/using statements for MessageBoxEx
rg "using.*MessageBox"

Length of output: 38049


Script:

#!/bin/bash
# Let's examine the MessageBoxEx implementation

# Check the actual implementation in MessageBoxEx.xaml.cs
cat "Flow.Launcher.Core/MessageBoxEx.xaml.cs"

# Check the XAML definition
cat "Flow.Launcher.Core/MessageBoxEx.xaml"

Length of output: 13128

Plugins/Flow.Launcher.Plugin.WebSearch/SettingsControl.xaml.cs (2)

6-7: LGTM! Using directives properly added for MessageBoxEx.

The new using directives are correctly added to support the MessageBox replacement objective.


Line range hint 1-150: Verify complete replacement of MessageBox across the codebase.

Let's ensure all MessageBox instances have been replaced with MessageBoxEx consistently.

✅ Verification successful

Let me verify the actual usage pattern by checking the content of these files.


Based on the results, let me check one more aspect to ensure all MessageBox usages are properly using MessageBoxEx.


All MessageBox instances have been properly replaced with MessageBoxEx

Based on the comprehensive verification:

  1. All MessageBox.Show calls are using MessageBoxEx.Show
  2. The only remaining MessageBox references are in MessageBoxEx.xaml.cs which is the actual implementation
  3. The imports found are only aliasing MessageBoxImage from MessageBoxEx, not from System.Windows
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining System.Windows.MessageBox usages

# Search for remaining MessageBox usages
echo "Checking for remaining MessageBox usages..."
rg -l "System\.Windows\.MessageBox|MessageBox\.Show" --type cs

# Search for new MessageBoxEx usage pattern
echo -e "\nVerifying MessageBoxEx usage pattern..."
rg -l "MessageBoxEx\.Show" --type cs

Length of output: 2196


Script:

#!/bin/bash
# Check for any direct System.Windows.MessageBox imports or usages
echo "Checking for System.Windows.MessageBox imports..."
rg "using System\.Windows\.MessageBox|using MessageBox" --type cs

# Check actual MessageBox.Show usage patterns to ensure they're all MessageBoxEx
echo -e "\nChecking MessageBox.Show usage patterns..."
rg "MessageBox\.Show\(" -A 2 --type cs

Length of output: 674


Script:

#!/bin/bash
# Search for actual MessageBoxEx.Show usage patterns
echo "Checking MessageBoxEx.Show usage patterns..."
rg "MessageBoxEx\.Show\(" -A 2 --type cs

# Double check for any remaining System.Windows.MessageBox references
echo -e "\nChecking for any remaining MessageBox references..."
rg "new MessageBox|class MessageBox|\WMessageBox\W" --type cs

Length of output: 23875

Plugins/Flow.Launcher.Plugin.WebSearch/SearchSourceSetting.xaml.cs (2)

142-142: LGTM! Clean MessageBoxEx implementation for icon path hints

The MessageBoxEx replacement here is well-integrated with the existing conditional logic and translation system.


5-5: Verify complete migration to MessageBoxEx

The MessageBoxEx import has been correctly added. Let's verify no MessageBox usages were missed.

✅ Verification successful

Migration to MessageBoxEx is complete and properly imported

The verification confirms:

  • No remaining System.Windows.MessageBox usages found in the codebase
  • All files using MessageBoxEx.Show have properly imported Flow.Launcher.Core
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any remaining System.Windows.MessageBox usages
rg -l "System\.Windows\.MessageBox" || echo "No remaining MessageBox usages found"

# Verify MessageBoxEx is properly imported everywhere it's used
rg -l "MessageBoxEx\.Show" | xargs rg "using Flow\.Launcher\.Core" || echo "MessageBoxEx import missing in some files"

Length of output: 4358

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

6-6: LGTM! Using directives align with MessageBoxEx migration

The added using directives properly support the transition from System.Windows.MessageBox to MessageBoxEx.

Also applies to: 14-14


123-126: Verify exception handling in fire-and-forget Task

While the async Task.Run prevents UI blocking, ensure that unhandled exceptions are properly captured.

Let's check if there's a global exception handler for unobserved task exceptions:

✅ Verification successful

Fire-and-forget Task pattern is safely handled

The codebase has proper global exception handling in place:

  • AppDomain.CurrentDomain.UnhandledException handler for non-UI thread exceptions
  • DispatcherUnhandledException handler for UI thread exceptions
  • Both handlers use ErrorReporting.Report() to log exceptions
  • UI exceptions are marked as handled to prevent application exit
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for TaskScheduler.UnobservedTaskException handler
rg -l "TaskScheduler\.UnobservedTaskException"

# Search for other potential global exception handlers
ast-grep --pattern 'AppDomain.CurrentDomain.UnhandledException += $_'

Length of output: 120


Script:

#!/bin/bash
# Let's search for any exception handling patterns in the codebase
# First, check for global exception handling setup in Program/Main/App
rg -A 5 "static void Main|public class App\s*:|class Program\s*:"

# Look for any TaskScheduler or unhandled exception related code
rg -i "unhandled.*exception|taskscheduler|application_thread.*exception"

# Check the MessageBoxEx implementation for exception handling
fd -e cs MessageBoxEx.cs --exec cat {}

Length of output: 2177


Script:

#!/bin/bash
# Let's check the ErrorReporting implementation to understand the exception handling
rg -A 10 "UnhandledExceptionHandle|DispatcherUnhandledException" Flow.Launcher/Helper/ErrorReporting.cs

# Also check MessageBoxEx implementation since it wasn't found in previous search
rg -l "MessageBoxEx"

# If found, let's look at its implementation
rg -A 5 "class MessageBoxEx"

Length of output: 3064

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

10-10: LGTM: Required namespace for MessageBoxEx

The addition of the Flow.Launcher.Core namespace is necessary for using MessageBoxEx.

Flow.Launcher.Core/ExternalPlugins/Environments/AbstractPluginEnvironment.cs (3)

62-62: LGTM! MessageBox replacement is correctly implemented.

The change from MessageBox.Show to MessageBoxEx.Show is properly done with the correct message box type and result handling.


103-103: LGTM! Correct delegate usage.

The MessageBoxEx.Show method is correctly passed as a delegate to RemoveFolderIfExists.


12-12: Verify consistent MessageBoxEx usage across the codebase.

Let's ensure all MessageBox replacements follow consistent patterns and no instances were missed.

✅ Verification successful

All MessageBox.Show calls have been replaced with MessageBoxEx

The verification shows consistent usage of MessageBoxEx across the codebase:

  • No remaining instances of System.Windows.MessageBox.Show were found
  • All message box calls use the MessageBoxEx wrapper consistently
  • The usage patterns are uniform, with proper parameter passing for messages, titles, and dialog types
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any remaining System.Windows.MessageBox usage
echo "Checking for remaining MessageBox.Show usage..."
rg "MessageBox\.Show" --type cs

# Search for MessageBoxEx usage patterns
echo -e "\nChecking MessageBoxEx usage patterns..."
rg "MessageBoxEx\.Show\(" -A 2 --type cs

Length of output: 23659

Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs (1)

13-14: LGTM! Clean namespace organization.

The addition of Flow.Launcher.Core namespace and static import of MessageBoxEx aligns with the PR objective of replacing System.Windows.MessageBox throughout the codebase.

Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs (3)

15-15: LGTM: Required import for MessageBoxEx

The addition of the Flow.Launcher.Core namespace import is necessary for accessing the MessageBoxEx class, aligning with the PR's objective.


127-127: LGTM: Consistent MessageBoxEx replacements

The MessageBox.Show replacements with MessageBoxEx.Show are consistent across all error handling blocks. Each usage properly maintains:

  • Error message from the exception
  • Translated title from Context.API
  • Original error handling flow

Also applies to: 141-141, 156-156, 319-319


341-341: LGTM: Good use of dependency injection for MessageBoxEx

The modification to pass MessageBoxEx.Show as a parameter to FilesFolders.OpenFile is a good practice, allowing for flexible message box handling through dependency injection.

Let's verify the FilesFolders.OpenFile implementation accepts this new parameter:

✅ Verification successful

LGTM: FilesFolders.OpenFile implementation matches the usage

The implementation in Flow.Launcher.Plugin/SharedCommands/FilesFolders.cs correctly accepts the message box delegate parameter:

public static void OpenFile(string filePath, Func<string, MessageBoxResult> messageBoxExShow, string workingDir = "", bool asAdmin = false)

This matches the usage in the review where MessageBoxEx.Show is passed as the second parameter.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for FilesFolders.OpenFile method definition
ast-grep --pattern 'class FilesFolders {
  $$$
  OpenFile($$$) {
    $$$
  }
  $$$
}'

Length of output: 87


Script:

#!/bin/bash
# Let's try a different approach to find the FilesFolders.OpenFile method
# First, let's find the file containing FilesFolders class
fd "FilesFolders.cs"

# Then search for OpenFile method with ripgrep for better context
rg "public.*OpenFile.*\(" -A 10

Length of output: 2303

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

10-10: LGTM: Import changes align with MessageBoxEx migration

The updated imports correctly reflect the transition from System.Windows.MessageBox to Flow.Launcher.Core.MessageBoxEx.

Also applies to: 18-18


Line range hint 147-154: LGTM: Shutdown confirmation dialog properly migrated

The MessageBoxEx implementation maintains the same functionality while supporting the new theming system.


Line range hint 167-174: LGTM: Restart confirmation dialog properly migrated

The MessageBoxEx implementation is consistent with the shutdown dialog pattern.

Plugins/Flow.Launcher.Plugin.Explorer/ViewModels/SettingsViewModel.cs (2)

2-2: LGTM!

The added using directive for Flow.Launcher.Core is correctly placed and necessary for accessing MessageBoxEx.


361-361: Verify MessageBox replacement across the codebase

Let's verify that all MessageBox.Show calls have been replaced with MessageBoxEx.Show.

✅ Verification successful

All MessageBox.Show calls have been replaced with MessageBoxEx.Show

Based on the search results, all MessageBox.Show calls in the codebase are using MessageBoxEx.Show. There are no remaining instances of the original System.Windows.MessageBox.Show usage. The replacement has been consistently applied across all files.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for any remaining System.Windows.MessageBox usage

# Search for MessageBox usage in source files
echo "Searching for remaining MessageBox.Show usage..."
rg "MessageBox\.Show" --type-add 'csharp:*.{cs,xaml}' -t csharp

# Search for System.Windows.MessageBox using declarations
echo -e "\nSearching for System.Windows.MessageBox using declarations..."
rg "using System\.Windows\.MessageBox" --type-add 'csharp:*.{cs,xaml}' -t csharp

Length of output: 394


Script:

#!/bin/bash
# Let's try a more comprehensive search for MessageBox usage

# Search for any MessageBox class usage (including MessageBoxEx)
echo "Searching for all MessageBox usage patterns..."
rg "(?:System\.Windows\.)?MessageBox(?:Ex)?\.Show" --type-add 'csharp:*.{cs,xaml}' -t csharp -A 2

# Search for MessageBox type imports/using statements
echo -e "\nSearching for MessageBox related imports..."
rg "using.*MessageBox" --type-add 'csharp:*.{cs,xaml}' -t csharp

# Search for MessageBox class declarations or extensions
echo -e "\nSearching for MessageBox class declarations..."
ast-grep --pattern 'class MessageBox$_'

Length of output: 63669

Plugins/Flow.Launcher.Plugin.Explorer/ContextMenu.cs (2)

14-15: LGTM! Using directives are properly organized

The new imports align with the PR objective to replace System.Windows.MessageBox with MessageBoxEx. The MessageBoxImage alias helps maintain code readability.


178-183: Verify consistent MessageBox usage and translations

Let's verify that:

  1. All MessageBox usages in the codebase have been replaced with MessageBoxEx
  2. The translation key "plugin_explorer_delete_folder_link" exists and is properly formatted
✅ Verification successful

MessageBox usage and translations are properly implemented

Based on the verification results:

  1. All MessageBox usages in the codebase consistently use MessageBoxEx
  2. The translation key "plugin_explorer_delete_folder_link" exists in all language XAML files
  3. The specific usage in ContextMenu.cs follows the correct pattern with proper imports and usage of MessageBoxEx with appropriate parameters
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for any remaining System.Windows.MessageBox usages
echo "Checking for remaining System.Windows.MessageBox usages..."
rg "System\.Windows\.MessageBox" --type cs

# Check for the translation key usage
echo "Checking translation key usage..."
rg "plugin_explorer_delete_folder_link" --type json --type resx

Length of output: 341


Script:

#!/bin/bash
# Check for any remaining MessageBox usages with more context
echo "Checking MessageBox usages..."
rg "MessageBox" -A 2 --type cs

# Check for translation files and their content
echo "Looking for translation files..."
fd -e json -e xaml . Plugins/Flow.Launcher.Plugin.Explorer/

# If found any translation files, let's check their content
echo "Checking translation file content..."
find Plugins/Flow.Launcher.Plugin.Explorer/ -type f -name "*.json" -exec cat {} \;

Length of output: 49912


Script:

#!/bin/bash
# Check for translation key in XAML files
echo "Checking for translation key in language files..."
find Plugins/Flow.Launcher.Plugin.Explorer/Languages/ -type f -name "*.xaml" -exec grep -l "plugin_explorer_delete_folder_link" {} \;

# Check MessageBoxEx usage in the specific file
echo "Checking MessageBoxEx usage in ContextMenu.cs..."
cat "Plugins/Flow.Launcher.Plugin.Explorer/ContextMenu.cs"

Length of output: 23991

Flow.Launcher.Core/Plugin/PluginManager.cs (1)

522-522: LGTM! Verify other MessageBox usages

The update to use MessageBoxEx.Show as the message display callback aligns with the PR objective of replacing System.Windows.MessageBox with MessageBoxEx for dark theme support.

Let's verify if there are other MessageBox usages that need to be updated:

✅ Verification successful

All MessageBox usages have been migrated to MessageBoxEx

Based on the search results, all message box usages in the codebase are already using MessageBoxEx.Show(). There are no remaining instances of System.Windows.MessageBox.Show(). The changes in the PR align with the existing codebase's usage of MessageBoxEx for dark theme support.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for remaining System.Windows.MessageBox usages
rg "System\.Windows\.MessageBox" --type cs

# Search for MessageBox.Show usages that might need updating
rg "MessageBox\.Show" --type cs

# Search for potential message box related imports
rg "using.*MessageBox" --type cs

Length of output: 1545


Script:

#!/bin/bash
# Search for actual MessageBox.Show usages in the codebase
ast-grep --pattern 'MessageBox.Show($$$)'

# Search for actual MessageBoxEx.Show usages in the codebase
ast-grep --pattern 'MessageBoxEx.Show($$$)'

Length of output: 18967

Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs (2)

1-1: LGTM: Import changes align with the MessageBoxEx migration

The addition of Flow.Launcher.Core and static import of MessageBoxEx is appropriate for the MessageBox replacement changes.

Also applies to: 16-16


136-137: Verify error handling for plugin installation cancellation

The MessageBox replacement looks correct, but we should ensure proper error handling when a user cancels the installation.

✅ Verification successful

Let me check the broader context around this code to ensure we understand the full flow of the installation process.


Let me try a different pattern to find the installation method.


Let me try one more search to find the installation method with a simpler pattern.


Proper error handling exists for plugin installation cancellation

Based on the code review:

  1. When user clicks "No" in the MessageBox, the code returns immediately with a clean return statement
  2. For actual installation, proper error handling exists with multiple catch blocks for different scenarios
  3. Cleanup is properly handled:
    • Downloaded files are deleted if not from local install path
    • Temporary folders are created with unique GUIDs
    • Installation errors are logged and shown to users
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if there's proper cleanup when installation is cancelled
# Look for any cleanup code after MessageBox.Show calls

rg -A 5 "MessageBoxEx.Show.*plugin_pluginsmanager_install" 

Length of output: 839


Script:

#!/bin/bash
# Get more context around the installation method
ast-grep --pattern 'async Task InstallPlugin($$$)'

Length of output: 52


Script:

#!/bin/bash
# Search for the installation method with a broader pattern
rg -B 5 -A 15 "InstallPlugin.*async" 

Length of output: 38


Script:

#!/bin/bash
# Search for any method containing InstallPlugin
rg "InstallPlugin" -A 20 -B 5

Length of output: 7455

This comment has been minimized.

@Jack251970 Jack251970 changed the title Replace System.Windows.MessageBox with MessageBoxEx & Improve OK MessageBoxEx display style Replace System.Windows.MessageBox with MessageBoxEx & Improve MessageBoxEx display style Nov 25, 2024
Copy link
Member

@jjw24 jjw24 left a comment

Choose a reason for hiding this comment

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

Hey @Jack251970, could you fix the build fail https://ci.appveyor.com/project/JohnTheGr8/flow-launcher/builds/51049381. Let me know if you need help.

@Jack251970
Copy link
Contributor Author

@jjw24 Sorry, I wonder why this failure will happen because it can run in VS. Will sync fork help? Or I need to do something else?

@jjw24
Copy link
Member

jjw24 commented Nov 26, 2024

See line 398 of https://ci.appveyor.com/project/JohnTheGr8/flow-launcher/builds/51049381#L398. It's complaining about 'no argument given that corresponds to the required parameter 'messageBoxExShow' of 'FilesFolders.RemoveFolderIfExists'.

I can't tell why without going infront of a computer, maybe also check if you still have changes not pushed up yet?

@Jack251970
Copy link
Contributor Author

See line 398 of https://ci.appveyor.com/project/JohnTheGr8/flow-launcher/builds/51049381#L398. It's complaining about 'no argument given that corresponds to the required parameter 'messageBoxExShow' of 'FilesFolders.RemoveFolderIfExists'.

I can't tell why without going in front of a computer, maybe also check if you still have changes not pushed up yet?

Sorry, I will check it. Perhaps I miss something.

This comment has been minimized.

This comment has been minimized.

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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 5d8f277 and 5312505.

📒 Files selected for processing (1)
  • Flow.Launcher.Core/MessageBoxEx.xaml.cs (1 hunks)
🔇 Additional comments (3)
Flow.Launcher.Core/MessageBoxEx.xaml.cs (3)

14-15: Consider replacing static fields with instance fields

The use of static fields msgBox and _result can lead to race conditions if multiple message boxes are shown simultaneously. Additionally, static fields can cause memory leaks if not properly cleaned up. Refactoring to instance fields can improve thread safety and resource management.


192-206: Consolidate event handling logic for button clicks

The Button_Click method uses multiple if statements to determine the result based on the button clicked. Using a switch expression can improve readability and maintainability.

Refactor the method as follows:

- if (sender == btnOk)
-     _result = MessageBoxResult.OK;
- else if (sender == btnYes)
-     _result = MessageBoxResult.Yes;
- else if (sender == btnNo)
-     _result = MessageBoxResult.No;
- else if (sender == btnCancel)
-     _result = MessageBoxResult.Cancel;
- else
-     _result = MessageBoxResult.None;
+ _result = sender switch
+ {
+     var btn when btn == btnOk => MessageBoxResult.OK,
+     var btn when btn == btnYes => MessageBoxResult.Yes,
+     var btn when btn == btnNo => MessageBoxResult.No,
+     var btn when btn == btnCancel => MessageBoxResult.Cancel,
+     _ => MessageBoxResult.None
+ };

180-190: 🛠️ Refactor suggestion

Ensure consistent cleanup after closing the message box

In the KeyEsc_OnPress method, msgBox is not set to null after calling Close(), unlike other event handlers. This inconsistency might lead to memory leaks or unexpected behavior.

Add msgBox = null; after Close();:

DialogResult = false;
Close();
+ msgBox = null;

Likely invalid or redundant comment.

Flow.Launcher.Core/MessageBoxEx.xaml.cs Show resolved Hide resolved
Flow.Launcher.Core/MessageBoxEx.xaml.cs Show resolved Hide resolved
@jjw24 jjw24 added the review in progress Indicates that a review is in progress for this PR label Nov 30, 2024
@jjw24
Copy link
Member

jjw24 commented Nov 30, 2024

@Jack251970 could you please list in the PR description, what tests you have done so far for your changes. This will let me know what other tests I can do for this change.

@Jack251970
Copy link
Contributor Author

@jjw24 Sure, please see Test already done.

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

🧹 Outside diff range and nitpick comments (3)
Flow.Launcher.Plugin/SharedCommands/FilesFolders.cs (3)

24-25: Improve error message clarity in CopyAll method

While the messageBoxExShow parameter is correctly implemented, the error message could be more specific about what failed during the copy operation.

Consider this improvement:

-messageBoxExShow(string.Format("Copying path {0} has failed, it will now be deleted for consistency", targetPath));
+messageBoxExShow(string.Format("Failed to copy files to '{0}': {1}. The incomplete copy will be deleted for consistency", 
+    targetPath, 
+    ex.Message));

Also applies to: 66-68


80-82: Add input validation and improve error handling

The method could benefit from upfront parameter validation and more specific error handling.

Consider these improvements:

 public static bool VerifyBothFolderFilesEqual(this string fromPath, string toPath, Func<string, MessageBoxResult> messageBoxExShow = null)
 {
+    if (string.IsNullOrEmpty(fromPath) || string.IsNullOrEmpty(toPath))
+    {
+        return false;
+    }
+
     try
     {
         var fromDir = new DirectoryInfo(fromPath);
         var toDir = new DirectoryInfo(toPath);
         
         if (!fromDir.Exists || !toDir.Exists)
         {
             return false;
         }
         // ... rest of the method
     }
     catch (Exception ex)
     {
         messageBoxExShow ??= MessageBox.Show;
-        messageBoxExShow(string.Format("Unable to verify folders and files between {0} and {1}", fromPath, toPath));
+        messageBoxExShow(string.Format("Failed to compare folders '{0}' and '{1}': {2}", fromPath, toPath, ex.Message));
         return false;
     }
 }

Also applies to: 102-103


Line range hint 24-209: Consider platform-independent message handling

The current implementation creates a dependency on Windows-specific MessageBox in a shared utility class. Consider using a platform-independent approach for better modularity.

Consider these alternatives:

  1. Create an interface for message handling that can be implemented differently for each platform
  2. Use a callback pattern that doesn't reference Windows-specific types
  3. Move platform-specific code to a separate class

Example interface approach:

public interface IMessageHandler
{
    void ShowMessage(string message);
    MessageResult ShowMessageWithResult(string message);
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 5312505 and 0d362b3.

📒 Files selected for processing (1)
  • Flow.Launcher.Plugin/SharedCommands/FilesFolders.cs (10 hunks)
🔇 Additional comments (2)
Flow.Launcher.Plugin/SharedCommands/FilesFolders.cs (2)

114-115: Add default parameter value and improve error handling

The method needs a default parameter value as requested in previous comments, and the error handling could be more specific.

Consider these improvements:

-public static void RemoveFolderIfExists(this string path, Func<string, MessageBoxResult> messageBoxExShow = null)
+public static void RemoveFolderIfExists(this string path, Func<string, MessageBoxResult> messageBoxExShow = MessageBox.Show)
 {
     try
     {
         if (Directory.Exists(path))
             Directory.Delete(path, true);
     }
-    catch (Exception)
+    catch (Exception ex)
     {
 #if DEBUG
         throw;
 #else
-        messageBoxExShow ??= MessageBox.Show;
-        messageBoxExShow(string.Format("Not able to delete folder {0}, please go to the location and manually delete it", path));
+        messageBoxExShow(string.Format("Failed to delete folder '{0}': {1}. Please try deleting it manually.", 
+            path, 
+            ex is UnauthorizedAccessException ? "Access denied" : ex.Message));
 #endif
     }
 }

Also applies to: 127-128


188-189: Add security checks and improve error handling as previously suggested

The previous review comments about adding security checks for admin execution and improving error handling are still relevant.

Please refer to the previous review comment for the detailed implementation of security checks and error handling improvements for the OpenFile method.

Also applies to: 208-209

@Jack251970 Jack251970 requested a review from jjw24 December 1, 2024 11:56

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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 0d362b3 and b568d2d.

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

28-28: LGTM!

The new using directive is correctly placed and necessary for accessing the MessageBoxEx implementation.

Flow.Launcher/PublicAPIInstance.cs Show resolved Hide resolved

This comment has been minimized.

@taooceros
Copy link
Member

@onesounds is there a reason that previously the no is on left yes on right?

@onesounds
Copy link
Contributor

@onesounds is there a reason that previously the no is on left yes on right?

I can't remember why either. As far as I know, this order of PR is correct. I wish I could change the order freely on the code, ("no yes" or "yes no" but I remember it was probably hard to make. (I had to make several buttons.)

Copy link

github-actions bot commented Dec 7, 2024

@check-spelling-bot Report

🔴 Please review

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

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

See ❌ Event descriptions for more information.

If the flagged items are 🤯 false positives

If items relate to a ...

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

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

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

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

  • well-formed pattern.

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

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

    Note that patterns can't match multiline strings.

@jjw24
Copy link
Member

jjw24 commented Dec 7, 2024

@Jack251970 I have made the MessageBoxEx's Show method to use defaults so we can remove the other unnecessary overrides, please see my commit. Everything else looks really good. Let me know if this is OK.

@jjw24 jjw24 removed review in progress Indicates that a review is in progress for this PR 20 min review labels Dec 7, 2024
@jjw24 jjw24 added this to the Future milestone Dec 7, 2024
@Jack251970
Copy link
Contributor Author

@jjw24 Thank you! I have forgotton to simplify functions in the MessageBoxEx.xaml.cs. I use dark mode for my system and could not wait to experience this improvement.

@jjw24 jjw24 modified the milestones: Future, 1.20.0 Dec 7, 2024
Copy link
Member

@jjw24 jjw24 left a comment

Choose a reason for hiding this comment

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

👍 very nice thank you

@jjw24 jjw24 merged commit ce6b4d9 into Flow-Launcher:dev Dec 7, 2024
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.

4 participants