| 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | goruntime "runtime" |
| 5 | |
| 6 | "github.com/wailsapp/wails/v2/pkg/menu" |
| 7 | "github.com/wailsapp/wails/v2/pkg/menu/keys" |
| 8 | "github.com/wailsapp/wails/v2/pkg/runtime" |
| 9 | ) |
| 10 | |
| 11 | // createAppMenu builds the native application menu bar. macOS only: it's the |
| 12 | // platform convention there, and the Edit menu's standard roles are what make |
| 13 | // Cmd+C/V work in the webview. On Windows/Linux a menu bar renders as a stray |
| 14 | // in-window "File" strip (the Edit/Window mac roles don't show), so return nil. |
| 15 | func (a *App) createAppMenu() *menu.Menu { |
| 16 | if goruntime.GOOS != "darwin" { |
| 17 | return nil |
| 18 | } |
| 19 | |
| 20 | m := menu.NewMenu() |
| 21 | |
| 22 | m.Append(menu.AppMenu()) |
| 23 | |
| 24 | fileMenu := m.AddSubmenu("File") |
| 25 | fileMenu.AddText("Settings", keys.CmdOrCtrl(","), func(_ *menu.CallbackData) { |
| 26 | if a.ctx != nil { |
| 27 | runtime.EventsEmit(a.ctx, "app:open-settings") |
| 28 | } |
| 29 | }) |
| 30 | fileMenu.AddText("Toggle Developer Tools", keys.CmdOrCtrl("i"), func(_ *menu.CallbackData) { |
| 31 | if a.ctx != nil { |
| 32 | runtime.WindowExecJS(a.ctx, `window.webkit.messageHandlers.external.postMessage("wails:openInspector");`) |
| 33 | } |
| 34 | }) |
| 35 | fileMenu.AddText("Show Reasonix", nil, func(_ *menu.CallbackData) { |
| 36 | a.showMainWindow() |
| 37 | }) |
| 38 | fileMenu.AddText("Quit Reasonix", keys.CmdOrCtrl("q"), func(_ *menu.CallbackData) { |
| 39 | a.quitApp() |
| 40 | }) |
| 41 | m.Append(menu.EditMenu()) |
| 42 | m.Append(menu.WindowMenu()) |
| 43 | |
| 44 | return m |
| 45 | } |
| 46 |