5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-02 23:51:44 +08:00

[v2, darwin] Add some missing default shortcuts (#2586)

* [v2, darwin] Add "Hide, Hide Others, Show All“ to appmenu

This also includes shortcuts support for those commands.
Arrange the menu items in the well known MacOS order.

* [v2, darwin] Add Window menu with well known shortcuts Minimize, Full-Screen and Zoom.
This commit is contained in:
stffabi 2023-04-20 12:38:32 +02:00 committed by GitHub
parent 529ec569f7
commit 0bf41090b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 38 additions and 9 deletions

View File

@ -12,5 +12,6 @@ typedef int Role;
static const Role AppMenu = 1; static const Role AppMenu = 1;
static const Role EditMenu = 2; static const Role EditMenu = 2;
static const Role WindowMenu = 3;
#endif /* Role_h */ #endif /* Role_h */

View File

@ -68,12 +68,20 @@
appName = [[NSProcessInfo processInfo] processName]; appName = [[NSProcessInfo processInfo] processName];
} }
WailsMenu *appMenu = [[[WailsMenu new] initWithNSTitle:appName] autorelease]; WailsMenu *appMenu = [[[WailsMenu new] initWithNSTitle:appName] autorelease];
if (ctx.aboutTitle != nil) {
[appMenu addItem:[self newMenuItemWithContext :ctx :[@"About " stringByAppendingString:appName] :@selector(About) :nil :0]];
[appMenu addItem:[NSMenuItem separatorItem]];
}
[appMenu addItem:[self newMenuItem:[@"Hide " stringByAppendingString:appName] :@selector(hide:) :@"h" :NSEventModifierFlagCommand]];
[appMenu addItem:[self newMenuItem:@"Hide Others" :@selector(hideOtherApplications:) :@"h" :(NSEventModifierFlagOption | NSEventModifierFlagCommand)]];
[appMenu addItem:[self newMenuItem:@"Show All" :@selector(unhideAllApplications:) :@""]];
[appMenu addItem:[NSMenuItem separatorItem]];
id quitTitle = [@"Quit " stringByAppendingString:appName]; id quitTitle = [@"Quit " stringByAppendingString:appName];
NSMenuItem* quitMenuItem = [self newMenuItem:quitTitle :@selector(Quit) :@"q" :NSEventModifierFlagCommand]; NSMenuItem* quitMenuItem = [self newMenuItem:quitTitle :@selector(Quit) :@"q" :NSEventModifierFlagCommand];
quitMenuItem.target = ctx; quitMenuItem.target = ctx;
if (ctx.aboutTitle != nil) {
[appMenu addItem:[self newMenuItemWithContext :ctx :[@"About " stringByAppendingString:appName] :@selector(About) :nil :0]];
}
[appMenu addItem:quitMenuItem]; [appMenu addItem:quitMenuItem];
[self appendSubmenu:appMenu]; [self appendSubmenu:appMenu];
break; break;
@ -100,6 +108,17 @@
[editMenu appendSubmenu:speechMenu]; [editMenu appendSubmenu:speechMenu];
[self appendSubmenu:editMenu]; [self appendSubmenu:editMenu];
break;
}
case WindowMenu:
{
WailsMenu *windowMenu = [[[WailsMenu new] initWithNSTitle:@"Window"] autorelease];
[windowMenu addItem:[self newMenuItem:@"Minimize" :@selector(performMiniaturize:) :@"m" :NSEventModifierFlagCommand]];
[windowMenu addItem:[self newMenuItem:@"Zoom" :@selector(performZoom:) :@""]];
[windowMenu addItem:[NSMenuItem separatorItem]];
[windowMenu addItem:[self newMenuItem:@"Full Screen" :@selector(enterFullScreenMode:) :@"f" :(NSEventModifierFlagControl | NSEventModifierFlagCommand)]];
[self appendSubmenu:windowMenu];
break; break;
} }
} }

View File

@ -8,8 +8,9 @@ type Role int
// These constants need to be kept in sync with `v2/internal/frontend/desktop/darwin/Role.h` // These constants need to be kept in sync with `v2/internal/frontend/desktop/darwin/Role.h`
const ( const (
AppMenuRole Role = 1 AppMenuRole Role = 1
EditMenuRole = 2 EditMenuRole = 2
WindowMenuRole = 3
//AboutRole Role = "about" //AboutRole Role = "about"
//UndoRole Role = "undo" //UndoRole Role = "undo"
//RedoRole Role = "redo" //RedoRole Role = "redo"
@ -142,14 +143,16 @@ func ViewMenu() *MenuItem {
Role: ViewMenuRole, Role: ViewMenuRole,
} }
} }
*/
// WindowMenu provides a MenuItem with the whole default "Window" menu (Minimize, Zoom, etc.). // WindowMenu provides a MenuItem with the whole default "Window" menu (Minimize, Zoom, etc.).
// On MacOS currently all options in there won't work if the window is frameless.
func WindowMenu() *MenuItem { func WindowMenu() *MenuItem {
return &MenuItem{ return &MenuItem{
Role: WindowMenuRole, Role: WindowMenuRole,
} }
} }
*/
// These roles are Mac only // These roles are Mac only
// AppMenu provides a MenuItem with the whole default "App" menu (About, Services, etc.) // AppMenu provides a MenuItem with the whole default "App" menu (About, Services, etc.)

View File

@ -160,10 +160,14 @@ func processMenus(appoptions *App) {
switch runtime.GOOS { switch runtime.GOOS {
case "darwin": case "darwin":
if appoptions.Menu == nil { if appoptions.Menu == nil {
appoptions.Menu = menu.NewMenuFromItems( items := []*menu.MenuItem{
menu.AppMenu(),
menu.EditMenu(), menu.EditMenu(),
) }
if !appoptions.Frameless {
items = append(items, menu.WindowMenu()) // Current options in Window Menu only work if not frameless
}
appoptions.Menu = menu.NewMenuFromItems(menu.AppMenu(), items...)
} }
} }
} }

View File

@ -22,6 +22,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added Nodejs version in `wails doctor`. Added by @misitebao in [PR](https://github.com/wailsapp/wails/pull/2546) - Added Nodejs version in `wails doctor`. Added by @misitebao in [PR](https://github.com/wailsapp/wails/pull/2546)
- Added support for WebKit2GTK 2.40+ on Linux. This brings additional features for the [AssetServer](/docs/reference/options#assetserver), like support for HTTP Request Bodies. The app must be compiled with the Go build tag `webkit2_40` to activate support for this features. This also bumps the minimum requirement of WebKit2GTK to 2.40 for your app. Added by @stffabi in this [PR](https://github.com/wailsapp/wails/pull/2592) - Added support for WebKit2GTK 2.40+ on Linux. This brings additional features for the [AssetServer](/docs/reference/options#assetserver), like support for HTTP Request Bodies. The app must be compiled with the Go build tag `webkit2_40` to activate support for this features. This also bumps the minimum requirement of WebKit2GTK to 2.40 for your app. Added by @stffabi in this [PR](https://github.com/wailsapp/wails/pull/2592)
- macOS: Added Window menu role with well known shortcuts "Minimize, Full-Screen and Zoom". Added by @stffabi in [PR](https://github.com/wailsapp/wails/pull/2586)
- macOS: Added "Hide, Hide Others, Show All“ to appmenu. Added by @stffabi in [PR](https://github.com/wailsapp/wails/pull/2586)
### Changed ### Changed