Skip to content

Fix issue that mainVM fails to work #3296

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

Closed

Conversation

Jack251970
Copy link
Member

From #3275.

We should not create MainViewModel when creating API instance in constructor because it can cause unknown issue that makes all functions related to _mainVM in API instance cannot work.

Test

Originally (Tested in VMWare, installed latest dev branch version 65f85cf)

2025-02-28.15-59-05.mp4

Because installing & uninstalling plugins need _mainVM to ChangeQuery and ShowWindow so nothing happens when _mainVM fails to work.

After

@prlabeler prlabeler bot added the bug Something isn't working label Feb 28, 2025
Copy link

@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.

Copy link

gitstream-cm bot commented Feb 28, 2025

🥷 Code experts: no user but you matched threshold 10

Jack251970 has most 👩‍💻 activity in the files.
Jack251970 has most 🧠 knowledge in the files.

See details

Flow.Launcher/App.xaml.cs

Activity based on git-commit:

Jack251970
FEB 79 additions & 40 deletions
JAN 86 additions & 66 deletions
DEC
NOV
OCT
SEP

Knowledge based on git-blame:
Jack251970: 37%

Flow.Launcher/PublicAPIInstance.cs

Activity based on git-commit:

Jack251970
FEB 24 additions & 3 deletions
JAN 45 additions & 47 deletions
DEC 25 additions & 32 deletions
NOV 16 additions & 0 deletions
OCT
SEP

Knowledge based on git-blame:
Jack251970: 17%

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

Copy link

gitstream-cm bot commented Feb 28, 2025

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 Feb 28, 2025

📝 Walkthrough

Walkthrough

The pull request updates the initialization flow of the application by decoupling the MainViewModel assignment from the constructor of the PublicAPIInstance. In the startup method of the application, the PublicAPIInstance is explicitly initialized with the MainViewModel via an added method call. Simultaneously, the PublicAPIInstance class is refactored to allow delayed assignment of its MainViewModel field. No other parts of the control flow or public declarations have been modified.

Changes

File(s) Change Summary
Flow.Launcher/App.xaml.cs Added ((PublicAPIInstance)API).Initialize(mainVM); in the OnStartupAsync method to initialize the public API with the main view model.
Flow.Launcher/PublicAPIInstance.cs Removed MainViewModel parameter from the constructor, changed _mainVM from readonly to a mutable field, and added Initialize(MainViewModel mainVM) for delayed initialization.

Sequence Diagram(s)

sequenceDiagram
    participant App as Application
    participant API as PublicAPIInstance
    participant MainVM as MainViewModel

    App->>API: OnStartupAsync()
    App->>API: Initialize(mainVM)
    API->>API: Set _mainVM = mainVM
Loading

Possibly related PRs

Suggested labels

5 min review

Suggested reviewers

  • jjw24
  • taooceros

Poem

Hop along, dear coder, with a skip and a cheer,
Our MainVM now joins the startup frontier.
The PublicAPI awakens with a fresh, bright glow,
Delayed yet deliberate — ready, set, go!
Scribbling lines of logic with each joyful twitch,
A rabbit’s code dance, in every ASCII glitch!


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 65f85cf and 2e516a9.

📒 Files selected for processing (2)
  • Flow.Launcher/App.xaml.cs (1 hunks)
  • Flow.Launcher/PublicAPIInstance.cs (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
🔇 Additional comments (4)
Flow.Launcher/App.xaml.cs (1)

138-138: Proper initialization of API with MainViewModel.

This added line correctly initializes the PublicAPIInstance with the MainViewModel after both have been fully created. This change addresses the core issue described in the PR objectives where mainVM was failing to work when initialized during API instance construction.

Flow.Launcher/PublicAPIInstance.cs (3)

37-37: Field properly modified to support delayed initialization.

Removing the readonly modifier is necessary to allow the MainViewModel to be assigned after the PublicAPIInstance is constructed, which is the core fix for this issue.


41-46: Constructor appropriately simplified.

The constructor no longer takes a MainViewModel parameter, which prevents the premature initialization that was causing the issues mentioned in the PR objectives.


48-52: Good addition of the Initialize method with clear documentation.

The new Initialize method provides a clean way to set the MainViewModel after both the API instance and MainViewModel are fully initialized. The comment clearly explains why this approach is necessary.

✨ Finishing Touches
  • 📝 Generate Docstrings

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

@Jack251970
Copy link
Member Author

@taooceros Hello, after testing on a fresh Windows system, I have confirmed that the issue occurs consistently. Earlier, you mentioned you couldn’t reproduce the behavior, and I initially suspected it might be specific to my system. However, it appears to be a broader issue.

@taooceros
Copy link
Member

yeah I think I could reproduce now. Maybe previously the version is messed up. Sorry for the confusion.

@taooceros
Copy link
Member

How about we firstly create the mainviewmodel and pass that instance to the dependency injection. Would that also fix the issue?

@Jack251970
Copy link
Member Author

Let me check. IIRC, it cannot fix this issue.

@Jack251970
Copy link
Member Author

How about we firstly create the mainviewmodel and pass that instance to the dependency injection. Would that also fix the issue?

No, we cannot do that. Because Updater will call API construction firstly.

.AddSingleton(sp => new Updater(sp.GetRequiredService<IPublicAPI>(), Launcher.Properties.Settings.Default.GithubRepo))

@Jack251970
Copy link
Member Author

I tried this but it cannot help.

image

@taooceros
Copy link
Member

taooceros commented Feb 28, 2025

I think it's important to understand why this is happening. Does this problem happen when build with VS?

@Jack251970
Copy link
Member Author

I am still checking.

@Jack251970
Copy link
Member Author

I think it's important to understand why this is happening. Does this problem happen when build with VS?

Yes.

@taooceros
Copy link
Member

I think it's important to understand why this is happening. Does this problem happen when build with VS?

Yes.

That's good, so we don't have to test the appveyor build to understand why. I need to be afk for a while.

@Jack251970
Copy link
Member Author

I think it's important to understand why this is happening. Does this problem happen when build with VS?

Yes.

That's good, so we don't have to test the appveyor build to understand why. I need to be afk for a while.

Certainly! For now I found that PublicAPIInstance is created twice, and I will keep you informed of any progress or updates.

@taooceros
Copy link
Member

I think it's important to understand why this is happening. Does this problem happen when build with VS?

Yes.

That's good, so we don't have to test the appveyor build to understand why. I need to be afk for a while.

Certainly! For now I found that PublicAPIInstance is created twice, and I will keep you informed of any progress or updates.

Oh if that's the case then things can certainly goes wrong. It can link to the wrong publicapiinstance (which associate with a wrong mainviewmodel), which causes the problem. Let's try to figure out where's the problem.

@Jack251970
Copy link
Member Author

I think it's important to understand why this is happening. Does this problem happen when build with VS?

Yes.

That's good, so we don't have to test the appveyor build to understand why. I need to be afk for a while.

Certainly! For now I found that PublicAPIInstance is created twice, and I will keep you informed of any progress or updates.

Oh if that's the case then things can certainly goes wrong. It can link to the wrong publicapiinstance (which associate with a wrong mainviewmodel), which causes the problem. Let's try to figure out where's the problem.

Ok, I found the reason. PluginManager uses static property for API initialization which creates one more instance.

I will close this PR, and create a new one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants