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
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion v2/internal/frontend/desktop/darwin/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#define WindowStartsMinimised 2
#define WindowStartsFullscreen 3

WailsContext* Create(const char* title, int width, int height, int frameless, int resizable, int fullscreen, int fullSizeContent, int hideTitleBar, int titlebarAppearsTransparent, int hideTitle, int useToolbar, int hideToolbarSeparator, int webviewIsTransparent, int alwaysOnTop, int hideWindowOnClose, const char *appearance, int windowIsTranslucent, int devtoolsEnabled, int defaultContextMenuEnabled, int windowStartState, int startsHidden, int minWidth, int minHeight, int maxWidth, int maxHeight, bool fraudulentWebsiteWarningEnabled, struct Preferences preferences, int singleInstanceEnabled, const char* singleInstanceUniqueId);
WailsContext* Create(const char* title, int width, int height, int frameless, int resizable, int zoomable, int fullscreen, int fullSizeContent, int hideTitleBar, int titlebarAppearsTransparent, int hideTitle, int useToolbar, int hideToolbarSeparator, int webviewIsTransparent, int alwaysOnTop, int hideWindowOnClose, const char *appearance, int windowIsTranslucent, int devtoolsEnabled, int defaultContextMenuEnabled, int windowStartState, int startsHidden, int minWidth, int minHeight, int maxWidth, int maxHeight, bool fraudulentWebsiteWarningEnabled, struct Preferences preferences, int singleInstanceEnabled, const char* singleInstanceUniqueId);
wizzymore marked this conversation as resolved.
Show resolved Hide resolved
void Run(void*, const char* url);

void SetTitle(void* ctx, const char *title);
Expand Down
4 changes: 2 additions & 2 deletions v2/internal/frontend/desktop/darwin/Application.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#import "WailsMenu.h"
#import "WailsMenuItem.h"

WailsContext* Create(const char* title, int width, int height, int frameless, int resizable, int fullscreen, int fullSizeContent, int hideTitleBar, int titlebarAppearsTransparent, int hideTitle, int useToolbar, int hideToolbarSeparator, int webviewIsTransparent, int alwaysOnTop, int hideWindowOnClose, const char *appearance, int windowIsTranslucent, int devtoolsEnabled, int defaultContextMenuEnabled, int windowStartState, int startsHidden, int minWidth, int minHeight, int maxWidth, int maxHeight, bool fraudulentWebsiteWarningEnabled, struct Preferences preferences, int singleInstanceLockEnabled, const char* singleInstanceUniqueId) {
WailsContext* Create(const char* title, int width, int height, int frameless, int resizable, int zoomable, int fullscreen, int fullSizeContent, int hideTitleBar, int titlebarAppearsTransparent, int hideTitle, int useToolbar, int hideToolbarSeparator, int webviewIsTransparent, int alwaysOnTop, int hideWindowOnClose, const char *appearance, int windowIsTranslucent, int devtoolsEnabled, int defaultContextMenuEnabled, int windowStartState, int startsHidden, int minWidth, int minHeight, int maxWidth, int maxHeight, bool fraudulentWebsiteWarningEnabled, struct Preferences preferences, int singleInstanceLockEnabled, const char* singleInstanceUniqueId) {

[NSApplication sharedApplication];

Expand All @@ -27,7 +27,7 @@
fullscreen = 1;
}

[result CreateWindow:width :height :frameless :resizable :fullscreen :fullSizeContent :hideTitleBar :titlebarAppearsTransparent :hideTitle :useToolbar :hideToolbarSeparator :webviewIsTransparent :hideWindowOnClose :safeInit(appearance) :windowIsTranslucent :minWidth :minHeight :maxWidth :maxHeight :fraudulentWebsiteWarningEnabled :preferences];
[result CreateWindow:width :height :frameless :resizable :zoomable :fullscreen :fullSizeContent :hideTitleBar :titlebarAppearsTransparent :hideTitle :useToolbar :hideToolbarSeparator :webviewIsTransparent :hideWindowOnClose :safeInit(appearance) :windowIsTranslucent :minWidth :minHeight :maxWidth :maxHeight :fraudulentWebsiteWarningEnabled :preferences];
[result SetTitle:safeInit(title)];
[result Center];

Expand Down
2 changes: 1 addition & 1 deletion v2/internal/frontend/desktop/darwin/WailsContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ struct Preferences {
bool *fullscreenEnabled;
};

- (void) CreateWindow:(int)width :(int)height :(bool)frameless :(bool)resizable :(bool)fullscreen :(bool)fullSizeContent :(bool)hideTitleBar :(bool)titlebarAppearsTransparent :(bool)hideTitle :(bool)useToolbar :(bool)hideToolbarSeparator :(bool)webviewIsTransparent :(bool)hideWindowOnClose :(NSString *)appearance :(bool)windowIsTranslucent :(int)minWidth :(int)minHeight :(int)maxWidth :(int)maxHeight :(bool)fraudulentWebsiteWarningEnabled :(struct Preferences)preferences;
- (void) CreateWindow:(int)width :(int)height :(bool)frameless :(bool)resizable :(bool)zoomable :(bool)fullscreen :(bool)fullSizeContent :(bool)hideTitleBar :(bool)titlebarAppearsTransparent :(bool)hideTitle :(bool)useToolbar :(bool)hideToolbarSeparator :(bool)webviewIsTransparent :(bool)hideWindowOnClose :(NSString *)appearance :(bool)windowIsTranslucent :(int)minWidth :(int)minHeight :(int)maxWidth :(int)maxHeight :(bool)fraudulentWebsiteWarningEnabled :(struct Preferences)preferences;
- (void) SetSize:(int)width :(int)height;
- (void) SetPosition:(int)x :(int) y;
- (void) SetMinSize:(int)minWidth :(int)minHeight;
Expand Down
7 changes: 5 additions & 2 deletions v2/internal/frontend/desktop/darwin/WailsContext.m
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ - (BOOL) isFullscreen {
return NO;
}

- (void) CreateWindow:(int)width :(int)height :(bool)frameless :(bool)resizable :(bool)fullscreen :(bool)fullSizeContent :(bool)hideTitleBar :(bool)titlebarAppearsTransparent :(bool)hideTitle :(bool)useToolbar :(bool)hideToolbarSeparator :(bool)webviewIsTransparent :(bool)hideWindowOnClose :(NSString*)appearance :(bool)windowIsTranslucent :(int)minWidth :(int)minHeight :(int)maxWidth :(int)maxHeight :(bool)fraudulentWebsiteWarningEnabled :(struct Preferences)preferences {
- (void) CreateWindow:(int)width :(int)height :(bool)frameless :(bool)resizable :(bool)zoomable :(bool)fullscreen :(bool)fullSizeContent :(bool)hideTitleBar :(bool)titlebarAppearsTransparent :(bool)hideTitle :(bool)useToolbar :(bool)hideToolbarSeparator :(bool)webviewIsTransparent :(bool)hideWindowOnClose :(NSString*)appearance :(bool)windowIsTranslucent :(int)minWidth :(int)minHeight :(int)maxWidth :(int)maxHeight :(bool)fraudulentWebsiteWarningEnabled :(struct Preferences)preferences {
NSWindowStyleMask styleMask = 0;

if( !frameless ) {
Expand All @@ -158,7 +158,6 @@ - (void) CreateWindow:(int)width :(int)height :(bool)frameless :(bool)resizable

self.mainWindow = [[WailsWindow alloc] initWithContentRect:NSMakeRect(0, 0, width, height)
styleMask:styleMask backing:NSBackingStoreBuffered defer:NO];

if (!frameless && useToolbar) {
id toolbar = [[NSToolbar alloc] initWithIdentifier:@"wails.toolbar"];
[toolbar autorelease];
Expand Down Expand Up @@ -188,6 +187,10 @@ - (void) CreateWindow:(int)width :(int)height :(bool)frameless :(bool)resizable
[self.mainWindow setAppearance:nsAppearance];
}

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

NSSize minSize = { minWidth, minHeight };
NSSize maxSize = { maxWidth, maxHeight };
Comment on lines 187 to 196
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.

Expand Down
6 changes: 4 additions & 2 deletions v2/internal/frontend/desktop/darwin/window.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func NewWindow(frontendOptions *options.App, debug bool, devtools bool) *Window
defaultContextMenuEnabled := bool2Cint(debug || frontendOptions.EnableDefaultContextMenu)
singleInstanceEnabled := bool2Cint(frontendOptions.SingleInstanceLock != nil)

var fullSizeContent, hideTitleBar, hideTitle, useToolbar, webviewIsTransparent C.int
var fullSizeContent, hideTitleBar, zoomable, hideTitle, useToolbar, webviewIsTransparent C.int
var titlebarAppearsTransparent, hideToolbarSeparator, windowIsTranslucent C.int
var appearance, title *C.char
var preferences C.struct_Preferences
Expand Down Expand Up @@ -108,12 +108,14 @@ func NewWindow(frontendOptions *options.App, debug bool, devtools bool) *Window
}
}

zoomable = bool2Cint(!frontendOptions.Mac.DisableZoom)

windowIsTranslucent = bool2Cint(mac.WindowIsTranslucent)
webviewIsTransparent = bool2Cint(mac.WebviewIsTransparent)

appearance = c.String(string(mac.Appearance))
}
var context *C.WailsContext = C.Create(title, width, height, frameless, resizable, fullscreen, fullSizeContent,
var context *C.WailsContext = C.Create(title, width, height, frameless, resizable, zoomable, fullscreen, fullSizeContent,
hideTitleBar, titlebarAppearsTransparent, hideTitle, useToolbar, hideToolbarSeparator, webviewIsTransparent,
alwaysOnTop, hideWindowOnClose, appearance, windowIsTranslucent, devtoolsEnabled, defaultContextMenuEnabled,
windowStartState, startsHidden, minWidth, minHeight, maxWidth, maxHeight, enableFraudulentWebsiteWarnings,
Expand Down
1 change: 1 addition & 0 deletions v2/pkg/options/mac/mac.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type Options struct {
WebviewIsTransparent bool
WindowIsTranslucent bool
Preferences *Preferences
DisableZoom bool
// ActivationPolicy ActivationPolicy
About *AboutInfo
OnFileOpen func(filePath string) `json:"-"`
Expand Down
8 changes: 8 additions & 0 deletions website/versioned_docs/version-v2.8.0/reference/options.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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.

About: &mac.AboutInfo{
Title: "My Application",
Message: "© 2021 Me",
Expand Down Expand Up @@ -897,6 +898,13 @@ Mac: &mac.Options{
}
```

#### DisableZoom

By default, the window is zoomable. Setting this to `true` will disable the zoom button (green button).

Name: DisableZoom<br/>
Type: `bool`

#### About

This configuration lets you set the title, message and icon for the "About" menu item in the app menu created by the "AppMenu" role.
Expand Down