Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions v3/UNRELEASED_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ After processing, the content will be moved to the main changelog and this file

## Fixed
<!-- Bug fixes -->
- Prevent macOS applications from crashing when replacing the application menu from a Wails callback
- macOS app activation now respects activation policy for regular apps only in [PR](https://github.com/wailsapp/wails/pull/5897) by @julianstorer
- Guard uninitialized GTK windows in Linux builds in [PR](https://github.com/wailsapp/wails/pull/5898) by @julianstorer
- Set explicit opaque background color for Linux WebKit windows before URL load in [PR](https://github.com/wailsapp/wails/pull/5899) by @julianstorer
Expand Down
14 changes: 13 additions & 1 deletion v3/pkg/application/application_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,19 @@ static void destroyApp(void) {
// Set the application menu
static void setApplicationMenu(void *menu) {
NSMenu *nsMenu = (__bridge NSMenu *)menu;
[NSApp setMainMenu:menu];
void (^apply)(void) = ^{
[NSApp setMainMenu:nsMenu];
};

// AppKit requires the main menu to be replaced on the main thread. Menu.Set
// may be called from Wails event listeners, which execute on worker
// goroutines, so marshal the update synchronously. Avoid dispatch_sync when
// already on the main thread because that would deadlock.
if ([NSThread isMainThread]) {
apply();
} else {
dispatch_sync(dispatch_get_main_queue(), apply);
}
}

// Get the application name
Expand Down
Loading