5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-03 02:50:36 +08:00

The application menu is now macOS only.

Fixed a `Parameter incorrect` error in Windows.
Updated Window example for mica/acrylic/tabbed windows.
This commit is contained in:
Lea Anthony 2025-02-03 20:08:31 +11:00
parent 0ecfcee3bf
commit 36a1b71f93
No known key found for this signature in database
GPG Key ID: 33DAF7BB90A58405
6 changed files with 81 additions and 61 deletions

View File

@ -29,6 +29,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Renamed Service methods: `Name` -> `ServiceName`, `OnStartup` -> `ServiceStartup`, `OnShutdown` -> `ServiceShutdown` by [@leaanthony](https://github.com/leaanthony)
- Moved `Path` and `Paths` methods to `application` package by [@leaanthony](https://github.com/leaanthony)
- The application menu is now macOS only by [@leaanthony](https://github.com/leaanthony)
### Added
@ -57,6 +58,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Change paths in windows Taskfile to forward slashes to ensure it works on non-Windows platforms by [@leaanthony](https://github.com/leaanthony)
- Mac + Mac JS events now fixed by [@leaanthony](https://github.com/leaanthony)
- Fixed event deadlock for macOS by [@leaanthony](https://github.com/leaanthony)
- Fixed a `Parameter incorrect` error in Window initialisation on Windows when HTML provided but no JS by [@leaanthony](https://github.com/leaanthony)
### Changed
@ -66,6 +68,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- ContextMenuData now returns a string instead of any by [@leaanthony](https://github.com/leaanthony)
- `application.NewService` does not accept options as an optional parameter anymore (use `application.NewServiceWithOptions` instead) by [@leaanthony](https://github.com/leaanthony) in [#4024](https://github.com/wailsapp/wails/pull/4024)
- Removed `nanoid` dependency by [@leaanthony](https://github.com/leaanthony)
- Updated Window example for mica/acrylic/tabbed window styles by [@leaanthony](https://github.com/leaanthony)
## v3.0.0-alpha.9 - 2025-01-13

View File

@ -228,11 +228,9 @@ Application menus are the menus that appear at the top of your application windo
### Application Menu Behaviour
When you set an application menu using `app.SetMenu()`, it becomes the default menu for all windows in your application. However, there are a few important behaviours to note:
When you set an application menu using `app.SetMenu()`, it becomes the main menu on macOS.
Menus are set on a pre-window basis for Windows/Linux.
1. **Global Application Menu**: The menu set via `app.SetMenu()` acts as the default menu for all windows.
2. **Per-Window Menu Override**: Individual windows can override the application menu by setting their own menu through window options:
```go
app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{
Title: "Custom Menu Window",
@ -242,16 +240,6 @@ app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{
})
```
3. **Disable Window Menu**: On Windows, you can disable a window's menu completely even when there's a global application menu:
```go
app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{
Title: "No Menu Window",
Windows: application.WindowsWindow{
DisableMenu: true, // Disable menu for this window
},
})
```
Here's a complete example showing these different menu behaviours:
```go
@ -267,15 +255,10 @@ func main() {
window.SetTitle("New Window")
})
// Set as application menu - default for all windows
// Set as application menu - this is for macOS
app.SetMenu(appMenu)
// Window with default application menu
app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{
Title: "Default Menu",
})
// Window with custom menu
// Window with custom menu on Windows
customMenu := application.NewMenu()
customMenu.Add("Custom Action")
app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{
@ -285,14 +268,6 @@ func main() {
},
})
// Window with no menu
app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{
Title: "No Menu",
Windows: application.WindowsWindow{
DisableMenu: true,
},
})
app.Run()
}
```

View File

@ -234,8 +234,7 @@ func main() {
OnClick(func(ctx *application.Context) {
app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{
Windows: application.WindowsWindow{
DisableMenu: true,
ExStyle: getExStyle(),
ExStyle: getExStyle(),
},
}).
SetTitle("WebviewWindow "+strconv.Itoa(windowCounter)).
@ -247,11 +246,7 @@ func main() {
}
myMenu.Add("New WebviewWindow (Listen to Move)").
OnClick(func(ctx *application.Context) {
w := app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{
Windows: application.WindowsWindow{
DisableMenu: true,
},
}).
w := app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{}).
SetTitle("WebviewWindow "+strconv.Itoa(windowCounter)).
SetRelativePosition(rand.Intn(1000), rand.Intn(800)).
SetURL("https://wails.io").
@ -264,11 +259,7 @@ func main() {
})
myMenu.Add("New WebviewWindow (Listen to Resize)").
OnClick(func(ctx *application.Context) {
w := app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{
Windows: application.WindowsWindow{
DisableMenu: true,
},
}).
w := app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{}).
SetTitle("WebviewWindow "+strconv.Itoa(windowCounter)).
SetRelativePosition(rand.Intn(1000), rand.Intn(800)).
SetURL("https://wails.io").
@ -389,7 +380,26 @@ func main() {
X: rand.Intn(1000),
Y: rand.Intn(800),
BackgroundType: application.BackgroundTypeTranslucent,
HTML: "<html style='background-color: rgba(0,0,0,0);'><body></body></html>",
HTML: `
<html style='background-color: rgba(0,0,0,0);'>
<head>
<style>
body {
background-color: rgba(0,0,0,0);
color: rgb(128, 128, 128);
font-family: sans-serif;
display: flex;
justify-content: center;
align-items: center;
}
</style>
</head>
<body>
<div>
<h2 style="text-align: center;">This is a Window with a Mica backdrop</h2>
</div>
</body>
</html>`,
Windows: application.WindowsWindow{
BackdropType: application.Mica,
},
@ -403,7 +413,26 @@ func main() {
X: rand.Intn(1000),
Y: rand.Intn(800),
BackgroundType: application.BackgroundTypeTranslucent,
HTML: "<html style='background-color: rgba(0,0,0,0);'><body></body></html>",
HTML: `
<html style='background-color: rgba(0,0,0,0);'>
<head>
<style>
body {
background-color: rgba(0,0,0,0);
color: rgb(128, 128, 128);
font-family: sans-serif;
display: flex;
justify-content: center;
align-items: center;
}
</style>
</head>
<body>
<div>
<h2 style="text-align: center;">This is a Window with an Acrylic backdrop</h2>
</div>
</body>
</html>`,
Windows: application.WindowsWindow{
BackdropType: application.Acrylic,
},
@ -417,7 +446,26 @@ func main() {
X: rand.Intn(1000),
Y: rand.Intn(800),
BackgroundType: application.BackgroundTypeTranslucent,
HTML: "<html style='background-color: rgba(0,0,0,0);'><body></body></html>",
HTML: `
<html style='background-color: rgba(0,0,0,0);'>
<head>
<style>
body {
background-color: rgba(0,0,0,0);
color: rgb(128, 128, 128);
font-family: sans-serif;
display: flex;
justify-content: center;
align-items: center;
}
</style>
</head>
<body>
<div>
<h2 style="text-align: center;">This is a Window with a Tabbed-effect backdrop</h2>
</div>
</body>
</html>`,
Windows: application.WindowsWindow{
BackdropType: application.Tabbed,
},
@ -686,6 +734,9 @@ func main() {
Mac: application.MacWindow{
DisableShadow: true,
},
Windows: application.WindowsWindow{
Menu: menu,
},
})
app.SetMenu(menu)

View File

@ -262,9 +262,6 @@ func (w *linuxWebviewWindow) run() {
app := getNativeApplication()
var menu = w.menu
if menu == nil && globalApplication.ApplicationMenu != nil {
menu = globalApplication.ApplicationMenu.Clone()
}
if menu != nil {
InvokeSync(func() {
menu.Update()

View File

@ -258,10 +258,6 @@ type WindowsWindow struct {
// Default: 0
WindowDidMoveDebounceMS uint16
// Disable the menu bar for this window
// Default: false
DisableMenu bool
// Event mapping for the window. This allows you to define a translation from one event to another.
// Default: nil
EventMapping map[events.WindowEventType]events.WindowEventType

View File

@ -305,15 +305,11 @@ func (w *windowsWebviewWindow) run() {
var appMenu w32.HMENU
// Process Menu
if !options.Windows.DisableMenu && !options.Frameless {
theMenu := globalApplication.ApplicationMenu
// Create the menu if we have one
if w.parent.options.Windows.Menu != nil {
theMenu = w.parent.options.Windows.Menu
}
if theMenu != nil {
theMenu.Update()
w.menu = NewApplicationMenu(w, theMenu)
if !options.Frameless {
userMenu := w.parent.options.Windows.Menu
if userMenu != nil {
userMenu.Update()
w.menu = NewApplicationMenu(w, userMenu)
w.menu.parentWindow = w
appMenu = w.menu.menu
}
@ -1758,7 +1754,9 @@ func (w *windowsWebviewWindow) setupChromium() {
if w.parent.options.CSS != "" {
script += fmt.Sprintf("; addEventListener(\"DOMContentLoaded\", (event) => { document.head.appendChild(document.createElement('style')).innerHTML=\"%s\"; });", strings.ReplaceAll(w.parent.options.CSS, `"`, `\"`))
}
chromium.Init(script)
if script != "" {
chromium.Init(script)
}
chromium.NavigateToString(w.parent.options.HTML)
} else {
startURL, err := assetserver.GetStartURL(w.parent.options.URL)