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

fix(windows): correct window restoration behavior after minimization #4110

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

superDingda
Copy link

@superDingda superDingda commented Mar 4, 2025

Description

After maximizing the window and minimizing it, waking it up through the singleton does not restore maximization

Fixes #4109

Type of change

Please select the option that is relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Wails Doctor          
                                


# Wails
Version | v2.9.2

# System
┌─────────────────────────────────────────────────────────────────────────────────────────┐
| OS           | Windows 10 Enterprise                                                    |
| Version      | 2009 (Build: 22631)                                                      |
| ID           | 23H2                                                                     |
| Go Version   | go1.22.9                                                                 |
| Platform     | windows                                                                  |
| Architecture | amd64                                                                    |
| CPU          | 13th Gen Intel(R) Core(TM) i9-13900H                                     |
| GPU 1        | NVIDIA GeForce RTX 3050 4GB Laptop GPU (NVIDIA) - Driver: 31.0.15.2799   |
| GPU 2        | Intel(R) Iris(R) Xe Graphics (Intel Corporation) - Driver: 31.0.101.4575 |
| Memory       | 32GB                                                                     |
└─────────────────────────────────────────────────────────────────────────────────────────┘


# Diagnosis
Optional package(s) installation details:
  - upx : Available at https://upx.github.io/
  - nsis : More info at https://wails.io/docs/guides/windows-installer/

 SUCCESS  Your system is ready for Wails development!

 ♥   If Wails is useful to you or your company, please consider sponsoring the project:
https://github.com/sponsors/leaanthony
  • Windows
  • macOS
  • Linux

If you checked Linux, please specify the distro and version.

Test Configuration

Please paste the output of wails doctor. If you are unable to run this command, please describe your environment in as much detail as possible.

Checklist:

  • I have updated website/src/pages/changelog.mdx with details of this PR
  • My code follows the general coding style of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Summary by CodeRabbit

  • Bug Fixes
    • Updated window restoration behavior so that windows consistently become visible when activated, ensuring a more reliable user experience when re-opening or restoring from a minimized state.

Copy link
Contributor

coderabbitai bot commented Mar 4, 2025

Walkthrough

The change updates the Restore method in the Form struct located in v2/internal/frontend/desktop/windows/winc/form.go. Instead of using the SW_RESTORE flag to restore a minimized window to its previous state, the method now uses the SW_SHOW flag to simply display the window. There are no changes to any exported or public entities.

Changes

File Change Summary
v2/internal/…/winc/form.go Modified the Restore method to call w32.ShowWindow(fm.hwnd, w32.SW_SHOW) instead of w32.ShowWindow(fm.hwnd, w32.SW_RESTORE), altering window visibility.

Suggested reviewers

  • leanthony

Poem

I'm a bunny with a codey beat,
Hopping in changes, oh so neat.
The window now shines in plain sight,
No more restoring from a minimized night.
With a twitch of a whisker, our code feels right! 🐇✨


📜 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 fa4bf38 and 114c151.

📒 Files selected for processing (1)
  • v2/internal/frontend/desktop/windows/winc/form.go (1 hunks)
🔇 Additional comments (1)
v2/internal/frontend/desktop/windows/winc/form.go (1)

138-149: Appropriate fix for window restoration behavior.

The change from SW_RESTORE to SW_SHOW properly addresses the issue where a previously maximized window doesn't restore to its maximized state after minimization. This works because:

  1. The method already calls SendMessage with SC_RESTORE (lines 142-147) to restore the window from a minimized state
  2. Using SW_SHOW instead of SW_RESTORE ensures the window maintains its previous state (maximized or normal) rather than attempting to restore it again, which was causing the problem

This is a minimal change with maximum impact that correctly fixes issue #4109 without introducing side effects.

Here's why this approach is correct: In the Windows API, SC_RESTORE handles the window state transition from minimized to its previous state (maximized or normal). The subsequent ShowWindow call is now just ensuring visibility rather than forcing another state change, which maintains the window's proper dimensions.

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

@leaanthony
Copy link
Member

Thanks 🙏 Please could you add an entry to the changelog located at docs/src/content/docs/changelog.mdx? Thanks!

@leaanthony
Copy link
Member

Thanks 🙏 Please could you add an entry to the changelog located at website/src/pages/changelog.mdx?

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.

[v2]Abnormal behavior when restoring a minimized Wails window on Windows.
2 participants