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

chore(suite-desktop): Unify suite desktop flags #17687

Merged
merged 2 commits into from
Mar 19, 2025

Conversation

Lemonexe
Copy link
Contributor

@Lemonexe Lemonexe commented Mar 14, 2025

Description

  • create helpers hasSwitch & getSwitchValue incl. unit tests
    • to mimic behavior of same-named app.commandLine methods, which are not to be used for this (see issue)
  • refactor current usages of app.commandLine methods, or direct process.argv access
    • the only remaning usage of either of those two methods are width & height
    • those are actualy Chromium flags, so that's

Note: only width & height remain, where the electron API is OK, because those are Chromium switches ✔️

Related Issue

Resolve #17686

* Check if a switch is present in process arguments.
*/
export const hasSwitch = (switchName: SuiteSwitch) => {
const isSwitch = new RegExp(`^--${switchName}(?:=[^=]+)?=?$`);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

regex carefully crafted to match --flag without value, but also --flag=with_value or empty value --flag=, but =?.+ would not suffice, because it would accidentally match substring.
In other words, value at end can only come after = (optional).

This is simpler in getSwitchValue, where the regex always requires =

@Lemonexe Lemonexe marked this pull request as ready for review March 14, 2025 22:51
Copy link

coderabbitai bot commented Mar 14, 2025

Walkthrough

The changes refactor how command-line switches are handled throughout the application. A dedicated library for processing switches has been introduced with two new functions, hasSwitch and getSwitchValue, which replace direct calls to Electron’s app.commandLine methods. These utility functions now encapsulate the logic for checking and retrieving switch values. The update spans several modules such as auto-updater, bridge, dev-tools, logger, event-logging, HTTP receiver, Tor, and trezor-connect, ensuring a consistent approach across the codebase. A new test suite has also been added to validate the behavior of these functions under various scenarios. Additionally, the new file defining available switches standardizes the supported command-line options without modifying any exported entity declarations aside from including the new utilities.

Tip

⚡🧪 Multi-step agentic review comment chat (experimental)
  • We're introducing multi-step agentic chat in review comments. This experimental feature enhances review discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments.
    - To enable this feature, set early_access to true under in the settings.
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

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

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

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai 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.

@Lemonexe Lemonexe force-pushed the unify-suite-desktop-flags branch from 3f99920 to ff8b74f Compare March 19, 2025 11:42
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
packages/suite-desktop-core/src/libs/process-switches.ts (1)

34-44: Effective implementation of getSwitchValue function

The getSwitchValue function accurately mimics Electron's app.commandLine.getSwitchValue behavior, which improves maintainability by eliminating direct dependencies on Electron's API.

Consider a minor optimization to improve readability:

-const valueMatch = process.argv.map(arg => arg.match(switchValueMatch)).find(Boolean);
+const valueMatch = process.argv.find(arg => switchValueMatch.test(arg))?.match(switchValueMatch);

This approach could be slightly more efficient by avoiding unnecessary regex matches after finding the first match.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3f99920 and ff8b74f.

📒 Files selected for processing (12)
  • packages/suite-desktop-core/src/__tests__/process-switches.test.ts (1 hunks)
  • packages/suite-desktop-core/src/app.ts (3 hunks)
  • packages/suite-desktop-core/src/libs/app-utils.ts (1 hunks)
  • packages/suite-desktop-core/src/libs/logger.ts (3 hunks)
  • packages/suite-desktop-core/src/libs/process-switches.ts (1 hunks)
  • packages/suite-desktop-core/src/modules/auto-updater.ts (2 hunks)
  • packages/suite-desktop-core/src/modules/bridge.ts (1 hunks)
  • packages/suite-desktop-core/src/modules/dev-tools.ts (1 hunks)
  • packages/suite-desktop-core/src/modules/event-logging/contents.ts (1 hunks)
  • packages/suite-desktop-core/src/modules/http-receiver.ts (2 hunks)
  • packages/suite-desktop-core/src/modules/tor.ts (2 hunks)
  • packages/suite-desktop-core/src/modules/trezor-connect.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (10)
  • packages/suite-desktop-core/src/modules/http-receiver.ts
  • packages/suite-desktop-core/src/app.ts
  • packages/suite-desktop-core/src/libs/app-utils.ts
  • packages/suite-desktop-core/src/modules/dev-tools.ts
  • packages/suite-desktop-core/src/modules/event-logging/contents.ts
  • packages/suite-desktop-core/src/modules/tor.ts
  • packages/suite-desktop-core/src/tests/process-switches.test.ts
  • packages/suite-desktop-core/src/modules/auto-updater.ts
  • packages/suite-desktop-core/src/modules/bridge.ts
  • packages/suite-desktop-core/src/libs/logger.ts
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: build-web
  • GitHub Check: Analyze with CodeQL (javascript)
  • GitHub Check: Setup and Cache Dependencies
🔇 Additional comments (4)
packages/suite-desktop-core/src/modules/trezor-connect.ts (2)

1-7: Improved dependency management by removing direct Electron app imports

The change removes the direct dependency on Electron's app object and introduces the dedicated getSwitchValue utility function. This aligns with the PR objective to unify suite desktop flags handling.


65-65: Consistent usage of command-line switch handling

Good refactoring of the debug flag access from app.commandLine.getSwitchValue('log-connect') to the new getSwitchValue('log-connect'). This provides a unified approach to handling command-line arguments and eliminates direct dependencies on Electron's API.

packages/suite-desktop-core/src/libs/process-switches.ts (2)

1-23: Well-defined TypeScript type for command-line switches

The SuiteSwitch type alias provides a comprehensive list of all supported command-line switches, ensuring type safety throughout the application. This is a good practice for maintaining a centralized definition of supported options.


25-32: Robust implementation of hasSwitch function

The hasSwitch function implementation is well-designed with a carefully crafted regex pattern that correctly handles switches both with and without values.

The regex handles --flag without value, --flag=with_value, and empty value --flag= cases as mentioned in the past review comments.

@Lemonexe Lemonexe merged commit c2aec5c into develop Mar 19, 2025
29 checks passed
@Lemonexe Lemonexe deleted the unify-suite-desktop-flags branch March 19, 2025 12:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cleanup Suite Desktop process switches
2 participants