Skip to content

Update MCPForUnityEditorWindow.cs#917

Merged
Scriptwonder merged 1 commit intoCoplayDev:betafrom
Scriptwonder:fix-on-queueupdatecheck
Mar 11, 2026
Merged

Update MCPForUnityEditorWindow.cs#917
Scriptwonder merged 1 commit intoCoplayDev:betafrom
Scriptwonder:fix-on-queueupdatecheck

Conversation

@Scriptwonder
Copy link
Collaborator

@Scriptwonder Scriptwonder commented Mar 11, 2026

Problem #830. Previously once the GUI is on focus, RefreshAllData will be called and QueueUpdateCheck() is called, for some users with internet issues (from susception), this will cause issue, and check for update is not necessary to run that often. I moved it to the CreateGUI part, so every time the package is updated, restored, reopened, this function will still run.

Summary by Sourcery

Enhancements:

  • Trigger the update check once during editor window GUI creation instead of on every data refresh to avoid excessive checks.

Summary by CodeRabbit

  • Bug Fixes
    • Adjusted the timing of package update checks to occur when the editor window initializes, rather than during routine data refreshes.

Copilot AI review requested due to automatic review settings March 11, 2026 03:58
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Mar 11, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adjusts when the update check is queued so it runs once during GUI creation instead of every time data is refreshed, reducing unnecessary network calls when the editor window gains focus.

Sequence diagram for updated update check timing in MCPForUnityEditorWindow

sequenceDiagram
    actor User
    participant UnityEditor
    participant MCPForUnityEditorWindow

    rect rgb(230,230,255)
        alt Before_PR_OnFocus_triggers_update_check
            User ->> UnityEditor: Focus_editor_window
            UnityEditor ->> MCPForUnityEditorWindow: OnFocus
            MCPForUnityEditorWindow ->> MCPForUnityEditorWindow: RefreshAllData
            MCPForUnityEditorWindow ->> MCPForUnityEditorWindow: QueueUpdateCheck
        else After_PR_CreateGUI_triggers_update_check
            User ->> UnityEditor: Open_or_reload_editor_window
            UnityEditor ->> MCPForUnityEditorWindow: CreateGUI
            MCPForUnityEditorWindow ->> MCPForUnityEditorWindow: RefreshAllData
            MCPForUnityEditorWindow ->> MCPForUnityEditorWindow: QueueUpdateCheck

            User ->> UnityEditor: Focus_editor_window
            UnityEditor ->> MCPForUnityEditorWindow: OnFocus
            MCPForUnityEditorWindow ->> MCPForUnityEditorWindow: RefreshAllData
        end
    end
Loading

File-Level Changes

Change Details Files
Trigger update check during GUI initialization instead of on every data refresh to avoid frequent network calls.
  • Add QueueUpdateCheck() call immediately after RefreshAllData() in CreateGUI so it runs when the window is created or reopened.
  • Remove QueueUpdateCheck() invocation from RefreshAllData so it is no longer called whenever data is refreshed or the window gains focus.
MCPForUnity/Editor/Windows/MCPForUnityEditorWindow.cs

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@Scriptwonder Scriptwonder merged commit d440ddb into CoplayDev:beta Mar 11, 2026
2 checks passed
@Scriptwonder Scriptwonder deleted the fix-on-queueupdatecheck branch March 11, 2026 03:58
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • Now that QueueUpdateCheck() runs only in CreateGUI(), please double-check whether there are other code paths that call RefreshAllData() (e.g., manual refresh actions) where an update check is still desired, and if so consider either a separate explicit update trigger or a parameter to control this behavior.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Now that `QueueUpdateCheck()` runs only in `CreateGUI()`, please double-check whether there are other code paths that call `RefreshAllData()` (e.g., manual refresh actions) where an update check is still desired, and if so consider either a separate explicit update trigger or a parameter to control this behavior.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 11, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 942be0dd-12d7-42f2-912d-ff2508e53c63

📥 Commits

Reviewing files that changed from the base of the PR and between cab7496 and 89876f6.

📒 Files selected for processing (1)
  • MCPForUnity/Editor/Windows/MCPForUnityEditorWindow.cs

📝 Walkthrough

Walkthrough

A call to QueueUpdateCheck() is moved from the RefreshAllData method to the CreateGUI method in the editor window, shifting when package update checks are triggered from general data refreshes to initial UI construction time.

Changes

Cohort / File(s) Summary
Update Check Timing
MCPForUnity/Editor/Windows/MCPForUnityEditorWindow.cs
Relocated QueueUpdateCheck() invocation from RefreshAllData to CreateGUI, ensuring update checks occur during UI initialization rather than on every data refresh cycle.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 Checks now bloom at window's birth,
No longer tied to refresh's worth,
A timely hop, precise and clean,
Updates caught where they're first seen! ✨

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR reduces how often the Unity Editor window triggers package update checks by moving the update-check scheduling out of the frequent refresh path and into initial UI creation, addressing Issue #830’s report of repeated stalls.

Changes:

  • Schedule QueueUpdateCheck() during CreateGUI() (initial window build) instead of during RefreshAllData().
  • Stop triggering update checks from focus-driven refreshes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.


// Initial updates
RefreshAllData();
QueueUpdateCheck();
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

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

QueueUpdateCheck() ultimately calls PackageUpdateService.CheckForUpdate(), which performs synchronous WebClient.DownloadString network requests on the editor main thread. Even though it’s now only queued once per CreateGUI, users with poor connectivity can still experience long UI stalls when the delayCall runs. Consider running the update check off the main thread (or via UnityWebRequest/HttpClient with a short timeout + cancellation) and then marshaling the UI update back onto the main thread, so the editor stays responsive even when offline.

Suggested change
QueueUpdateCheck();
_ = Task.Run(() => QueueUpdateCheck());

Copilot uses AI. Check for mistakes.
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.

2 participants