More macOS menu bar improvements

This commit is contained in:
Wojtek Mach 2022-03-30 13:57:24 +02:00
parent c5152eb941
commit 108b40651d

View file

@ -41,12 +41,12 @@ if Mix.target() == :app do
wx = :wx.new() wx = :wx.new()
frame = :wxFrame.new(wx, -1, app_name, size: size) frame = :wxFrame.new(wx, -1, app_name, size: size)
:wxFrame.show(frame)
if os == :macos do if os == :macos do
fixup_macos_menubar(frame, app_name) fixup_macos_menubar(frame, app_name)
end end
:wxFrame.show(frame)
:wxFrame.connect(frame, :command_menu_selected, skip: true) :wxFrame.connect(frame, :command_menu_selected, skip: true)
:wxFrame.connect(frame, :close_window, skip: true) :wxFrame.connect(frame, :close_window, skip: true)
@ -122,8 +122,15 @@ if Mix.target() == :app do
defp fixup_macos_menubar(frame, app_name) do defp fixup_macos_menubar(frame, app_name) do
menubar = :wxMenuBar.new() menubar = :wxMenuBar.new()
:wxFrame.setMenuBar(frame, menubar) :wxFrame.setMenuBar(frame, menubar)
menu = :wxMenuBar.oSXGetAppleMenu(menubar) menu = :wxMenuBar.oSXGetAppleMenu(menubar)
# without this, for some reason setting the title later will make it non-bold
:wxMenu.getTitle(menu)
# this is useful in dev, not needed when bundled in .app
:wxMenu.setTitle(menu, app_name)
menu menu
|> :wxMenu.findItem(@wx_id_osx_hide) |> :wxMenu.findItem(@wx_id_osx_hide)
|> :wxMenuItem.setItemLabel("Hide #{app_name}\tCtrl+H") |> :wxMenuItem.setItemLabel("Hide #{app_name}\tCtrl+H")