From 544f7d6d8b372ebf6d2b35e391a2b96d4d406465 Mon Sep 17 00:00:00 2001 From: Romein van Buren Date: Fri, 20 Jan 2023 16:27:51 +0100 Subject: [PATCH] App menu --- frontend/src/app.svelte | 20 +++++------ frontend/src/organisms/about/index.svelte | 9 +++++ frontend/wailsjs/go/app/App.d.ts | 3 ++ frontend/wailsjs/go/app/App.js | 4 +++ internal/app/app.go | 41 ++++++++++++++++++++++- main.go | 1 + 6 files changed, 67 insertions(+), 11 deletions(-) create mode 100644 frontend/src/organisms/about/index.svelte diff --git a/frontend/src/app.svelte b/frontend/src/app.svelte index b68c4d1..10f56ea 100644 --- a/frontend/src/app.svelte +++ b/frontend/src/app.svelte @@ -1,13 +1,13 @@ - +
@@ -66,6 +65,7 @@ {/key} + {/if}
diff --git a/frontend/src/organisms/about/index.svelte b/frontend/src/organisms/about/index.svelte new file mode 100644 index 0000000..e290118 --- /dev/null +++ b/frontend/src/organisms/about/index.svelte @@ -0,0 +1,9 @@ + + + + about... + diff --git a/frontend/wailsjs/go/app/App.d.ts b/frontend/wailsjs/go/app/App.d.ts index 224351c..88b63e1 100755 --- a/frontend/wailsjs/go/app/App.d.ts +++ b/frontend/wailsjs/go/app/App.d.ts @@ -3,6 +3,7 @@ import {app} from '../models'; import {primitive} from '../models'; import {map[string]app} from '../models'; +import {menu} from '../models'; export function AddHost(arg1:string):Promise; @@ -20,6 +21,8 @@ export function Hosts():Promise; export function InsertItems(arg1:string,arg2:string,arg3:string,arg4:string):Promise; +export function Menu():Promise; + export function OpenCollection(arg1:string,arg2:string,arg3:string):Promise; export function OpenConnection(arg1:string):Promise>; diff --git a/frontend/wailsjs/go/app/App.js b/frontend/wailsjs/go/app/App.js index 4f5ae33..674b940 100755 --- a/frontend/wailsjs/go/app/App.js +++ b/frontend/wailsjs/go/app/App.js @@ -34,6 +34,10 @@ export function InsertItems(arg1, arg2, arg3, arg4) { return window['go']['app']['App']['InsertItems'](arg1, arg2, arg3, arg4); } +export function Menu() { + return window['go']['app']['App']['Menu'](); +} + export function OpenCollection(arg1, arg2, arg3) { return window['go']['app']['App']['OpenCollection'](arg1, arg2, arg3); } diff --git a/internal/app/app.go b/internal/app/app.go index c5da997..6c09e8b 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -1,6 +1,13 @@ package app -import "context" +import ( + "context" + "runtime" + + "github.com/wailsapp/wails/v2/pkg/menu" + "github.com/wailsapp/wails/v2/pkg/menu/keys" + wailsRuntime "github.com/wailsapp/wails/v2/pkg/runtime" +) type App struct { ctx context.Context @@ -13,3 +20,35 @@ func NewApp() *App { func (a *App) Startup(ctx context.Context) { a.ctx = ctx } + +func (a *App) Menu() *menu.Menu { + appMenu := menu.NewMenu() + + aboutMenu := appMenu.AddSubmenu("About") + aboutMenu.AddText("About…", nil, func(cd *menu.CallbackData) { + wailsRuntime.EventsEmit(a.ctx, "OpenAboutModal") + }) + aboutMenu.AddText("Prefrences…", keys.CmdOrCtrl(","), func(cd *menu.CallbackData) { + wailsRuntime.EventsEmit(a.ctx, "OpenPrefrences") + }) + aboutMenu.AddSeparator() + aboutMenu.AddText("Quit", keys.CmdOrCtrl("q"), func(cd *menu.CallbackData) { + wailsRuntime.Quit(a.ctx) + }) + + fileMenu := appMenu.AddSubmenu("File") + fileMenu.AddText("Hosts…", keys.CmdOrCtrl("k"), func(cd *menu.CallbackData) { + wailsRuntime.EventsEmit(a.ctx, "OpenHostsModal") + }) + + helpMenu := appMenu.AddSubmenu("Help") + helpMenu.AddText("User guide", nil, func(cd *menu.CallbackData) { + wailsRuntime.BrowserOpenURL(a.ctx, "") + }) + + if runtime.GOOS == "darwin" { + appMenu.Append(menu.EditMenu()) + } + + return appMenu +} diff --git a/main.go b/main.go index e4aab9b..f4d3f00 100644 --- a/main.go +++ b/main.go @@ -29,6 +29,7 @@ func main() { MinHeight: 600, BackgroundColour: &options.RGBA{R: 0, G: 0, B: 139, A: 1}, OnStartup: app.Startup, + Menu: app.Menu(), AssetServer: &assetserver.Options{ Assets: assets,