2023-02-10 08:25:52 +11:00
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"embed"
|
|
|
|
|
_ "embed"
|
|
|
|
|
"log"
|
|
|
|
|
|
|
|
|
|
"github.com/wailsapp/wails/v3/pkg/application"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
//go:embed assets
|
|
|
|
|
var assets embed.FS
|
|
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
|
|
|
|
|
app := application.New(application.Options{
|
|
|
|
|
Name: "Context Menu Demo",
|
|
|
|
|
Description: "A demo of the Context Menu API",
|
2023-03-15 09:14:41 +01:00
|
|
|
Assets: application.AssetOptions{
|
2024-03-17 15:08:30 +11:00
|
|
|
Handler: application.BundledAssetFileServer(assets),
|
2023-03-15 09:14:41 +01:00
|
|
|
},
|
2023-07-21 08:24:38 +10:00
|
|
|
Mac: application.MacOptions{
|
|
|
|
|
ApplicationShouldTerminateAfterLastWindowClosed: true,
|
|
|
|
|
},
|
2023-02-10 08:25:52 +11:00
|
|
|
})
|
|
|
|
|
|
2023-05-01 18:21:22 +10:00
|
|
|
mainWindow := app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{
|
2023-06-20 21:11:37 +10:00
|
|
|
Title: "Context Menu Demo",
|
|
|
|
|
Width: 1024,
|
2023-07-01 03:52:55 +03:00
|
|
|
Height: 1024,
|
2023-02-10 08:25:52 +11:00
|
|
|
Mac: application.MacWindow{
|
|
|
|
|
Backdrop: application.MacBackdropTranslucent,
|
|
|
|
|
TitleBar: application.MacTitleBarHiddenInsetUnified,
|
|
|
|
|
InvisibleTitleBarHeight: 50,
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
contextMenu := app.NewMenu()
|
|
|
|
|
contextMenu.Add("Click Me").OnClick(func(data *application.Context) {
|
2023-10-10 19:59:45 +11:00
|
|
|
app.Logger.Info("Context menu", "context data", data.ContextMenuData())
|
2023-02-10 08:25:52 +11:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
globalContextMenu := app.NewMenu()
|
|
|
|
|
globalContextMenu.Add("Default context menu item").OnClick(func(data *application.Context) {
|
2023-10-10 19:59:45 +11:00
|
|
|
app.Logger.Info("Context menu", "context data", data.ContextMenuData())
|
2023-02-10 08:25:52 +11:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// Registering the menu with a window will make it available to that window only
|
|
|
|
|
mainWindow.RegisterContextMenu("test", contextMenu)
|
|
|
|
|
|
|
|
|
|
// Registering the menu with the app will make it available to all windows
|
|
|
|
|
app.RegisterContextMenu("test", globalContextMenu)
|
|
|
|
|
|
|
|
|
|
err := app.Run()
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatal(err.Error())
|
|
|
|
|
}
|
|
|
|
|
}
|