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

raise variable browser window, if already created, otherwise create a… #537

Merged
merged 2 commits into from
Dec 27, 2024

Conversation

highperformancecoder
Copy link
Owner

@highperformancecoder highperformancecoder commented Dec 27, 2024

… new window. For #1775.


This change is Reviewable

Summary by CodeRabbit

  • New Features

    • Introduced a new property url in the main window details for future enhancements.
    • Added a method to manage existing windows by raising them instead of creating duplicates.
    • Updated window creation methods to handle a new url parameter and a flag to raise existing windows.
    • Modified variable pane handling to include a flag for raising existing instances.
  • Bug Fixes

    • Enhanced window management to prevent duplicate windows for the same URL.
  • Documentation

    • Updated interface definitions to include new properties for better clarity and functionality.

Copy link

coderabbitai bot commented Dec 27, 2024

Walkthrough

The changes introduce enhanced window management capabilities in the Minsky Electron application. A new url property has been added to track window URLs, and a raiseWindow method has been implemented to prevent duplicate window creation. The modifications allow for raising existing windows instead of creating new ones when a window with the same URL already exists. These updates expand the structure of the application and improve window handling.

Changes

File Change Summary
gui-js/apps/minsky-electron/src/app/app.ts Added url: "" to mainWindowDetails object
gui-js/apps/minsky-electron/src/app/managers/WindowManager.ts - Added raiseWindow method
- Updated createWindow to handle url and raiseIfPresent
- Modified createPopupWindowWithRouting
gui-js/libs/shared/src/lib/interfaces/ActiveWindow.ts - Added url: string property
- Formatted menu property
gui-js/libs/shared/src/lib/interfaces/Interfaces.ts Added optional raiseIfPresent boolean to CreateWindowPayload
gui-js/libs/ui-components/src/lib/wiring/variable/variable.component.ts Added raiseIfPresent: true to openVariablePane method

Sequence Diagram

sequenceDiagram
    participant User
    participant WindowManager
    participant ElectronService
    participant ActiveWindows

    User->>WindowManager: Request Window
    WindowManager->>ActiveWindows: Check Existing Windows
    alt Window with URL exists
        WindowManager->>WindowManager: Raise Existing Window
    else No Existing Window
        WindowManager->>ElectronService: Create New Window
    end
    WindowManager->>User: Return Window
Loading

Poem

🐰 A rabbit's tale of windows bright,
No duplicates shall cause a fight!
Raise the pane, don't make anew,
With URL magic, our code rings true!
Efficiency hops, with electron's might! 🖥️

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


🪧 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. (Beta)
  • @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

@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 (3)
gui-js/libs/shared/src/lib/interfaces/ActiveWindow.ts (1)

10-10: Consider validating or documenting the new url property.

Adding a url property is a solid idea. However, determine whether any validation or additional documentation is needed, particularly if the url can be an empty string or some special format. This helps prevent confusion when referencing it elsewhere in the code.

gui-js/apps/minsky-electron/src/app/app.ts (1)

152-152: Defaulting url to an empty string is fine, but consider clarifying usage.

Initialize url with "" indicates you may not load a specific route initially. If the app expects a meaningful URL, consider clarifying this in a doc comment or referencing existing usage in the WindowManager to ensure consistency across the codebase.

gui-js/apps/minsky-electron/src/app/managers/WindowManager.ts (1)

191-198: Reassess static usage and confirm code flow for existing windows.

  1. At line 195, the direct call to this.raiseWindow(url) once again uses this in a static context. Though valid, consider referencing the class name directly (WindowManager.raiseWindow(...)) if it aligns better with your code style.

  2. This branch of code gracefully avoids creating a duplicate window when raiseIfPresent is set. Ensure all call sites set raiseIfPresent appropriately, especially for windows that must be unique.

🧰 Tools
🪛 Biome (1.9.4)

[error] 195-195: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e275c95 and a92a86a.

📒 Files selected for processing (5)
  • gui-js/apps/minsky-electron/src/app/app.ts (1 hunks)
  • gui-js/apps/minsky-electron/src/app/managers/WindowManager.ts (3 hunks)
  • gui-js/libs/shared/src/lib/interfaces/ActiveWindow.ts (1 hunks)
  • gui-js/libs/shared/src/lib/interfaces/Interfaces.ts (1 hunks)
  • gui-js/libs/ui-components/src/lib/wiring/variable/variable.component.ts (1 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
gui-js/apps/minsky-electron/src/app/managers/WindowManager.ts

[error] 138-138: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 195-195: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)

🔇 Additional comments (5)
gui-js/libs/shared/src/lib/interfaces/ActiveWindow.ts (1)

9-9: Use consistent formatting for interface properties.

Good job updating menu : Menu; to menu: Menu; for consistency. Ensure that similar formatting improvements are applied throughout this file to reduce friction for future contributors.

gui-js/libs/ui-components/src/lib/wiring/variable/variable.component.ts (1)

45-54: Verify presence of raiseIfPresent logic in the WindowManager.

Your addition of raiseIfPresent: true indicates you intend to raise an already open window. Confirm that the WindowManager checks both url and the raiseIfPresent flag as intended. This ensures that existing windows are not duplicated, and new windows are only created when needed.

gui-js/libs/shared/src/lib/interfaces/Interfaces.ts (1)

135-135: Excellent addition of the raiseIfPresent property.

Introducing raiseIfPresent?: boolean; helps manage window duplication. Be sure to handle undefined cases or default it to false to avoid unexpected behaviors.

gui-js/apps/minsky-electron/src/app/managers/WindowManager.ts (2)

134-145: Ensure consistent handling of multiple windows with the same URL.

This logic raises the first matching window by URL and stops searching. If multiple windows share the same URL, only the first match will be raised. Confirm this is the desired behavior or handle multiple matches if needed.

Additionally, note the static analysis suggestion regarding usage of this in a static context (line 138). In TypeScript, using this within a static method is valid, but some codebases prefer referencing the class name, e.g. WindowManager.activeWindows, to avoid confusion.

🧰 Tools
🪛 Biome (1.9.4)

[error] 138-138: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


245-245: Validate URL usage and fallback scenarios.

Storing the URL in childWindowDetails.url is crucial for future lookups or raising existing windows. Verify that the URL is always provided, and handle scenarios where it might be empty or invalid if the code design requires such fallback logic.

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)
gui-js/apps/minsky-electron/src/app/managers/WindowManager.ts (1)

134-145: Enhance the raiseWindow implementation

While the functionality is correct, the implementation could be improved for better TypeScript practices and readability.

Consider this alternative implementation:

 static raiseWindow(url: string): BrowserWindow {
-  let window=null;
-  for (let i of WindowManager.activeWindows) 
-    if (i[1].url==url) {
-      window=i[1].context;
-      break;
-    }
-  if (window) window.show();
-  return window;
+  const existingWindow = Array.from(WindowManager.activeWindows.values())
+    .find(window => window.url === url)?.context;
+  
+  if (existingWindow) {
+    existingWindow.show();
+  }
+  
+  return existingWindow || null;
 }

This refactored version:

  1. Uses more idiomatic TypeScript/JavaScript array methods
  2. Improves variable naming for clarity
  3. Uses proper spacing and formatting
  4. Maintains better type safety
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a92a86a and 0da2559.

📒 Files selected for processing (2)
  • gui-js/apps/minsky-electron/src/app/managers/WindowManager.ts (11 hunks)
  • gui-js/libs/shared/src/lib/interfaces/ActiveWindow.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • gui-js/libs/shared/src/lib/interfaces/ActiveWindow.ts
🔇 Additional comments (8)
gui-js/apps/minsky-electron/src/app/managers/WindowManager.ts (8)

35-35: LGTM: Improved static method access clarity

The changes from this to WindowManager make the static nature of these methods more explicit and align with TypeScript best practices.

Also applies to: 39-39


52-52: LGTM: Improved code formatting and static access

The changes maintain consistency in static method access and improve the readability of the renderFrame parameters through better formatting.

Also applies to: 62-69


79-82: LGTM: Consistent static method access in tab management

The changes maintain proper static method access while correctly handling tab switching and frame cleanup.


158-158: LGTM: Proper URL handling in popup window creation

The change correctly implements the window URL loading mechanism using the WindowManager's URL utility method.


191-197: LGTM: Proper implementation of window raising logic

The changes correctly implement the window raising functionality, preventing duplicate windows when requested.


245-245: LGTM: Proper window tracking and cleanup

The changes maintain consistent static access and properly handle window tracking and cleanup in the maps.

Also applies to: 249-249, 252-252, 257-257, 260-260, 270-270


284-294: LGTM: Consistent static access in layout handling

The changes maintain proper static method access while preserving the existing layout calculation logic.

Also applies to: 297-298


209-209: Verify modal window behavior

The change in parent window assignment could affect modal window behavior.

✅ Verification successful

Modal window behavior change is safe

Based on the codebase analysis, the change in parent window assignment is safe because:

  1. The default modal behavior is explicitly set to true in the WindowManager.createWindow method:
const { width, height, minWidth, minHeight, title, modal = true, ... } = payload;
  1. Most windows that need non-modal behavior explicitly set modal: false in their creation options, including:
  • Menu-related windows
  • Godley widget windows
  • Plot widget windows
  • Ravel widget windows
  • Download windows

The parent window assignment change maintains the expected modal behavior - when modal is true, the window will be attached to the main window as its parent, and when modal is false, it won't have a parent window.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for modal window usage patterns
rg -l "modal:\s*true" --type ts

Length of output: 33


Script:

#!/bin/bash
# Search for modal window related patterns with broader context
rg "modal.*window" --type ts -B 2 -A 2

# Search for window creation patterns
rg "createWindow|new\s+BrowserWindow" --type ts -B 2 -A 2

# Search for modal property usage with different patterns
rg "modal:\s*(true|false)|modal\s*=\s*(true|false)" --type ts -B 2 -A 2

Length of output: 10881

@highperformancecoder highperformancecoder merged commit 2afa39f into master Dec 27, 2024
7 checks passed
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.

1 participant