Add reference to open windows in Butil (#10043)#10045
Add reference to open windows in Butil (#10043)#10045msynk merged 2 commits intobitfoundation:developfrom
Conversation
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughThe pull request enhances several components. XML documentation comments are added to two public methods in the BitButil class. The Window class is updated to implement asynchronous disposal and its Open and Close methods have modified signatures, including passing unique window identifiers. The TypeScript script for window management now tracks opened windows using an internal reference map and adds functions for closing and disposing windows. Finally, the demo page is updated with a new close button and a mechanism to maintain and remove window identifiers. Changes
Sequence Diagram(s)sequenceDiagram
participant U as User
participant WP as WindowPage
participant W as Window (C#)
participant JS as window.ts
U->>WP: Click "OpenWindow" button
WP->>W: Invoke Open(url, target, features)
W->>JS: Call open(guid, url, target, features)
JS-->>W: Return window reference
W-->>WP: Return generated GUID
WP->>WP: Append GUID to windowIds
U->>WP: Click "CloseWindow" button
WP->>W: Invoke Close(lastGUID)
W->>JS: Call close(id)
JS-->>W: Confirm window closure
W-->>WP: (operation complete)
WP->>WP: Remove GUID from windowIds
Poem
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (4)
src/Butil/Demo/Bit.Butil.Demo.Core/Pages/WindowPage.razor (1)
367-372: Consider minimal error handling during window closure.
If a browser blocked the window or if it was already closed externally,window.Close(id)might fail silently. You could add a try/catch or console logging to inform the user when closure cannot be fulfilled.src/Butil/Bit.Butil/Scripts/window.ts (3)
4-5: Use of a global_refsobject to store window references.
Storing references in_refsworks, but consider adding TypeScript type annotations or other safeguards (e.g., ensuring unique IDs), to prevent collisions or potential misuse.
53-60: Close function logic is clear and safe.
It checks for an undefined ID and closes the current window if none is provided, or a specific reference otherwise. Optionally, logging a warning when an unknown ID is supplied could improve diagnosability.
79-82: Handle possible null returns fromwindow.open.
If a popup blocker prevents opening a new window,window.opencan returnnull. Consider detecting this scenario and gracefully informing the caller.function open(id: string, url?: string, target?: string, windowFeatures?: string) { const ref = window.open(url, target, windowFeatures); + if (!ref) { + console.warn("Window blocked or failed to open."); + return null; + } _refs[id] = ref; return id; }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
src/Butil/Bit.Butil/BitButil.cs(1 hunks)src/Butil/Bit.Butil/Publics/Window.cs(4 hunks)src/Butil/Bit.Butil/Scripts/window.ts(6 hunks)src/Butil/Demo/Bit.Butil.Demo.Core/Pages/WindowPage.razor(3 hunks)
✅ Files skipped from review due to trivial changes (1)
- src/Butil/Bit.Butil/BitButil.cs
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: build and test
🔇 Additional comments (11)
src/Butil/Demo/Bit.Butil.Demo.Core/Pages/WindowPage.razor (4)
11-19: No functional impact in these snippet lines.
They appear to display example code within the<pre>block. No further action needed.
100-100: The new "CloseWindow" button is a helpful addition.
It neatly complements the "OpenWindow" functionality by allowing users to close opened windows from the UI.
360-360: Good approach to keep track of opened window IDs.
Storing them in aList<string>is straightforward and aligns well with the updated API in theWindowclass.
364-365: Storing the opened window’s ID for subsequent closure.
This use ofawait window.Open(...)and storing the resulting GUID inwindowIdscorrectly matches the new JavaScript implementation.src/Butil/Bit.Butil/Scripts/window.ts (2)
26-26: Newly exposed methods in thebutil.windowobject.
Exportingclose,stop, anddisposebroadens window management. Confirm these additions are documented so consumers are aware of the new functionality.Also applies to: 37-38
101-103: Dispose function effectively resets stored references.
Clearing_refsensures no lingering references after disposal. This aligns with the .NET side’sDisposeAsync.src/Butil/Bit.Butil/Publics/Window.cs (5)
13-13: Adoption of IAsyncDisposable is well-structured.
Implementing asynchronous disposal indicates a well-considered approach to resource cleanup on the JS side.
182-185: Enhanced Close method with an optional ID.
Consistently mirrors the JavaScriptclosechange. This design is easy to call for general or specific window closure.
236-237: Open method returning a string ID.
Switching fromTask<bool>toTask<string>is a solid improvement that aligns with referencing windows by a unique identifier.
243-244: Overload for Open with WindowFeatures is consistent.
Clarifies usage by providing a typed parameter for window features, further enhancing correctness.
300-313: DisposeAsync implementation is coherent with JavaScript cleanup.
InvokingBitButil.window.disposefrom the .NET side effectively releases references. Consider logging or try/catch for failures, but otherwise this is good.
closes #10043
Summary by CodeRabbit
New Features
Refactor