mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-04 03:59:59 +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:
parent
0ecfcee3bf
commit
36a1b71f93
@ -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)
|
- 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)
|
- 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
|
### 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)
|
- 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)
|
- Mac + Mac JS events now fixed by [@leaanthony](https://github.com/leaanthony)
|
||||||
- Fixed event deadlock for macOS 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
|
### 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)
|
- 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)
|
- `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)
|
- 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
|
## v3.0.0-alpha.9 - 2025-01-13
|
||||||
|
|
||||||
|
@ -228,11 +228,9 @@ Application menus are the menus that appear at the top of your application windo
|
|||||||
|
|
||||||
### Application Menu Behaviour
|
### 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
|
```go
|
||||||
app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{
|
app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{
|
||||||
Title: "Custom Menu Window",
|
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:
|
Here's a complete example showing these different menu behaviours:
|
||||||
|
|
||||||
```go
|
```go
|
||||||
@ -267,15 +255,10 @@ func main() {
|
|||||||
window.SetTitle("New Window")
|
window.SetTitle("New Window")
|
||||||
})
|
})
|
||||||
|
|
||||||
// Set as application menu - default for all windows
|
// Set as application menu - this is for macOS
|
||||||
app.SetMenu(appMenu)
|
app.SetMenu(appMenu)
|
||||||
|
|
||||||
// Window with default application menu
|
// Window with custom menu on Windows
|
||||||
app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{
|
|
||||||
Title: "Default Menu",
|
|
||||||
})
|
|
||||||
|
|
||||||
// Window with custom menu
|
|
||||||
customMenu := application.NewMenu()
|
customMenu := application.NewMenu()
|
||||||
customMenu.Add("Custom Action")
|
customMenu.Add("Custom Action")
|
||||||
app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{
|
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()
|
app.Run()
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
@ -234,7 +234,6 @@ func main() {
|
|||||||
OnClick(func(ctx *application.Context) {
|
OnClick(func(ctx *application.Context) {
|
||||||
app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{
|
app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{
|
||||||
Windows: application.WindowsWindow{
|
Windows: application.WindowsWindow{
|
||||||
DisableMenu: true,
|
|
||||||
ExStyle: getExStyle(),
|
ExStyle: getExStyle(),
|
||||||
},
|
},
|
||||||
}).
|
}).
|
||||||
@ -247,11 +246,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
myMenu.Add("New WebviewWindow (Listen to Move)").
|
myMenu.Add("New WebviewWindow (Listen to Move)").
|
||||||
OnClick(func(ctx *application.Context) {
|
OnClick(func(ctx *application.Context) {
|
||||||
w := app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{
|
w := app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{}).
|
||||||
Windows: application.WindowsWindow{
|
|
||||||
DisableMenu: true,
|
|
||||||
},
|
|
||||||
}).
|
|
||||||
SetTitle("WebviewWindow "+strconv.Itoa(windowCounter)).
|
SetTitle("WebviewWindow "+strconv.Itoa(windowCounter)).
|
||||||
SetRelativePosition(rand.Intn(1000), rand.Intn(800)).
|
SetRelativePosition(rand.Intn(1000), rand.Intn(800)).
|
||||||
SetURL("https://wails.io").
|
SetURL("https://wails.io").
|
||||||
@ -264,11 +259,7 @@ func main() {
|
|||||||
})
|
})
|
||||||
myMenu.Add("New WebviewWindow (Listen to Resize)").
|
myMenu.Add("New WebviewWindow (Listen to Resize)").
|
||||||
OnClick(func(ctx *application.Context) {
|
OnClick(func(ctx *application.Context) {
|
||||||
w := app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{
|
w := app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{}).
|
||||||
Windows: application.WindowsWindow{
|
|
||||||
DisableMenu: true,
|
|
||||||
},
|
|
||||||
}).
|
|
||||||
SetTitle("WebviewWindow "+strconv.Itoa(windowCounter)).
|
SetTitle("WebviewWindow "+strconv.Itoa(windowCounter)).
|
||||||
SetRelativePosition(rand.Intn(1000), rand.Intn(800)).
|
SetRelativePosition(rand.Intn(1000), rand.Intn(800)).
|
||||||
SetURL("https://wails.io").
|
SetURL("https://wails.io").
|
||||||
@ -389,7 +380,26 @@ func main() {
|
|||||||
X: rand.Intn(1000),
|
X: rand.Intn(1000),
|
||||||
Y: rand.Intn(800),
|
Y: rand.Intn(800),
|
||||||
BackgroundType: application.BackgroundTypeTranslucent,
|
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{
|
Windows: application.WindowsWindow{
|
||||||
BackdropType: application.Mica,
|
BackdropType: application.Mica,
|
||||||
},
|
},
|
||||||
@ -403,7 +413,26 @@ func main() {
|
|||||||
X: rand.Intn(1000),
|
X: rand.Intn(1000),
|
||||||
Y: rand.Intn(800),
|
Y: rand.Intn(800),
|
||||||
BackgroundType: application.BackgroundTypeTranslucent,
|
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{
|
Windows: application.WindowsWindow{
|
||||||
BackdropType: application.Acrylic,
|
BackdropType: application.Acrylic,
|
||||||
},
|
},
|
||||||
@ -417,7 +446,26 @@ func main() {
|
|||||||
X: rand.Intn(1000),
|
X: rand.Intn(1000),
|
||||||
Y: rand.Intn(800),
|
Y: rand.Intn(800),
|
||||||
BackgroundType: application.BackgroundTypeTranslucent,
|
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{
|
Windows: application.WindowsWindow{
|
||||||
BackdropType: application.Tabbed,
|
BackdropType: application.Tabbed,
|
||||||
},
|
},
|
||||||
@ -686,6 +734,9 @@ func main() {
|
|||||||
Mac: application.MacWindow{
|
Mac: application.MacWindow{
|
||||||
DisableShadow: true,
|
DisableShadow: true,
|
||||||
},
|
},
|
||||||
|
Windows: application.WindowsWindow{
|
||||||
|
Menu: menu,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
app.SetMenu(menu)
|
app.SetMenu(menu)
|
||||||
|
@ -262,9 +262,6 @@ func (w *linuxWebviewWindow) run() {
|
|||||||
app := getNativeApplication()
|
app := getNativeApplication()
|
||||||
|
|
||||||
var menu = w.menu
|
var menu = w.menu
|
||||||
if menu == nil && globalApplication.ApplicationMenu != nil {
|
|
||||||
menu = globalApplication.ApplicationMenu.Clone()
|
|
||||||
}
|
|
||||||
if menu != nil {
|
if menu != nil {
|
||||||
InvokeSync(func() {
|
InvokeSync(func() {
|
||||||
menu.Update()
|
menu.Update()
|
||||||
|
@ -258,10 +258,6 @@ type WindowsWindow struct {
|
|||||||
// Default: 0
|
// Default: 0
|
||||||
WindowDidMoveDebounceMS uint16
|
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.
|
// Event mapping for the window. This allows you to define a translation from one event to another.
|
||||||
// Default: nil
|
// Default: nil
|
||||||
EventMapping map[events.WindowEventType]events.WindowEventType
|
EventMapping map[events.WindowEventType]events.WindowEventType
|
||||||
|
@ -305,15 +305,11 @@ func (w *windowsWebviewWindow) run() {
|
|||||||
var appMenu w32.HMENU
|
var appMenu w32.HMENU
|
||||||
|
|
||||||
// Process Menu
|
// Process Menu
|
||||||
if !options.Windows.DisableMenu && !options.Frameless {
|
if !options.Frameless {
|
||||||
theMenu := globalApplication.ApplicationMenu
|
userMenu := w.parent.options.Windows.Menu
|
||||||
// Create the menu if we have one
|
if userMenu != nil {
|
||||||
if w.parent.options.Windows.Menu != nil {
|
userMenu.Update()
|
||||||
theMenu = w.parent.options.Windows.Menu
|
w.menu = NewApplicationMenu(w, userMenu)
|
||||||
}
|
|
||||||
if theMenu != nil {
|
|
||||||
theMenu.Update()
|
|
||||||
w.menu = NewApplicationMenu(w, theMenu)
|
|
||||||
w.menu.parentWindow = w
|
w.menu.parentWindow = w
|
||||||
appMenu = w.menu.menu
|
appMenu = w.menu.menu
|
||||||
}
|
}
|
||||||
@ -1758,7 +1754,9 @@ func (w *windowsWebviewWindow) setupChromium() {
|
|||||||
if w.parent.options.CSS != "" {
|
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, `"`, `\"`))
|
script += fmt.Sprintf("; addEventListener(\"DOMContentLoaded\", (event) => { document.head.appendChild(document.createElement('style')).innerHTML=\"%s\"; });", strings.ReplaceAll(w.parent.options.CSS, `"`, `\"`))
|
||||||
}
|
}
|
||||||
|
if script != "" {
|
||||||
chromium.Init(script)
|
chromium.Init(script)
|
||||||
|
}
|
||||||
chromium.NavigateToString(w.parent.options.HTML)
|
chromium.NavigateToString(w.parent.options.HTML)
|
||||||
} else {
|
} else {
|
||||||
startURL, err := assetserver.GetStartURL(w.parent.options.URL)
|
startURL, err := assetserver.GetStartURL(w.parent.options.URL)
|
||||||
|
Loading…
Reference in New Issue
Block a user