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

Add disable zoom on mac #3289

Merged
merged 3 commits into from
Mar 2, 2024

Conversation

wizzymore
Copy link
Contributor

@wizzymore wizzymore commented Mar 1, 2024

Description

Add a new boolean inside mac.Options called DisableZoom, this setting will disable the green zoom button when the window is resizable.
Currently you can only disable the green zoom button by setting the window as "not resizable" and this is unwanted behaviour, prior to this PR you can't disable the button without disabling resizing.

I could add a test, but i don't know if this change is testable or if it is, how to test it.

Fixes #3288

Type of change

Please delete options that are not 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?

I tested the application by running all the possible configurations:

  • DisableResize: true & Frameless: false & DisableZoom: true ( does nothing new )

  • DisableResize: true & Frameless: true & DisableZoom: true ( does nothing new )

  • DisableResize: false & Frameless: false & DisableZoom: true ( the button is disabled )

  • DisableResize: false & Frameless: true & DisableZoom: true ( does nothing new )

  • Windows

  • macOS

  • Linux

Test Configuration

# Wails
Version | v2.8.0

# System
┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
| OS           | MacOS                                                                                                                       |
| Version      | 14.2.1                                                                                                                      |
| ID           | 23C71                                                                                                                       |
| Go Version   | go1.21.6                                                                                                                    |
| Platform     | darwin                                                                                                                      |
| Architecture | arm64                                                                                                                       |
| CPU          | Apple M2 Pro                                                                                                                |
| GPU          | Chipset Model: Apple M2 Pro Type: GPU Bus: Built-In Total Number of Cores: 16 Vendor: Apple (0x106b) Metal Support: Metal 3 |
| Memory       | 16GB                                                                                                                        |
└────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘

# Dependencies
┌───────────────────────────────────────────────────────────────────────┐
| Dependency                | Package Name | Status    | Version        |
| Xcode command line tools  | N/A          | Installed | 2405           |
| Nodejs                    | N/A          | Installed | 20.11.0        |
| npm                       | N/A          | Installed | 10.4.0         |
| *Xcode                    | N/A          | Installed | 15.2 (15C500b) |
| *upx                      | N/A          | Available |                |
| *nsis                     | N/A          | Available |                |
└─────────────────────── * - Optional Dependency ───────────────────────┘

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

  • New Features
    • Updated window creation functionality to include a zoomable option, replacing fullscreen.
  • Documentation
    • Added documentation for the new DisableZoom option to control window zoom on Mac.

Copy link
Contributor

coderabbitai bot commented Mar 1, 2024

Warning

Rate Limit Exceeded

@wizzymore has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 18 minutes and 27 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.
Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.
Please see our FAQ for further information.

Commits Files that changed from the base of the PR and between 4216cee and 916c3e8.

Walkthrough

The recent update introduces a feature allowing the disabling of the zoom button on macOS applications without affecting the window's resize capability. This enhancement is implemented through a new DisableZoom option under macOS-specific settings, affecting the window creation logic to accommodate the zoom functionality preference.

Changes

File Path Change Summary
v2/internal/frontend/desktop/darwin/Application.h, v2/internal/frontend/desktop/darwin/Application.m, v2/internal/frontend/desktop/darwin/WailsContext.h, v2/internal/frontend/desktop/darwin/WailsContext.m Updated window creation functions to replace resizable with zoomable.
v2/internal/frontend/desktop/darwin/window.go Added zoomable variable in NewWindow to control zoom functionality based on frontendOptions.Mac.DisableZoom.
v2/pkg/options/mac/mac.go Introduced DisableZoom field in the Options struct.
website/versioned_docs/version-v2.8.0/reference/options.mdx Added documentation for the DisableZoom option.
website/src/pages/changelog.mdx Implemented a new feature to include DisableZoom option for Mac in pull request #3289.

Assessment against linked issues

Objective Addressed Explanation
Add a way to disable the zoom button on Mac (#3288)

Poem

In the code where windows bloom,
A rabbit hopped into the room.
With a flip and a zoom toggle,
It whispered softly, "No more joggle."
🌟 "Let there be resize, but keep zoom at bay,
For the macOS windows, that's the way."
With a hop and a skip, it left with grace,
Leaving behind a more flexible space.

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>.
    • Generate unit-tests for this file.
  • 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 tests 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 generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link
Contributor

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

Review Status

Actionable comments generated: 3

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 3bf4ea5 and c49c3e5.
Files selected for processing (7)
  • v2/internal/frontend/desktop/darwin/Application.h (1 hunks)
  • v2/internal/frontend/desktop/darwin/Application.m (2 hunks)
  • v2/internal/frontend/desktop/darwin/WailsContext.h (1 hunks)
  • v2/internal/frontend/desktop/darwin/WailsContext.m (3 hunks)
  • v2/internal/frontend/desktop/darwin/window.go (2 hunks)
  • v2/pkg/options/mac/mac.go (1 hunks)
  • website/versioned_docs/version-v2.8.0/reference/options.mdx (2 hunks)
Additional comments: 4
v2/pkg/options/mac/mac.go (1)
  • 24-24: The addition of the DisableZoom boolean field to the Options struct is clear and aligns with the PR's objectives. Ensure that all usages of the Options struct across the codebase are updated to consider this new field where necessary.
v2/internal/frontend/desktop/darwin/WailsContext.h (1)
  • 67-67: The update to the CreateWindow method to include a zoomable parameter is consistent with the PR's objectives. Ensure that the implementation of this method and all calls to it correctly handle the new parameter.
Verification successful

To ensure a thorough verification, let's broaden the search to include all file types and adjust the search pattern to capture potential variations in how the CreateWindow method might be called or referenced. This approach will help us gather more information about the integration of the new zoomable parameter.


The verification process has confirmed that the zoomable parameter has been correctly integrated into the CreateWindow method for the Darwin platform, as evidenced by the method signature in WailsContext.h, its implementation in WailsContext.m, and the call in Application.m. This aligns with the objectives of providing more granular control over window zoom capabilities on macOS.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for calls to the CreateWindow method to ensure the new parameter is correctly used.
rg "CreateWindow\(" --type objc

Length of output: 33



Script:

#!/bin/bash
# Broaden the search to include all file types and adjust the pattern to capture potential variations in method calls or references.
rg "CreateWindow" 

Length of output: 4772

v2/internal/frontend/desktop/darwin/window.go (1)
  • 111-112: The logic to control the zoomable variable based on the DisableZoom option is correctly implemented. Ensure thorough testing of this functionality to confirm it behaves as expected under various configurations.
v2/internal/frontend/desktop/darwin/Application.m (1)
  • 17-17: The inclusion of the zoomable parameter in the Create function and its correct usage in the call to CreateWindow aligns with the PR's objectives. Verify the correct handling of this parameter throughout the codebase to ensure it functions as intended.
Verification successful

Given the lack of results from the initial search, let's broaden our approach to find how the zoomable parameter is handled in the codebase. We'll search for all occurrences of the zoomable parameter in Objective-C files.


The zoomable parameter is correctly included in the CreateWindow method signatures and is actively used in the window creation logic, as evidenced by its presence in both the header and implementation files (WailsContext.h and WailsContext.m), and its correct passing in the Create function within Application.m. This confirms that the changes related to the zoomable parameter have been correctly implemented across the relevant parts of the codebase.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for the implementation of CreateWindow to ensure the zoomable parameter is correctly handled.
rg "CreateWindow\(" --type objc

Length of output: 33



Script:

#!/bin/bash
# Search for all occurrences of the "zoomable" parameter in Objective-C files.
rg "zoomable" --type objc

Length of output: 3015

@@ -109,6 +109,7 @@ func main() {
Appearance: mac.NSAppearanceNameDarkAqua,
WebviewIsTransparent: true,
WindowIsTranslucent: false,
DisableZoom: false,
Copy link
Contributor

Choose a reason for hiding this comment

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

The addition of the DisableZoom option to the mac.Options struct is correctly documented. However, it would be beneficial to include a brief example of how to set this option in code, similar to other options documented in this file. This would provide developers with a clear, practical example of how to use the new feature.

Consider adding a code snippet demonstrating how to set the DisableZoom option to true or false within the mac.Options struct.

Comment on lines 187 to 196
[self.mainWindow setAppearance:nsAppearance];
}

if (!zoomable && resizable) {
NSButton *button = [self.mainWindow standardWindowButton:NSWindowZoomButton];
[button setEnabled: NO];
}

NSSize minSize = { minWidth, minHeight };
NSSize maxSize = { maxWidth, maxHeight };
Copy link
Contributor

Choose a reason for hiding this comment

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

📝 NOTE
This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [139-193]

The introduction of the zoomable parameter and the associated logic to disable the zoom button if zoomable is false is a well-implemented feature that directly addresses the PR objectives. However, there are a few considerations and potential improvements:

  1. Parameter Documentation: It's important to document the new zoomable parameter in the method's header comment (if applicable) to ensure that other developers understand its purpose and how it affects window behavior.

  2. Consistency with macOS Guidelines: Disabling the zoom button while allowing resizing is unconventional in macOS applications. Ensure this behavior aligns with macOS Human Interface Guidelines and consider how it might affect user expectations.

  3. Testing: The PR description mentions that unit tests for this feature have not been added due to questions about testability. While testing UI behavior can be challenging, consider exploring UI testing frameworks like XCTest for macOS that support automated UI tests. This could help ensure the feature works as expected across different macOS versions and configurations.

  4. Fallback for Non-resizable Windows: The logic correctly disables the zoom button only if the window is resizable. Consider adding a comment or documentation noting that this feature is intended for use with resizable windows, as the behavior might be unclear if zoomable is set to false for a non-resizable window.

Overall, the changes are aligned with the PR objectives and are a valuable addition to the Wails framework for macOS developers. Just ensure to address the considerations mentioned for documentation, testing, and adherence to macOS guidelines.

Copy link
Contributor

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between c49c3e5 and 4216cee.
Files selected for processing (1)
  • website/src/pages/changelog.mdx (1 hunks)
Additional comments: 1
website/src/pages/changelog.mdx (1)
  • 18-18: The addition of the DisableZoom option for macOS applications is clearly documented in the changelog. It's important to ensure that all relevant details about the new feature are included, such as its impact on existing functionality and any necessary steps for developers to utilize it. The current description seems concise and follows the established format of the changelog, which is good for maintaining consistency.

I see this file is ignore, but i think it's better to keep it up-to-date so if we ever unignore it will work correctly.
Copy link
Member

@leaanthony leaanthony left a comment

Choose a reason for hiding this comment

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

Thanks for this. Looks good 👍

@leaanthony leaanthony merged commit 5d22da4 into wailsapp:master Mar 2, 2024
8 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.

Add a way to disable the zoom button on mac
2 participants