diff --git a/go.work.sum b/go.work.sum index f4608dff1..a64b305dc 100644 --- a/go.work.sum +++ b/go.work.sum @@ -6,16 +6,19 @@ github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keL github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I= github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/gofuzz v1.0.0 h1:A8PeW59pxE9IoFRqBp37U+mSNaQoZ46F1f0f863XSXw= github.com/google/renameio/v2 v2.0.0 h1:UifI23ZTGY8Tt29JbYFiuyIU3eX+RNFtUwefq9qAhxg= github.com/jessevdk/go-flags v1.5.0 h1:1jKYvbxEjfUl0fmqTCOfonvskHHXMjBySTLW4y9LFvc= github.com/klauspost/cpuid/v2 v2.2.0/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY= github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk= github.com/kr/fs v0.1.0 h1:Jskdu9ieNAYnjxsi0LbQp1ulIKZV1LAFgK1tWhpZgl8= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= +github.com/kr/pty v1.1.1 h1:VkoXIwSboBpnk99O/KFauAEILuNHv5DVFKZMBN/gUgw= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e h1:aoZm08cpOy4WuID//EZDgcC4zIxODThtZNPirFr42+A= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pkg/sftp v1.10.1 h1:VasscCm72135zRysgrJDKsntdmPN+OuU3+nnHYA9wyc= github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= +github.com/sirupsen/logrus v1.4.1 h1:GL2rEmy6nsikmW0r8opw9JIRScdMF5hA8cOYLH7In1k= github.com/spf13/afero v1.6.0 h1:xoax2sJ2DT8S8xA2paPFjDCScCNeWsg75VG0DLRreiY= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c= diff --git a/v3/examples/binding/main.go b/v3/examples/binding/main.go index f6669c278..d8f5d4e9a 100644 --- a/v3/examples/binding/main.go +++ b/v3/examples/binding/main.go @@ -7,13 +7,12 @@ import ( "github.com/wailsapp/wails/v3/examples/binding/services" "github.com/wailsapp/wails/v3/pkg/application" - "github.com/wailsapp/wails/v3/pkg/options" ) type localStruct struct{} func main() { - app := application.New(options.Application{ + app := application.New(application.Options{ Bind: []interface{}{ &localStruct{}, &services.GreetService{}, diff --git a/v3/examples/build/main.go b/v3/examples/build/main.go index b8092bcf6..48ba24088 100755 --- a/v3/examples/build/main.go +++ b/v3/examples/build/main.go @@ -9,18 +9,16 @@ import ( "strconv" "time" - "github.com/wailsapp/wails/v3/pkg/options" - "github.com/wailsapp/wails/v3/pkg/events" "github.com/wailsapp/wails/v3/pkg/application" ) func main() { - app := application.New(options.Application{ + app := application.New(application.Options{ Name: "WebviewWindow Demo", Description: "A demo of the WebviewWindow API", - Mac: options.Mac{ + Mac: application.MacOptions{ ApplicationShouldTerminateAfterLastWindowClosed: true, }, }) @@ -67,45 +65,45 @@ func main() { windowCounter++ }) if runtime.GOOS == "darwin" { - myMenu.Add("New WebviewWindow (TitleBarHiddenInset)"). + myMenu.Add("New WebviewWindow (MacTitleBarHiddenInset)"). OnClick(func(ctx *application.Context) { - app.NewWebviewWindowWithOptions(&options.WebviewWindow{ - Mac: options.MacWindow{ - TitleBar: options.TitleBarHiddenInset, + app.NewWebviewWindowWithOptions(&application.WebviewWindowOptions{ + Mac: application.MacWindow{ + TitleBar: application.MacTitleBarHiddenInset, InvisibleTitleBarHeight: 25, }, }). SetTitle("WebviewWindow "+strconv.Itoa(windowCounter)). SetPosition(rand.Intn(1000), rand.Intn(800)). - SetHTML("

A TitleBarHiddenInset WebviewWindow example

"). + SetHTML("

A MacTitleBarHiddenInset WebviewWindow example

"). Show() windowCounter++ }) - myMenu.Add("New WebviewWindow (TitleBarHiddenInsetUnified)"). + myMenu.Add("New WebviewWindow (MacTitleBarHiddenInsetUnified)"). OnClick(func(ctx *application.Context) { - app.NewWebviewWindowWithOptions(&options.WebviewWindow{ - Mac: options.MacWindow{ - TitleBar: options.TitleBarHiddenInsetUnified, + app.NewWebviewWindowWithOptions(&application.WebviewWindowOptions{ + Mac: application.MacWindow{ + TitleBar: application.MacTitleBarHiddenInsetUnified, InvisibleTitleBarHeight: 50, }, }). SetTitle("WebviewWindow "+strconv.Itoa(windowCounter)). SetPosition(rand.Intn(1000), rand.Intn(800)). - SetHTML("

A TitleBarHiddenInsetUnified WebviewWindow example

"). + SetHTML("

A MacTitleBarHiddenInsetUnified WebviewWindow example

"). Show() windowCounter++ }) - myMenu.Add("New WebviewWindow (TitleBarHidden)"). + myMenu.Add("New WebviewWindow (MacTitleBarHidden)"). OnClick(func(ctx *application.Context) { - app.NewWebviewWindowWithOptions(&options.WebviewWindow{ - Mac: options.MacWindow{ - TitleBar: options.TitleBarHidden, + app.NewWebviewWindowWithOptions(&application.WebviewWindowOptions{ + Mac: application.MacWindow{ + TitleBar: application.MacTitleBarHidden, InvisibleTitleBarHeight: 25, }, }). SetTitle("WebviewWindow "+strconv.Itoa(windowCounter)). SetPosition(rand.Intn(1000), rand.Intn(800)). - SetHTML("

A TitleBarHidden WebviewWindow example

"). + SetHTML("

A MacTitleBarHidden WebviewWindow example

"). Show() windowCounter++ }) diff --git a/v3/examples/clipboard/main.go b/v3/examples/clipboard/main.go index bb2740ca3..c8e0e465b 100644 --- a/v3/examples/clipboard/main.go +++ b/v3/examples/clipboard/main.go @@ -5,17 +5,15 @@ import ( "log" "time" - "github.com/wailsapp/wails/v3/pkg/options" - "github.com/wailsapp/wails/v3/pkg/application" ) func main() { - app := application.New(options.Application{ + app := application.New(application.Options{ Name: "Clipboard Demo", Description: "A demo of the clipboard API", - Mac: options.Mac{ + Mac: application.MacOptions{ ApplicationShouldTerminateAfterLastWindowClosed: true, }, }) diff --git a/v3/examples/contextmenus/assets/index.html b/v3/examples/contextmenus/assets/index.html new file mode 100644 index 000000000..adb32d775 --- /dev/null +++ b/v3/examples/contextmenus/assets/index.html @@ -0,0 +1,30 @@ + + + + + Title + + + + +

Events Demo

+
+
+

1

+
+
+

2

+
+
+

3

+
+
+ + + + + \ No newline at end of file diff --git a/v3/examples/contextmenus/main.go b/v3/examples/contextmenus/main.go new file mode 100644 index 000000000..0ed4fcc69 --- /dev/null +++ b/v3/examples/contextmenus/main.go @@ -0,0 +1,70 @@ +package main + +import ( + "embed" + _ "embed" + "fmt" + "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", + Mac: application.MacOptions{ + ApplicationShouldTerminateAfterLastWindowClosed: true, + }, + }) + + mainWindow := app.NewWebviewWindowWithOptions(&application.WebviewWindowOptions{ + Title: "Context Menu Demo", + Assets: application.AssetOptions{ + FS: assets, + }, + Mac: application.MacWindow{ + Backdrop: application.MacBackdropTranslucent, + TitleBar: application.MacTitleBarHiddenInsetUnified, + InvisibleTitleBarHeight: 50, + }, + }) + + app.NewWebviewWindowWithOptions(&application.WebviewWindowOptions{ + Title: "Context Menu Demo", + Assets: application.AssetOptions{ + FS: assets, + }, + Mac: application.MacWindow{ + Backdrop: application.MacBackdropTranslucent, + TitleBar: application.MacTitleBarHiddenInsetUnified, + InvisibleTitleBarHeight: 50, + }, + }) + + contextMenu := app.NewMenu() + contextMenu.Add("Click Me").OnClick(func(data *application.Context) { + fmt.Printf("Context menu data: %+v\n", data.ContextMenuData()) + }) + + globalContextMenu := app.NewMenu() + globalContextMenu.Add("Default context menu item").OnClick(func(data *application.Context) { + fmt.Printf("Context menu data: %+v\n", data.ContextMenuData()) + }) + + // 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()) + } +} diff --git a/v3/examples/dialogs/main.go b/v3/examples/dialogs/main.go index 4ae46a236..ff55949ae 100644 --- a/v3/examples/dialogs/main.go +++ b/v3/examples/dialogs/main.go @@ -7,17 +7,15 @@ import ( "runtime" "strings" - "github.com/wailsapp/wails/v3/pkg/options" - "github.com/wailsapp/wails/v3/pkg/application" ) func main() { - app := application.New(options.Application{ + app := application.New(application.Options{ Name: "Dialogs Demo", Description: "A demo of the dialogs API", - Mac: options.Mac{ + Mac: application.MacOptions{ ApplicationShouldTerminateAfterLastWindowClosed: true, }, }) diff --git a/v3/examples/drag-n-drop/assets/index.html b/v3/examples/drag-n-drop/assets/index.html new file mode 100644 index 000000000..1ec2339dd --- /dev/null +++ b/v3/examples/drag-n-drop/assets/index.html @@ -0,0 +1,25 @@ + + + + + Title + + + +

Drag-n-drop Demo

+
+Drop Files onto this window... +
+ + + + + \ No newline at end of file diff --git a/v3/examples/drag-n-drop/main.go b/v3/examples/drag-n-drop/main.go new file mode 100644 index 000000000..5719b454f --- /dev/null +++ b/v3/examples/drag-n-drop/main.go @@ -0,0 +1,51 @@ +package main + +import ( + "embed" + _ "embed" + "log" + + "github.com/wailsapp/wails/v3/pkg/application" + "github.com/wailsapp/wails/v3/pkg/events" +) + +//go:embed assets +var assets embed.FS + +func main() { + + app := application.New(application.Options{ + Name: "Drag-n-drop Demo", + Description: "A demo of the Drag-n-drop API", + Mac: application.MacOptions{ + ApplicationShouldTerminateAfterLastWindowClosed: true, + }, + }) + + window := app.NewWebviewWindowWithOptions(&application.WebviewWindowOptions{ + Title: "Drag-n-drop Demo", + Assets: application.AssetOptions{ + FS: assets, + }, + Mac: application.MacWindow{ + Backdrop: application.MacBackdropTranslucent, + TitleBar: application.MacTitleBarHiddenInsetUnified, + InvisibleTitleBarHeight: 50, + }, + }) + + window.On(events.FilesDropped, func(ctx *application.WindowEventContext) { + files := ctx.DroppedFiles() + app.Events.Emit(&application.CustomEvent{ + Name: "files", + Data: files, + }) + log.Printf("[Go] FilesDropped received: %+v\n", files) + }) + + err := app.Run() + + if err != nil { + log.Fatal(err.Error()) + } +} diff --git a/v3/examples/kitchensink/main.go b/v3/examples/kitchensink/main.go index 851e4b787..509da3415 100644 --- a/v3/examples/kitchensink/main.go +++ b/v3/examples/kitchensink/main.go @@ -8,14 +8,13 @@ import ( "time" "github.com/wailsapp/wails/v3/pkg/application" - "github.com/wailsapp/wails/v3/pkg/options" ) func main() { - app := application.New(options.Application{ + app := application.New(application.Options{ Name: "Menu Demo", Description: "A demo of the menu system", - Mac: options.Mac{ + Mac: application.MacOptions{ ApplicationShouldTerminateAfterLastWindowClosed: true, }, }) @@ -110,22 +109,22 @@ func main() { mySystray.SetMenu(myMenu) mySystray.SetIconPosition(application.NSImageLeading) - myWindow := app.NewWebviewWindowWithOptions(&options.WebviewWindow{ + myWindow := app.NewWebviewWindowWithOptions(&application.WebviewWindowOptions{ Title: "Kitchen Sink", Width: 600, Height: 400, AlwaysOnTop: true, DisableResize: false, - BackgroundColour: &options.RGBA{ + BackgroundColour: &application.RGBA{ Red: 255, Green: 255, Blue: 255, Alpha: 30, }, - StartState: options.WindowStateMaximised, - Mac: options.MacWindow{ - Backdrop: options.MacBackdropTranslucent, - Appearance: options.NSAppearanceNameDarkAqua, + StartState: application.WindowStateMaximised, + Mac: application.MacWindow{ + Backdrop: application.MacBackdropTranslucent, + Appearance: application.NSAppearanceNameDarkAqua, }, }) /* @@ -185,14 +184,14 @@ func main() { */ var myWindow2 *application.WebviewWindow var myWindow2Lock sync.RWMutex - myWindow2 = app.NewWebviewWindowWithOptions(&options.WebviewWindow{ + myWindow2 = app.NewWebviewWindowWithOptions(&application.WebviewWindowOptions{ Title: "#2", Width: 1024, Height: 768, AlwaysOnTop: false, URL: "https://google.com", - Mac: options.MacWindow{ - Backdrop: options.MacBackdropTranslucent, + Mac: application.MacWindow{ + Backdrop: application.MacBackdropTranslucent, }, }) //myWindow2.On(events.Mac.WindowDidMove, func() { diff --git a/v3/examples/menu/main.go b/v3/examples/menu/main.go index 0310f4fec..3ca15cf47 100644 --- a/v3/examples/menu/main.go +++ b/v3/examples/menu/main.go @@ -4,17 +4,15 @@ import ( _ "embed" "log" - "github.com/wailsapp/wails/v3/pkg/options" - "github.com/wailsapp/wails/v3/pkg/application" ) func main() { - app := application.New(options.Application{ + app := application.New(application.Options{ Name: "Menu Demo", Description: "A demo of the menu system", - Mac: options.Mac{ + Mac: application.MacOptions{ ApplicationShouldTerminateAfterLastWindowClosed: true, }, }) diff --git a/v3/examples/plain/main.go b/v3/examples/plain/main.go index 1257ee2a0..63de5e8a1 100644 --- a/v3/examples/plain/main.go +++ b/v3/examples/plain/main.go @@ -5,31 +5,29 @@ import ( "log" "net/http" - "github.com/wailsapp/wails/v3/pkg/options" - "github.com/wailsapp/wails/v3/pkg/application" ) func main() { - app := application.New(options.Application{ + app := application.New(application.Options{ Name: "Plain", Description: "A demo of using raw HTML & CSS", - Mac: options.Mac{ + Mac: application.MacOptions{ ApplicationShouldTerminateAfterLastWindowClosed: true, }, }) // Create window - app.NewWebviewWindowWithOptions(&options.WebviewWindow{ + app.NewWebviewWindowWithOptions(&application.WebviewWindowOptions{ Title: "Plain Bundle", CSS: `body { background-color: rgba(255, 255, 255, 0); } .main { color: white; margin: 20%; }`, - Mac: options.MacWindow{ + Mac: application.MacWindow{ InvisibleTitleBarHeight: 50, - Backdrop: options.MacBackdropTranslucent, - TitleBar: options.TitleBarHiddenInset, + Backdrop: application.MacBackdropTranslucent, + TitleBar: application.MacTitleBarHiddenInset, }, URL: "/", - Assets: options.Assets{ + Assets: application.AssetOptions{ Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) w.Write([]byte(`Plain Bundle

Plain Bundle

This is a plain bundle. It has no frontend code but this was Served by the AssetServer's Handler

`)) diff --git a/v3/examples/systray/main.go b/v3/examples/systray/main.go index 054b2a9bc..2beb4501d 100644 --- a/v3/examples/systray/main.go +++ b/v3/examples/systray/main.go @@ -5,17 +5,15 @@ import ( "log" "runtime" - "github.com/wailsapp/wails/v3/pkg/options" - "github.com/wailsapp/wails/v3/pkg/application" ) func main() { - app := application.New(options.Application{ + app := application.New(application.Options{ Name: "Systray Demo", Description: "A demo of the Systray API", - Mac: options.Mac{ - ActivationPolicy: options.ActivationPolicyAccessory, + Mac: application.MacOptions{ + ActivationPolicy: application.ActivationPolicyAccessory, }, }) diff --git a/v3/examples/window/main.go b/v3/examples/window/main.go index 9d7a84a56..94aa474a7 100644 --- a/v3/examples/window/main.go +++ b/v3/examples/window/main.go @@ -9,18 +9,16 @@ import ( "strconv" "time" - "github.com/wailsapp/wails/v3/pkg/options" - "github.com/wailsapp/wails/v3/pkg/events" "github.com/wailsapp/wails/v3/pkg/application" ) func main() { - app := application.New(options.Application{ + app := application.New(application.Options{ Name: "WebviewWindow Demo", Description: "A demo of the WebviewWindow API", - Mac: options.Mac{ + Mac: application.MacOptions{ ApplicationShouldTerminateAfterLastWindowClosed: true, }, }) @@ -58,56 +56,56 @@ func main() { myMenu.Add("New Frameless WebviewWindow"). SetAccelerator("CmdOrCtrl+F"). OnClick(func(ctx *application.Context) { - app.NewWebviewWindowWithOptions(&options.WebviewWindow{ + app.NewWebviewWindowWithOptions(&application.WebviewWindowOptions{ X: rand.Intn(1000), Y: rand.Intn(800), Frameless: true, - Mac: options.MacWindow{ + Mac: application.MacWindow{ InvisibleTitleBarHeight: 50, }, }).Show() windowCounter++ }) if runtime.GOOS == "darwin" { - myMenu.Add("New WebviewWindow (TitleBarHiddenInset)"). + myMenu.Add("New WebviewWindow (MacTitleBarHiddenInset)"). OnClick(func(ctx *application.Context) { - app.NewWebviewWindowWithOptions(&options.WebviewWindow{ - Mac: options.MacWindow{ - TitleBar: options.TitleBarHiddenInset, + app.NewWebviewWindowWithOptions(&application.WebviewWindowOptions{ + Mac: application.MacWindow{ + TitleBar: application.MacTitleBarHiddenInset, InvisibleTitleBarHeight: 25, }, }). SetTitle("WebviewWindow "+strconv.Itoa(windowCounter)). SetPosition(rand.Intn(1000), rand.Intn(800)). - SetHTML("

A TitleBarHiddenInset WebviewWindow example

"). + SetHTML("

A MacTitleBarHiddenInset WebviewWindow example

"). Show() windowCounter++ }) - myMenu.Add("New WebviewWindow (TitleBarHiddenInsetUnified)"). + myMenu.Add("New WebviewWindow (MacTitleBarHiddenInsetUnified)"). OnClick(func(ctx *application.Context) { - app.NewWebviewWindowWithOptions(&options.WebviewWindow{ - Mac: options.MacWindow{ - TitleBar: options.TitleBarHiddenInsetUnified, + app.NewWebviewWindowWithOptions(&application.WebviewWindowOptions{ + Mac: application.MacWindow{ + TitleBar: application.MacTitleBarHiddenInsetUnified, InvisibleTitleBarHeight: 50, }, }). SetTitle("WebviewWindow "+strconv.Itoa(windowCounter)). SetPosition(rand.Intn(1000), rand.Intn(800)). - SetHTML("

A TitleBarHiddenInsetUnified WebviewWindow example

"). + SetHTML("

A MacTitleBarHiddenInsetUnified WebviewWindow example

"). Show() windowCounter++ }) - myMenu.Add("New WebviewWindow (TitleBarHidden)"). + myMenu.Add("New WebviewWindow (MacTitleBarHidden)"). OnClick(func(ctx *application.Context) { - app.NewWebviewWindowWithOptions(&options.WebviewWindow{ - Mac: options.MacWindow{ - TitleBar: options.TitleBarHidden, + app.NewWebviewWindowWithOptions(&application.WebviewWindowOptions{ + Mac: application.MacWindow{ + TitleBar: application.MacTitleBarHidden, InvisibleTitleBarHeight: 25, }, }). SetTitle("WebviewWindow "+strconv.Itoa(windowCounter)). SetPosition(rand.Intn(1000), rand.Intn(800)). - SetHTML("

A TitleBarHidden WebviewWindow example

"). + SetHTML("

A MacTitleBarHidden WebviewWindow example

"). Show() windowCounter++ }) diff --git a/v3/examples/windowjs/main.go b/v3/examples/windowjs/main.go index 2f6b6c412..0ce071f1a 100644 --- a/v3/examples/windowjs/main.go +++ b/v3/examples/windowjs/main.go @@ -7,8 +7,6 @@ import ( "math/rand" "strconv" - "github.com/wailsapp/wails/v3/pkg/options" - "github.com/wailsapp/wails/v3/pkg/application" ) @@ -16,11 +14,11 @@ import ( var assets embed.FS func main() { - app := application.New(options.Application{ + app := application.New(application.Options{ Name: "WebviewWindow Javascript Demo", Description: "A demo of the WebviewWindow API from Javascript", Icon: nil, - Mac: options.Mac{ + Mac: application.MacOptions{ ApplicationShouldTerminateAfterLastWindowClosed: true, }, }) @@ -32,8 +30,8 @@ func main() { windowCounter := 1 newWindow := func() { - app.NewWebviewWindowWithOptions(&options.WebviewWindow{ - Assets: options.Assets{ + app.NewWebviewWindowWithOptions(&application.WebviewWindowOptions{ + Assets: application.AssetOptions{ FS: assets, }, }). diff --git a/v3/internal/parser/parser.go b/v3/internal/parser/parser.go index 79c1ca728..8229536a8 100644 --- a/v3/internal/parser/parser.go +++ b/v3/internal/parser/parser.go @@ -115,7 +115,7 @@ func findApplicationNewCalls(context *Context) { return true } - // Check struct literal is of type "options.Application" + // Check struct literal is of type "application.Options" selectorExpr, ok := structLit.Type.(*ast.SelectorExpr) if !ok { return true diff --git a/v3/internal/parser/testdata/struct_literal_multiple/main.go b/v3/internal/parser/testdata/struct_literal_multiple/main.go index 4f0bf8bd3..125aad612 100644 --- a/v3/internal/parser/testdata/struct_literal_multiple/main.go +++ b/v3/internal/parser/testdata/struct_literal_multiple/main.go @@ -5,7 +5,6 @@ import ( "log" "github.com/wailsapp/wails/v3/pkg/application" - "github.com/wailsapp/wails/v3/pkg/options" ) type GreetService struct { @@ -22,7 +21,7 @@ type OtherService struct { } func main() { - app := application.New(options.Application{ + app := application.New(application.Options{ Bind: []interface{}{ &GreetService{}, &OtherService{}, diff --git a/v3/internal/parser/testdata/struct_literal_multiple_files/main.go b/v3/internal/parser/testdata/struct_literal_multiple_files/main.go index fd801c1bf..a75d4d7bd 100644 --- a/v3/internal/parser/testdata/struct_literal_multiple_files/main.go +++ b/v3/internal/parser/testdata/struct_literal_multiple_files/main.go @@ -5,11 +5,10 @@ import ( "log" "github.com/wailsapp/wails/v3/pkg/application" - "github.com/wailsapp/wails/v3/pkg/options" ) func main() { - app := application.New(options.Application{ + app := application.New(application.Options{ Bind: []interface{}{ &GreetService{}, &OtherService{}, diff --git a/v3/internal/parser/testdata/struct_literal_single/main.go b/v3/internal/parser/testdata/struct_literal_single/main.go index cfc684e1c..ac7f05f8d 100644 --- a/v3/internal/parser/testdata/struct_literal_single/main.go +++ b/v3/internal/parser/testdata/struct_literal_single/main.go @@ -5,7 +5,6 @@ import ( "log" "github.com/wailsapp/wails/v3/pkg/application" - "github.com/wailsapp/wails/v3/pkg/options" ) type GreetService struct { @@ -18,7 +17,7 @@ func (*GreetService) Greet(name string) string { } func main() { - app := application.New(options.Application{ + app := application.New(application.Options{ Bind: []interface{}{ &GreetService{}, }, diff --git a/v3/internal/runtime/desktop/contextmenu.js b/v3/internal/runtime/desktop/contextmenu.js new file mode 100644 index 000000000..7b6e2c1f4 --- /dev/null +++ b/v3/internal/runtime/desktop/contextmenu.js @@ -0,0 +1,32 @@ +import {newRuntimeCaller} from "./runtime"; + +let call = newRuntimeCaller("contextmenu"); + +function openContextMenu(id, x, y, data) { + return call("OpenContextMenu", {id, x, y, data}); +} + +export function enableContextMenus(enabled) { + if (enabled) { + window.addEventListener('contextmenu', contextMenuHandler); + } else { + window.removeEventListener('contextmenu', contextMenuHandler); + } +} + +function contextMenuHandler(event) { + processContextMenu(event.target, event); +} + +function processContextMenu(element, event) { + let id = element.getAttribute('data-contextmenu'); + if (id) { + event.preventDefault(); + openContextMenu(id, event.clientX, event.clientY, element.getAttribute('data-contextmenu-data')); + } else { + let parent = element.parentElement; + if (parent) { + processContextMenu(parent, event); + } + } +} diff --git a/v3/internal/templates/_base/default/main.tmpl.go b/v3/internal/templates/_base/default/main.go.tmpl similarity index 63% rename from v3/internal/templates/_base/default/main.tmpl.go rename to v3/internal/templates/_base/default/main.go.tmpl index ea8f138b8..1bc6a4868 100644 --- a/v3/internal/templates/_base/default/main.tmpl.go +++ b/v3/internal/templates/_base/default/main.go.tmpl @@ -5,8 +5,6 @@ import ( _ "embed" "log" - "github.com/wailsapp/wails/v3/pkg/options" - "github.com/wailsapp/wails/v3/pkg/application" ) @@ -14,25 +12,25 @@ import ( var assets embed.FS func main() { - app := application.New(options.Application{ + app := application.New(application.Options{ Name: "{{.ProjectName}}", Description: "A demo of using raw HTML & CSS", - Mac: options.Mac{ + Mac: application.MacOptions{ ApplicationShouldTerminateAfterLastWindowClosed: true, }, }) // Create window - app.NewWebviewWindowWithOptions(&options.WebviewWindow{ + app.NewWebviewWindowWithOptions(&application.WebviewWindowOptions{ Title: "Plain Bundle", CSS: `body { background-color: rgba(255, 255, 255, 0); } .main { color: white; margin: 20%; }`, - Mac: options.MacWindow{ + Mac: application.MacWindow{ InvisibleTitleBarHeight: 50, - Backdrop: options.MacBackdropTranslucent, - TitleBar: options.TitleBarHiddenInset, + Backdrop: application.MacBackdropTranslucent, + TitleBar: application.MacTitleBarHiddenInset, }, URL: "/", - Assets: options.Assets{ + Assets: application.AssetOptions{ FS: assets, }, }) diff --git a/v3/internal/templates/lit-ts/main.tmpl.go b/v3/internal/templates/lit-ts/main.go.tmpl similarity index 63% rename from v3/internal/templates/lit-ts/main.tmpl.go rename to v3/internal/templates/lit-ts/main.go.tmpl index ea8f138b8..1bc6a4868 100644 --- a/v3/internal/templates/lit-ts/main.tmpl.go +++ b/v3/internal/templates/lit-ts/main.go.tmpl @@ -5,8 +5,6 @@ import ( _ "embed" "log" - "github.com/wailsapp/wails/v3/pkg/options" - "github.com/wailsapp/wails/v3/pkg/application" ) @@ -14,25 +12,25 @@ import ( var assets embed.FS func main() { - app := application.New(options.Application{ + app := application.New(application.Options{ Name: "{{.ProjectName}}", Description: "A demo of using raw HTML & CSS", - Mac: options.Mac{ + Mac: application.MacOptions{ ApplicationShouldTerminateAfterLastWindowClosed: true, }, }) // Create window - app.NewWebviewWindowWithOptions(&options.WebviewWindow{ + app.NewWebviewWindowWithOptions(&application.WebviewWindowOptions{ Title: "Plain Bundle", CSS: `body { background-color: rgba(255, 255, 255, 0); } .main { color: white; margin: 20%; }`, - Mac: options.MacWindow{ + Mac: application.MacWindow{ InvisibleTitleBarHeight: 50, - Backdrop: options.MacBackdropTranslucent, - TitleBar: options.TitleBarHiddenInset, + Backdrop: application.MacBackdropTranslucent, + TitleBar: application.MacTitleBarHiddenInset, }, URL: "/", - Assets: options.Assets{ + Assets: application.AssetOptions{ FS: assets, }, }) diff --git a/v3/internal/templates/lit/main.tmpl.go b/v3/internal/templates/lit/main.go.tmpl similarity index 63% rename from v3/internal/templates/lit/main.tmpl.go rename to v3/internal/templates/lit/main.go.tmpl index ea8f138b8..1bc6a4868 100644 --- a/v3/internal/templates/lit/main.tmpl.go +++ b/v3/internal/templates/lit/main.go.tmpl @@ -5,8 +5,6 @@ import ( _ "embed" "log" - "github.com/wailsapp/wails/v3/pkg/options" - "github.com/wailsapp/wails/v3/pkg/application" ) @@ -14,25 +12,25 @@ import ( var assets embed.FS func main() { - app := application.New(options.Application{ + app := application.New(application.Options{ Name: "{{.ProjectName}}", Description: "A demo of using raw HTML & CSS", - Mac: options.Mac{ + Mac: application.MacOptions{ ApplicationShouldTerminateAfterLastWindowClosed: true, }, }) // Create window - app.NewWebviewWindowWithOptions(&options.WebviewWindow{ + app.NewWebviewWindowWithOptions(&application.WebviewWindowOptions{ Title: "Plain Bundle", CSS: `body { background-color: rgba(255, 255, 255, 0); } .main { color: white; margin: 20%; }`, - Mac: options.MacWindow{ + Mac: application.MacWindow{ InvisibleTitleBarHeight: 50, - Backdrop: options.MacBackdropTranslucent, - TitleBar: options.TitleBarHiddenInset, + Backdrop: application.MacBackdropTranslucent, + TitleBar: application.MacTitleBarHiddenInset, }, URL: "/", - Assets: options.Assets{ + Assets: application.AssetOptions{ FS: assets, }, }) diff --git a/v3/internal/templates/preact-ts/main.tmpl.go b/v3/internal/templates/preact-ts/main.go.tmpl similarity index 63% rename from v3/internal/templates/preact-ts/main.tmpl.go rename to v3/internal/templates/preact-ts/main.go.tmpl index ea8f138b8..1bc6a4868 100644 --- a/v3/internal/templates/preact-ts/main.tmpl.go +++ b/v3/internal/templates/preact-ts/main.go.tmpl @@ -5,8 +5,6 @@ import ( _ "embed" "log" - "github.com/wailsapp/wails/v3/pkg/options" - "github.com/wailsapp/wails/v3/pkg/application" ) @@ -14,25 +12,25 @@ import ( var assets embed.FS func main() { - app := application.New(options.Application{ + app := application.New(application.Options{ Name: "{{.ProjectName}}", Description: "A demo of using raw HTML & CSS", - Mac: options.Mac{ + Mac: application.MacOptions{ ApplicationShouldTerminateAfterLastWindowClosed: true, }, }) // Create window - app.NewWebviewWindowWithOptions(&options.WebviewWindow{ + app.NewWebviewWindowWithOptions(&application.WebviewWindowOptions{ Title: "Plain Bundle", CSS: `body { background-color: rgba(255, 255, 255, 0); } .main { color: white; margin: 20%; }`, - Mac: options.MacWindow{ + Mac: application.MacWindow{ InvisibleTitleBarHeight: 50, - Backdrop: options.MacBackdropTranslucent, - TitleBar: options.TitleBarHiddenInset, + Backdrop: application.MacBackdropTranslucent, + TitleBar: application.MacTitleBarHiddenInset, }, URL: "/", - Assets: options.Assets{ + Assets: application.AssetOptions{ FS: assets, }, }) diff --git a/v3/internal/templates/preact/main.go.tmpl b/v3/internal/templates/preact/main.go.tmpl new file mode 100644 index 000000000..1bc6a4868 --- /dev/null +++ b/v3/internal/templates/preact/main.go.tmpl @@ -0,0 +1,43 @@ +package main + +import ( + "embed" + _ "embed" + "log" + + "github.com/wailsapp/wails/v3/pkg/application" +) + +//go:embed frontend/dist +var assets embed.FS + +func main() { + app := application.New(application.Options{ + Name: "{{.ProjectName}}", + Description: "A demo of using raw HTML & CSS", + Mac: application.MacOptions{ + ApplicationShouldTerminateAfterLastWindowClosed: true, + }, + }) + // Create window + app.NewWebviewWindowWithOptions(&application.WebviewWindowOptions{ + Title: "Plain Bundle", + CSS: `body { background-color: rgba(255, 255, 255, 0); } .main { color: white; margin: 20%; }`, + Mac: application.MacWindow{ + InvisibleTitleBarHeight: 50, + Backdrop: application.MacBackdropTranslucent, + TitleBar: application.MacTitleBarHiddenInset, + }, + + URL: "/", + Assets: application.AssetOptions{ + FS: assets, + }, + }) + + err := app.Run() + + if err != nil { + log.Fatal(err) + } +} diff --git a/v3/internal/templates/preact/main.tmpl.go b/v3/internal/templates/preact/main.tmpl.go deleted file mode 100644 index ea8f138b8..000000000 --- a/v3/internal/templates/preact/main.tmpl.go +++ /dev/null @@ -1,45 +0,0 @@ -package main - -import ( - "embed" - _ "embed" - "log" - - "github.com/wailsapp/wails/v3/pkg/options" - - "github.com/wailsapp/wails/v3/pkg/application" -) - -//go:embed frontend/dist -var assets embed.FS - -func main() { - app := application.New(options.Application{ - Name: "{{.ProjectName}}", - Description: "A demo of using raw HTML & CSS", - Mac: options.Mac{ - ApplicationShouldTerminateAfterLastWindowClosed: true, - }, - }) - // Create window - app.NewWebviewWindowWithOptions(&options.WebviewWindow{ - Title: "Plain Bundle", - CSS: `body { background-color: rgba(255, 255, 255, 0); } .main { color: white; margin: 20%; }`, - Mac: options.MacWindow{ - InvisibleTitleBarHeight: 50, - Backdrop: options.MacBackdropTranslucent, - TitleBar: options.TitleBarHiddenInset, - }, - - URL: "/", - Assets: options.Assets{ - FS: assets, - }, - }) - - err := app.Run() - - if err != nil { - log.Fatal(err) - } -} diff --git a/v3/internal/templates/react-swc-ts/main.go.tmpl b/v3/internal/templates/react-swc-ts/main.go.tmpl new file mode 100644 index 000000000..1bc6a4868 --- /dev/null +++ b/v3/internal/templates/react-swc-ts/main.go.tmpl @@ -0,0 +1,43 @@ +package main + +import ( + "embed" + _ "embed" + "log" + + "github.com/wailsapp/wails/v3/pkg/application" +) + +//go:embed frontend/dist +var assets embed.FS + +func main() { + app := application.New(application.Options{ + Name: "{{.ProjectName}}", + Description: "A demo of using raw HTML & CSS", + Mac: application.MacOptions{ + ApplicationShouldTerminateAfterLastWindowClosed: true, + }, + }) + // Create window + app.NewWebviewWindowWithOptions(&application.WebviewWindowOptions{ + Title: "Plain Bundle", + CSS: `body { background-color: rgba(255, 255, 255, 0); } .main { color: white; margin: 20%; }`, + Mac: application.MacWindow{ + InvisibleTitleBarHeight: 50, + Backdrop: application.MacBackdropTranslucent, + TitleBar: application.MacTitleBarHiddenInset, + }, + + URL: "/", + Assets: application.AssetOptions{ + FS: assets, + }, + }) + + err := app.Run() + + if err != nil { + log.Fatal(err) + } +} diff --git a/v3/internal/templates/react-swc-ts/main.tmpl.go b/v3/internal/templates/react-swc-ts/main.tmpl.go deleted file mode 100644 index ea8f138b8..000000000 --- a/v3/internal/templates/react-swc-ts/main.tmpl.go +++ /dev/null @@ -1,45 +0,0 @@ -package main - -import ( - "embed" - _ "embed" - "log" - - "github.com/wailsapp/wails/v3/pkg/options" - - "github.com/wailsapp/wails/v3/pkg/application" -) - -//go:embed frontend/dist -var assets embed.FS - -func main() { - app := application.New(options.Application{ - Name: "{{.ProjectName}}", - Description: "A demo of using raw HTML & CSS", - Mac: options.Mac{ - ApplicationShouldTerminateAfterLastWindowClosed: true, - }, - }) - // Create window - app.NewWebviewWindowWithOptions(&options.WebviewWindow{ - Title: "Plain Bundle", - CSS: `body { background-color: rgba(255, 255, 255, 0); } .main { color: white; margin: 20%; }`, - Mac: options.MacWindow{ - InvisibleTitleBarHeight: 50, - Backdrop: options.MacBackdropTranslucent, - TitleBar: options.TitleBarHiddenInset, - }, - - URL: "/", - Assets: options.Assets{ - FS: assets, - }, - }) - - err := app.Run() - - if err != nil { - log.Fatal(err) - } -} diff --git a/v3/internal/templates/react-swc/main.go.tmpl b/v3/internal/templates/react-swc/main.go.tmpl new file mode 100644 index 000000000..1bc6a4868 --- /dev/null +++ b/v3/internal/templates/react-swc/main.go.tmpl @@ -0,0 +1,43 @@ +package main + +import ( + "embed" + _ "embed" + "log" + + "github.com/wailsapp/wails/v3/pkg/application" +) + +//go:embed frontend/dist +var assets embed.FS + +func main() { + app := application.New(application.Options{ + Name: "{{.ProjectName}}", + Description: "A demo of using raw HTML & CSS", + Mac: application.MacOptions{ + ApplicationShouldTerminateAfterLastWindowClosed: true, + }, + }) + // Create window + app.NewWebviewWindowWithOptions(&application.WebviewWindowOptions{ + Title: "Plain Bundle", + CSS: `body { background-color: rgba(255, 255, 255, 0); } .main { color: white; margin: 20%; }`, + Mac: application.MacWindow{ + InvisibleTitleBarHeight: 50, + Backdrop: application.MacBackdropTranslucent, + TitleBar: application.MacTitleBarHiddenInset, + }, + + URL: "/", + Assets: application.AssetOptions{ + FS: assets, + }, + }) + + err := app.Run() + + if err != nil { + log.Fatal(err) + } +} diff --git a/v3/internal/templates/react-swc/main.tmpl.go b/v3/internal/templates/react-swc/main.tmpl.go deleted file mode 100644 index ea8f138b8..000000000 --- a/v3/internal/templates/react-swc/main.tmpl.go +++ /dev/null @@ -1,45 +0,0 @@ -package main - -import ( - "embed" - _ "embed" - "log" - - "github.com/wailsapp/wails/v3/pkg/options" - - "github.com/wailsapp/wails/v3/pkg/application" -) - -//go:embed frontend/dist -var assets embed.FS - -func main() { - app := application.New(options.Application{ - Name: "{{.ProjectName}}", - Description: "A demo of using raw HTML & CSS", - Mac: options.Mac{ - ApplicationShouldTerminateAfterLastWindowClosed: true, - }, - }) - // Create window - app.NewWebviewWindowWithOptions(&options.WebviewWindow{ - Title: "Plain Bundle", - CSS: `body { background-color: rgba(255, 255, 255, 0); } .main { color: white; margin: 20%; }`, - Mac: options.MacWindow{ - InvisibleTitleBarHeight: 50, - Backdrop: options.MacBackdropTranslucent, - TitleBar: options.TitleBarHiddenInset, - }, - - URL: "/", - Assets: options.Assets{ - FS: assets, - }, - }) - - err := app.Run() - - if err != nil { - log.Fatal(err) - } -} diff --git a/v3/internal/templates/react-ts/main.go.tmpl b/v3/internal/templates/react-ts/main.go.tmpl new file mode 100644 index 000000000..1bc6a4868 --- /dev/null +++ b/v3/internal/templates/react-ts/main.go.tmpl @@ -0,0 +1,43 @@ +package main + +import ( + "embed" + _ "embed" + "log" + + "github.com/wailsapp/wails/v3/pkg/application" +) + +//go:embed frontend/dist +var assets embed.FS + +func main() { + app := application.New(application.Options{ + Name: "{{.ProjectName}}", + Description: "A demo of using raw HTML & CSS", + Mac: application.MacOptions{ + ApplicationShouldTerminateAfterLastWindowClosed: true, + }, + }) + // Create window + app.NewWebviewWindowWithOptions(&application.WebviewWindowOptions{ + Title: "Plain Bundle", + CSS: `body { background-color: rgba(255, 255, 255, 0); } .main { color: white; margin: 20%; }`, + Mac: application.MacWindow{ + InvisibleTitleBarHeight: 50, + Backdrop: application.MacBackdropTranslucent, + TitleBar: application.MacTitleBarHiddenInset, + }, + + URL: "/", + Assets: application.AssetOptions{ + FS: assets, + }, + }) + + err := app.Run() + + if err != nil { + log.Fatal(err) + } +} diff --git a/v3/internal/templates/react-ts/main.tmpl.go b/v3/internal/templates/react-ts/main.tmpl.go deleted file mode 100644 index ea8f138b8..000000000 --- a/v3/internal/templates/react-ts/main.tmpl.go +++ /dev/null @@ -1,45 +0,0 @@ -package main - -import ( - "embed" - _ "embed" - "log" - - "github.com/wailsapp/wails/v3/pkg/options" - - "github.com/wailsapp/wails/v3/pkg/application" -) - -//go:embed frontend/dist -var assets embed.FS - -func main() { - app := application.New(options.Application{ - Name: "{{.ProjectName}}", - Description: "A demo of using raw HTML & CSS", - Mac: options.Mac{ - ApplicationShouldTerminateAfterLastWindowClosed: true, - }, - }) - // Create window - app.NewWebviewWindowWithOptions(&options.WebviewWindow{ - Title: "Plain Bundle", - CSS: `body { background-color: rgba(255, 255, 255, 0); } .main { color: white; margin: 20%; }`, - Mac: options.MacWindow{ - InvisibleTitleBarHeight: 50, - Backdrop: options.MacBackdropTranslucent, - TitleBar: options.TitleBarHiddenInset, - }, - - URL: "/", - Assets: options.Assets{ - FS: assets, - }, - }) - - err := app.Run() - - if err != nil { - log.Fatal(err) - } -} diff --git a/v3/internal/templates/react/main.go.tmpl b/v3/internal/templates/react/main.go.tmpl new file mode 100644 index 000000000..1bc6a4868 --- /dev/null +++ b/v3/internal/templates/react/main.go.tmpl @@ -0,0 +1,43 @@ +package main + +import ( + "embed" + _ "embed" + "log" + + "github.com/wailsapp/wails/v3/pkg/application" +) + +//go:embed frontend/dist +var assets embed.FS + +func main() { + app := application.New(application.Options{ + Name: "{{.ProjectName}}", + Description: "A demo of using raw HTML & CSS", + Mac: application.MacOptions{ + ApplicationShouldTerminateAfterLastWindowClosed: true, + }, + }) + // Create window + app.NewWebviewWindowWithOptions(&application.WebviewWindowOptions{ + Title: "Plain Bundle", + CSS: `body { background-color: rgba(255, 255, 255, 0); } .main { color: white; margin: 20%; }`, + Mac: application.MacWindow{ + InvisibleTitleBarHeight: 50, + Backdrop: application.MacBackdropTranslucent, + TitleBar: application.MacTitleBarHiddenInset, + }, + + URL: "/", + Assets: application.AssetOptions{ + FS: assets, + }, + }) + + err := app.Run() + + if err != nil { + log.Fatal(err) + } +} diff --git a/v3/internal/templates/react/main.tmpl.go b/v3/internal/templates/react/main.tmpl.go deleted file mode 100644 index ea8f138b8..000000000 --- a/v3/internal/templates/react/main.tmpl.go +++ /dev/null @@ -1,45 +0,0 @@ -package main - -import ( - "embed" - _ "embed" - "log" - - "github.com/wailsapp/wails/v3/pkg/options" - - "github.com/wailsapp/wails/v3/pkg/application" -) - -//go:embed frontend/dist -var assets embed.FS - -func main() { - app := application.New(options.Application{ - Name: "{{.ProjectName}}", - Description: "A demo of using raw HTML & CSS", - Mac: options.Mac{ - ApplicationShouldTerminateAfterLastWindowClosed: true, - }, - }) - // Create window - app.NewWebviewWindowWithOptions(&options.WebviewWindow{ - Title: "Plain Bundle", - CSS: `body { background-color: rgba(255, 255, 255, 0); } .main { color: white; margin: 20%; }`, - Mac: options.MacWindow{ - InvisibleTitleBarHeight: 50, - Backdrop: options.MacBackdropTranslucent, - TitleBar: options.TitleBarHiddenInset, - }, - - URL: "/", - Assets: options.Assets{ - FS: assets, - }, - }) - - err := app.Run() - - if err != nil { - log.Fatal(err) - } -} diff --git a/v3/internal/templates/svelte-ts/main.go.tmpl b/v3/internal/templates/svelte-ts/main.go.tmpl new file mode 100644 index 000000000..1bc6a4868 --- /dev/null +++ b/v3/internal/templates/svelte-ts/main.go.tmpl @@ -0,0 +1,43 @@ +package main + +import ( + "embed" + _ "embed" + "log" + + "github.com/wailsapp/wails/v3/pkg/application" +) + +//go:embed frontend/dist +var assets embed.FS + +func main() { + app := application.New(application.Options{ + Name: "{{.ProjectName}}", + Description: "A demo of using raw HTML & CSS", + Mac: application.MacOptions{ + ApplicationShouldTerminateAfterLastWindowClosed: true, + }, + }) + // Create window + app.NewWebviewWindowWithOptions(&application.WebviewWindowOptions{ + Title: "Plain Bundle", + CSS: `body { background-color: rgba(255, 255, 255, 0); } .main { color: white; margin: 20%; }`, + Mac: application.MacWindow{ + InvisibleTitleBarHeight: 50, + Backdrop: application.MacBackdropTranslucent, + TitleBar: application.MacTitleBarHiddenInset, + }, + + URL: "/", + Assets: application.AssetOptions{ + FS: assets, + }, + }) + + err := app.Run() + + if err != nil { + log.Fatal(err) + } +} diff --git a/v3/internal/templates/svelte-ts/main.tmpl.go b/v3/internal/templates/svelte-ts/main.tmpl.go deleted file mode 100644 index ea8f138b8..000000000 --- a/v3/internal/templates/svelte-ts/main.tmpl.go +++ /dev/null @@ -1,45 +0,0 @@ -package main - -import ( - "embed" - _ "embed" - "log" - - "github.com/wailsapp/wails/v3/pkg/options" - - "github.com/wailsapp/wails/v3/pkg/application" -) - -//go:embed frontend/dist -var assets embed.FS - -func main() { - app := application.New(options.Application{ - Name: "{{.ProjectName}}", - Description: "A demo of using raw HTML & CSS", - Mac: options.Mac{ - ApplicationShouldTerminateAfterLastWindowClosed: true, - }, - }) - // Create window - app.NewWebviewWindowWithOptions(&options.WebviewWindow{ - Title: "Plain Bundle", - CSS: `body { background-color: rgba(255, 255, 255, 0); } .main { color: white; margin: 20%; }`, - Mac: options.MacWindow{ - InvisibleTitleBarHeight: 50, - Backdrop: options.MacBackdropTranslucent, - TitleBar: options.TitleBarHiddenInset, - }, - - URL: "/", - Assets: options.Assets{ - FS: assets, - }, - }) - - err := app.Run() - - if err != nil { - log.Fatal(err) - } -} diff --git a/v3/internal/templates/svelte/main.go.tmpl b/v3/internal/templates/svelte/main.go.tmpl new file mode 100644 index 000000000..1bc6a4868 --- /dev/null +++ b/v3/internal/templates/svelte/main.go.tmpl @@ -0,0 +1,43 @@ +package main + +import ( + "embed" + _ "embed" + "log" + + "github.com/wailsapp/wails/v3/pkg/application" +) + +//go:embed frontend/dist +var assets embed.FS + +func main() { + app := application.New(application.Options{ + Name: "{{.ProjectName}}", + Description: "A demo of using raw HTML & CSS", + Mac: application.MacOptions{ + ApplicationShouldTerminateAfterLastWindowClosed: true, + }, + }) + // Create window + app.NewWebviewWindowWithOptions(&application.WebviewWindowOptions{ + Title: "Plain Bundle", + CSS: `body { background-color: rgba(255, 255, 255, 0); } .main { color: white; margin: 20%; }`, + Mac: application.MacWindow{ + InvisibleTitleBarHeight: 50, + Backdrop: application.MacBackdropTranslucent, + TitleBar: application.MacTitleBarHiddenInset, + }, + + URL: "/", + Assets: application.AssetOptions{ + FS: assets, + }, + }) + + err := app.Run() + + if err != nil { + log.Fatal(err) + } +} diff --git a/v3/internal/templates/svelte/main.tmpl.go b/v3/internal/templates/svelte/main.tmpl.go deleted file mode 100644 index ea8f138b8..000000000 --- a/v3/internal/templates/svelte/main.tmpl.go +++ /dev/null @@ -1,45 +0,0 @@ -package main - -import ( - "embed" - _ "embed" - "log" - - "github.com/wailsapp/wails/v3/pkg/options" - - "github.com/wailsapp/wails/v3/pkg/application" -) - -//go:embed frontend/dist -var assets embed.FS - -func main() { - app := application.New(options.Application{ - Name: "{{.ProjectName}}", - Description: "A demo of using raw HTML & CSS", - Mac: options.Mac{ - ApplicationShouldTerminateAfterLastWindowClosed: true, - }, - }) - // Create window - app.NewWebviewWindowWithOptions(&options.WebviewWindow{ - Title: "Plain Bundle", - CSS: `body { background-color: rgba(255, 255, 255, 0); } .main { color: white; margin: 20%; }`, - Mac: options.MacWindow{ - InvisibleTitleBarHeight: 50, - Backdrop: options.MacBackdropTranslucent, - TitleBar: options.TitleBarHiddenInset, - }, - - URL: "/", - Assets: options.Assets{ - FS: assets, - }, - }) - - err := app.Run() - - if err != nil { - log.Fatal(err) - } -} diff --git a/v3/internal/templates/vanilla-ts/main.go.tmpl b/v3/internal/templates/vanilla-ts/main.go.tmpl new file mode 100644 index 000000000..1bc6a4868 --- /dev/null +++ b/v3/internal/templates/vanilla-ts/main.go.tmpl @@ -0,0 +1,43 @@ +package main + +import ( + "embed" + _ "embed" + "log" + + "github.com/wailsapp/wails/v3/pkg/application" +) + +//go:embed frontend/dist +var assets embed.FS + +func main() { + app := application.New(application.Options{ + Name: "{{.ProjectName}}", + Description: "A demo of using raw HTML & CSS", + Mac: application.MacOptions{ + ApplicationShouldTerminateAfterLastWindowClosed: true, + }, + }) + // Create window + app.NewWebviewWindowWithOptions(&application.WebviewWindowOptions{ + Title: "Plain Bundle", + CSS: `body { background-color: rgba(255, 255, 255, 0); } .main { color: white; margin: 20%; }`, + Mac: application.MacWindow{ + InvisibleTitleBarHeight: 50, + Backdrop: application.MacBackdropTranslucent, + TitleBar: application.MacTitleBarHiddenInset, + }, + + URL: "/", + Assets: application.AssetOptions{ + FS: assets, + }, + }) + + err := app.Run() + + if err != nil { + log.Fatal(err) + } +} diff --git a/v3/internal/templates/vanilla-ts/main.tmpl.go b/v3/internal/templates/vanilla-ts/main.tmpl.go deleted file mode 100644 index ea8f138b8..000000000 --- a/v3/internal/templates/vanilla-ts/main.tmpl.go +++ /dev/null @@ -1,45 +0,0 @@ -package main - -import ( - "embed" - _ "embed" - "log" - - "github.com/wailsapp/wails/v3/pkg/options" - - "github.com/wailsapp/wails/v3/pkg/application" -) - -//go:embed frontend/dist -var assets embed.FS - -func main() { - app := application.New(options.Application{ - Name: "{{.ProjectName}}", - Description: "A demo of using raw HTML & CSS", - Mac: options.Mac{ - ApplicationShouldTerminateAfterLastWindowClosed: true, - }, - }) - // Create window - app.NewWebviewWindowWithOptions(&options.WebviewWindow{ - Title: "Plain Bundle", - CSS: `body { background-color: rgba(255, 255, 255, 0); } .main { color: white; margin: 20%; }`, - Mac: options.MacWindow{ - InvisibleTitleBarHeight: 50, - Backdrop: options.MacBackdropTranslucent, - TitleBar: options.TitleBarHiddenInset, - }, - - URL: "/", - Assets: options.Assets{ - FS: assets, - }, - }) - - err := app.Run() - - if err != nil { - log.Fatal(err) - } -} diff --git a/v3/internal/templates/vanilla/main.go.tmpl b/v3/internal/templates/vanilla/main.go.tmpl new file mode 100644 index 000000000..1bc6a4868 --- /dev/null +++ b/v3/internal/templates/vanilla/main.go.tmpl @@ -0,0 +1,43 @@ +package main + +import ( + "embed" + _ "embed" + "log" + + "github.com/wailsapp/wails/v3/pkg/application" +) + +//go:embed frontend/dist +var assets embed.FS + +func main() { + app := application.New(application.Options{ + Name: "{{.ProjectName}}", + Description: "A demo of using raw HTML & CSS", + Mac: application.MacOptions{ + ApplicationShouldTerminateAfterLastWindowClosed: true, + }, + }) + // Create window + app.NewWebviewWindowWithOptions(&application.WebviewWindowOptions{ + Title: "Plain Bundle", + CSS: `body { background-color: rgba(255, 255, 255, 0); } .main { color: white; margin: 20%; }`, + Mac: application.MacWindow{ + InvisibleTitleBarHeight: 50, + Backdrop: application.MacBackdropTranslucent, + TitleBar: application.MacTitleBarHiddenInset, + }, + + URL: "/", + Assets: application.AssetOptions{ + FS: assets, + }, + }) + + err := app.Run() + + if err != nil { + log.Fatal(err) + } +} diff --git a/v3/internal/templates/vanilla/main.tmpl.go b/v3/internal/templates/vanilla/main.tmpl.go deleted file mode 100644 index ea8f138b8..000000000 --- a/v3/internal/templates/vanilla/main.tmpl.go +++ /dev/null @@ -1,45 +0,0 @@ -package main - -import ( - "embed" - _ "embed" - "log" - - "github.com/wailsapp/wails/v3/pkg/options" - - "github.com/wailsapp/wails/v3/pkg/application" -) - -//go:embed frontend/dist -var assets embed.FS - -func main() { - app := application.New(options.Application{ - Name: "{{.ProjectName}}", - Description: "A demo of using raw HTML & CSS", - Mac: options.Mac{ - ApplicationShouldTerminateAfterLastWindowClosed: true, - }, - }) - // Create window - app.NewWebviewWindowWithOptions(&options.WebviewWindow{ - Title: "Plain Bundle", - CSS: `body { background-color: rgba(255, 255, 255, 0); } .main { color: white; margin: 20%; }`, - Mac: options.MacWindow{ - InvisibleTitleBarHeight: 50, - Backdrop: options.MacBackdropTranslucent, - TitleBar: options.TitleBarHiddenInset, - }, - - URL: "/", - Assets: options.Assets{ - FS: assets, - }, - }) - - err := app.Run() - - if err != nil { - log.Fatal(err) - } -} diff --git a/v3/internal/templates/vue-ts/main.go.tmpl b/v3/internal/templates/vue-ts/main.go.tmpl new file mode 100644 index 000000000..1bc6a4868 --- /dev/null +++ b/v3/internal/templates/vue-ts/main.go.tmpl @@ -0,0 +1,43 @@ +package main + +import ( + "embed" + _ "embed" + "log" + + "github.com/wailsapp/wails/v3/pkg/application" +) + +//go:embed frontend/dist +var assets embed.FS + +func main() { + app := application.New(application.Options{ + Name: "{{.ProjectName}}", + Description: "A demo of using raw HTML & CSS", + Mac: application.MacOptions{ + ApplicationShouldTerminateAfterLastWindowClosed: true, + }, + }) + // Create window + app.NewWebviewWindowWithOptions(&application.WebviewWindowOptions{ + Title: "Plain Bundle", + CSS: `body { background-color: rgba(255, 255, 255, 0); } .main { color: white; margin: 20%; }`, + Mac: application.MacWindow{ + InvisibleTitleBarHeight: 50, + Backdrop: application.MacBackdropTranslucent, + TitleBar: application.MacTitleBarHiddenInset, + }, + + URL: "/", + Assets: application.AssetOptions{ + FS: assets, + }, + }) + + err := app.Run() + + if err != nil { + log.Fatal(err) + } +} diff --git a/v3/internal/templates/vue-ts/main.tmpl.go b/v3/internal/templates/vue-ts/main.tmpl.go deleted file mode 100644 index ea8f138b8..000000000 --- a/v3/internal/templates/vue-ts/main.tmpl.go +++ /dev/null @@ -1,45 +0,0 @@ -package main - -import ( - "embed" - _ "embed" - "log" - - "github.com/wailsapp/wails/v3/pkg/options" - - "github.com/wailsapp/wails/v3/pkg/application" -) - -//go:embed frontend/dist -var assets embed.FS - -func main() { - app := application.New(options.Application{ - Name: "{{.ProjectName}}", - Description: "A demo of using raw HTML & CSS", - Mac: options.Mac{ - ApplicationShouldTerminateAfterLastWindowClosed: true, - }, - }) - // Create window - app.NewWebviewWindowWithOptions(&options.WebviewWindow{ - Title: "Plain Bundle", - CSS: `body { background-color: rgba(255, 255, 255, 0); } .main { color: white; margin: 20%; }`, - Mac: options.MacWindow{ - InvisibleTitleBarHeight: 50, - Backdrop: options.MacBackdropTranslucent, - TitleBar: options.TitleBarHiddenInset, - }, - - URL: "/", - Assets: options.Assets{ - FS: assets, - }, - }) - - err := app.Run() - - if err != nil { - log.Fatal(err) - } -} diff --git a/v3/internal/templates/vue/main.go.tmpl b/v3/internal/templates/vue/main.go.tmpl new file mode 100644 index 000000000..1bc6a4868 --- /dev/null +++ b/v3/internal/templates/vue/main.go.tmpl @@ -0,0 +1,43 @@ +package main + +import ( + "embed" + _ "embed" + "log" + + "github.com/wailsapp/wails/v3/pkg/application" +) + +//go:embed frontend/dist +var assets embed.FS + +func main() { + app := application.New(application.Options{ + Name: "{{.ProjectName}}", + Description: "A demo of using raw HTML & CSS", + Mac: application.MacOptions{ + ApplicationShouldTerminateAfterLastWindowClosed: true, + }, + }) + // Create window + app.NewWebviewWindowWithOptions(&application.WebviewWindowOptions{ + Title: "Plain Bundle", + CSS: `body { background-color: rgba(255, 255, 255, 0); } .main { color: white; margin: 20%; }`, + Mac: application.MacWindow{ + InvisibleTitleBarHeight: 50, + Backdrop: application.MacBackdropTranslucent, + TitleBar: application.MacTitleBarHiddenInset, + }, + + URL: "/", + Assets: application.AssetOptions{ + FS: assets, + }, + }) + + err := app.Run() + + if err != nil { + log.Fatal(err) + } +} diff --git a/v3/internal/templates/vue/main.tmpl.go b/v3/internal/templates/vue/main.tmpl.go deleted file mode 100644 index ea8f138b8..000000000 --- a/v3/internal/templates/vue/main.tmpl.go +++ /dev/null @@ -1,45 +0,0 @@ -package main - -import ( - "embed" - _ "embed" - "log" - - "github.com/wailsapp/wails/v3/pkg/options" - - "github.com/wailsapp/wails/v3/pkg/application" -) - -//go:embed frontend/dist -var assets embed.FS - -func main() { - app := application.New(options.Application{ - Name: "{{.ProjectName}}", - Description: "A demo of using raw HTML & CSS", - Mac: options.Mac{ - ApplicationShouldTerminateAfterLastWindowClosed: true, - }, - }) - // Create window - app.NewWebviewWindowWithOptions(&options.WebviewWindow{ - Title: "Plain Bundle", - CSS: `body { background-color: rgba(255, 255, 255, 0); } .main { color: white; margin: 20%; }`, - Mac: options.MacWindow{ - InvisibleTitleBarHeight: 50, - Backdrop: options.MacBackdropTranslucent, - TitleBar: options.TitleBarHiddenInset, - }, - - URL: "/", - Assets: options.Assets{ - FS: assets, - }, - }) - - err := app.Run() - - if err != nil { - log.Fatal(err) - } -} diff --git a/v3/pkg/application/app_delegate.m b/v3/pkg/application/app_delegate.m index af7510935..d20a48fda 100644 --- a/v3/pkg/application/app_delegate.m +++ b/v3/pkg/application/app_delegate.m @@ -1,22 +1,17 @@ //go:build darwin - #import "app_delegate.h" #import "../events/events.h" - extern bool hasListeners(unsigned int); - @implementation AppDelegate - (void)dealloc { [super dealloc]; } - // Create the applicationShouldTerminateAfterLastWindowClosed: method - (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)theApplication { return self.shouldTerminateWhenLastWindowClosed; } - // GENERATED EVENTS START - (void)applicationDidBecomeActive:(NSNotification *)notification { if( hasListeners(EventApplicationDidBecomeActive) ) { diff --git a/v3/pkg/application/application_darwin.go b/v3/pkg/application/application_darwin.go index 250f90972..12b9c4300 100644 --- a/v3/pkg/application/application_darwin.go +++ b/v3/pkg/application/application_darwin.go @@ -230,6 +230,20 @@ func processURLRequest(windowID C.uint, wkUrlSchemeTask unsafe.Pointer) { } } +//export processDragItems +func processDragItems(windowID C.uint, arr **C.char, length C.int) { + var filenames []string + // Convert the C array to a Go slice + goSlice := (*[1 << 30]*C.char)(unsafe.Pointer(arr))[:length:length] + for _, str := range goSlice { + filenames = append(filenames, C.GoString(str)) + } + windowDragAndDropBuffer <- &dragAndDropMessage{ + windowId: uint(windowID), + filenames: filenames, + } +} + //export processMenuItemClick func processMenuItemClick(menuID C.uint) { menuItemClicked <- uint(menuID) diff --git a/v3/pkg/application/context.go b/v3/pkg/application/context.go index fff4675ef..56b213350 100644 --- a/v3/pkg/application/context.go +++ b/v3/pkg/application/context.go @@ -14,6 +14,7 @@ func newContext() *Context { const ( clickedMenuItem string = "clickedMenuItem" menuItemIsChecked string = "menuItemIsChecked" + contextMenuData string = "contextMenuData" ) func (c *Context) ClickedMenuItem() *MenuItem { @@ -31,6 +32,9 @@ func (c *Context) IsChecked() bool { } return result.(bool) } +func (c *Context) ContextMenuData() any { + return c.data[contextMenuData] +} func (c *Context) withClickedMenuItem(menuItem *MenuItem) *Context { c.data[clickedMenuItem] = menuItem @@ -40,3 +44,11 @@ func (c *Context) withClickedMenuItem(menuItem *MenuItem) *Context { func (c *Context) withChecked(checked bool) { c.data[menuItemIsChecked] = checked } + +func (c *Context) withContextMenuData(data *ContextMenuData) *Context { + if data == nil { + return c + } + c.data[contextMenuData] = data.Data + return c +} diff --git a/v3/pkg/application/context_window_event.go b/v3/pkg/application/context_window_event.go new file mode 100644 index 000000000..f9895fbd2 --- /dev/null +++ b/v3/pkg/application/context_window_event.go @@ -0,0 +1,35 @@ +package application + +var blankWindowEventContext = &WindowEventContext{} + +const ( + // FilesDropped is the event name for when files are dropped on the window + droppedFiles = "droppedFiles" +) + +type WindowEventContext struct { + // contains filtered or unexported fields + data map[string]any +} + +func (c WindowEventContext) DroppedFiles() []string { + files, ok := c.data[droppedFiles] + if !ok { + return nil + } + result, ok := files.([]string) + if !ok { + return nil + } + return result +} + +func (c WindowEventContext) setDroppedFiles(files []string) { + c.data[droppedFiles] = files +} + +func newWindowEventContext() *WindowEventContext { + return &WindowEventContext{ + data: make(map[string]any), + } +} diff --git a/v3/pkg/application/menu.go b/v3/pkg/application/menu.go index 5d56c3584..80cf213dd 100644 --- a/v3/pkg/application/menu.go +++ b/v3/pkg/application/menu.go @@ -87,6 +87,12 @@ func (m *Menu) SetLabel(label string) { m.label = label } +func (m *Menu) setContextData(data *ContextMenuData) { + for _, item := range m.items { + item.setContextData(data) + } +} + func (a *App) NewMenu() *Menu { return &Menu{} } diff --git a/v3/pkg/application/menuitem.go b/v3/pkg/application/menuitem.go index 2603f0c02..da943156b 100644 --- a/v3/pkg/application/menuitem.go +++ b/v3/pkg/application/menuitem.go @@ -41,16 +41,17 @@ type menuItemImpl interface { } type MenuItem struct { - id uint - label string - tooltip string - disabled bool - checked bool - submenu *Menu - callback func(*Context) - itemType menuItemType - accelerator *accelerator - role Role + id uint + label string + tooltip string + disabled bool + checked bool + submenu *Menu + callback func(*Context) + itemType menuItemType + accelerator *accelerator + role Role + contextMenuData *ContextMenuData impl menuItemImpl radioGroupMembers []*MenuItem @@ -187,7 +188,9 @@ func newServicesMenu() *MenuItem { } func (m *MenuItem) handleClick() { - var ctx = newContext().withClickedMenuItem(m) + var ctx = newContext(). + withClickedMenuItem(m). + withContextMenuData(m.contextMenuData) if m.itemType == checkbox { m.checked = !m.checked ctx.withChecked(m.checked) @@ -272,3 +275,10 @@ func (m *MenuItem) Tooltip() string { func (m *MenuItem) Enabled() bool { return !m.disabled } + +func (m *MenuItem) setContextData(data *ContextMenuData) { + m.contextMenuData = data + if m.submenu != nil { + m.submenu.setContextData(data) + } +} diff --git a/v3/pkg/application/messageprocessor_contextmenu.go b/v3/pkg/application/messageprocessor_contextmenu.go new file mode 100644 index 000000000..d0fe57c98 --- /dev/null +++ b/v3/pkg/application/messageprocessor_contextmenu.go @@ -0,0 +1,30 @@ +package application + +import ( + "net/http" +) + +type ContextMenuData struct { + Id string `json:"id"` + X int `json:"x"` + Y int `json:"y"` + Data any `json:"data"` +} + +func (m *MessageProcessor) processContextMenuMethod(method string, rw http.ResponseWriter, _ *http.Request, window *WebviewWindow, params QueryParams) { + + switch method { + case "OpenContextMenu": + var data ContextMenuData + err := params.ToStruct(&data) + if err != nil { + m.httpError(rw, "error parsing contextmenu message: %s", err.Error()) + return + } + window.openContextMenu(&data) + m.ok(rw) + default: + m.httpError(rw, "Unknown clipboard method: %s", method) + } + +} diff --git a/v3/pkg/application/options_application.go b/v3/pkg/application/options_application.go new file mode 100644 index 000000000..cfb11ee76 --- /dev/null +++ b/v3/pkg/application/options_application.go @@ -0,0 +1,17 @@ +package application + +import ( + "github.com/wailsapp/wails/v3/pkg/logger" +) + +type Options struct { + Name string + Description string + Icon []byte + Mac MacOptions + Bind []any + Logger struct { + Silent bool + CustomLoggers []logger.Output + } +} diff --git a/v3/pkg/options/mac.go b/v3/pkg/application/options_mac.go similarity index 87% rename from v3/pkg/options/mac.go rename to v3/pkg/application/options_mac.go index ec5f2cc33..7ad1c5f0f 100644 --- a/v3/pkg/options/mac.go +++ b/v3/pkg/application/options_mac.go @@ -1,4 +1,4 @@ -package options +package application type ActivationPolicy int @@ -10,7 +10,7 @@ const ( ActivationPolicyProhibited ) -type Mac struct { +type MacOptions struct { // ActivationPolicy is the activation policy for the application. Defaults to // applicationActivationPolicyRegular. ActivationPolicy ActivationPolicy @@ -44,13 +44,13 @@ const ( // MacWindow contains macOS specific options type MacWindow struct { Backdrop MacBackdrop - TitleBar TitleBar + TitleBar MacTitleBar Appearance MacAppearanceType InvisibleTitleBarHeight int } -// TitleBar contains options for the Mac titlebar -type TitleBar struct { +// MacTitleBar contains options for the Mac titlebar +type MacTitleBar struct { AppearsTransparent bool Hide bool HideTitle bool @@ -60,8 +60,8 @@ type TitleBar struct { ToolbarStyle MacToolbarStyle } -// TitleBarDefault results in the default Mac TitleBar -var TitleBarDefault = TitleBar{ +// MacTitleBarDefault results in the default Mac MacTitleBar +var MacTitleBarDefault = MacTitleBar{ AppearsTransparent: false, Hide: false, HideTitle: false, @@ -72,10 +72,10 @@ var TitleBarDefault = TitleBar{ // Credit: Comments from Electron site -// TitleBarHidden results in a hidden title bar and a full size content window, +// MacTitleBarHidden results in a hidden title bar and a full size content window, // yet the title bar still has the standard window controls (“traffic lights”) // in the top left. -var TitleBarHidden = TitleBar{ +var MacTitleBarHidden = MacTitleBar{ AppearsTransparent: true, Hide: false, HideTitle: true, @@ -84,9 +84,9 @@ var TitleBarHidden = TitleBar{ HideToolbarSeparator: false, } -// TitleBarHiddenInset results in a hidden title bar with an alternative look where +// MacTitleBarHiddenInset results in a hidden title bar with an alternative look where // the traffic light buttons are slightly more inset from the window edge. -var TitleBarHiddenInset = TitleBar{ +var MacTitleBarHiddenInset = MacTitleBar{ AppearsTransparent: true, Hide: false, HideTitle: true, @@ -95,9 +95,9 @@ var TitleBarHiddenInset = TitleBar{ HideToolbarSeparator: true, } -// TitleBarHiddenInsetUnified results in a hidden title bar with an alternative look where +// MacTitleBarHiddenInsetUnified results in a hidden title bar with an alternative look where // the traffic light buttons are even more inset from the window edge. -var TitleBarHiddenInsetUnified = TitleBar{ +var MacTitleBarHiddenInsetUnified = MacTitleBar{ AppearsTransparent: true, Hide: false, HideTitle: true, diff --git a/v3/pkg/options/window.go b/v3/pkg/application/options_webview_window.go similarity index 100% rename from v3/pkg/options/window.go rename to v3/pkg/application/options_webview_window.go diff --git a/v3/pkg/application/webview_drag.h b/v3/pkg/application/webview_drag.h new file mode 100644 index 000000000..aca00d970 --- /dev/null +++ b/v3/pkg/application/webview_drag.h @@ -0,0 +1,7 @@ +//go:build darwin + +#import + +@interface WebviewDrag : NSView +@property unsigned int windowId; +@end \ No newline at end of file diff --git a/v3/pkg/application/webview_drag.m b/v3/pkg/application/webview_drag.m new file mode 100644 index 000000000..32d8f40b9 --- /dev/null +++ b/v3/pkg/application/webview_drag.m @@ -0,0 +1,59 @@ +//go:build darwin + +#import +#import +#import "webview_drag.h" + +#import "../events/events.h" + +extern void processDragItems(unsigned int windowId, char** arr, int length); + +@implementation WebviewDrag + +- (instancetype)initWithFrame:(NSRect)frameRect { + self = [super initWithFrame:frameRect]; + if (self) { + [self registerForDraggedTypes:@[NSFilenamesPboardType]]; + } + + return self; +} + +- (NSDragOperation)draggingEntered:(id)sender { + NSPasteboard *pasteboard = [sender draggingPasteboard]; + if ([[pasteboard types] containsObject:NSFilenamesPboardType]) { + processWindowEvent(self.windowId, EventWebViewDraggingEntered); + return NSDragOperationCopy; + } + return NSDragOperationNone; +} + + +- (void)draggingExited:(id)sender { + NSLog(@"I am here!!!!"); +} + +- (BOOL)prepareForDragOperation:(id)sender { + return YES; +} + +- (BOOL)performDragOperation:(id)sender { + NSPasteboard *pasteboard = [sender draggingPasteboard]; + if ([[pasteboard types] containsObject:NSFilenamesPboardType]) { + NSArray *files = [pasteboard propertyListForType:NSFilenamesPboardType]; + NSUInteger count = [files count]; + char** cArray = (char**)malloc(count * sizeof(char*)); + for (NSUInteger i = 0; i < count; i++) { + NSString* str = files[i]; + cArray[i] = (char*)[str UTF8String]; + } + processDragItems(self.windowId, cArray, (int)count); + free(cArray); + return YES; + } + return NO; +} + + +@end + diff --git a/v3/pkg/application/webview_window.h b/v3/pkg/application/webview_window.h index 72d56ee36..1a462d5a6 100644 --- a/v3/pkg/application/webview_window.h +++ b/v3/pkg/application/webview_window.h @@ -16,7 +16,7 @@ @end -@interface WebviewWindowDelegate : NSObject +@interface WebviewWindowDelegate : NSObject @property bool hideOnClose; @property (retain) WKWebView* webView; @@ -29,7 +29,6 @@ - (void)handleLeftMouseUp:(NSWindow *)window; - (void)handleLeftMouseDown:(NSEvent*)event; - @end diff --git a/v3/pkg/application/webview_window.m b/v3/pkg/application/webview_window.m index 504871764..3f33bcca5 100644 --- a/v3/pkg/application/webview_window.m +++ b/v3/pkg/application/webview_window.m @@ -1,16 +1,12 @@ //go:build darwin - #import #import #import "webview_window.h" #import "../events/events.h" - extern void processMessage(unsigned int, const char*); extern void processURLRequest(unsigned int, void *); extern bool hasListeners(unsigned int); - @implementation WebviewWindow - - (WebviewWindow*) initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)windowStyle backing:(NSBackingStoreType)bufferingType defer:(BOOL)deferCreation; { self = [super initWithContentRect:contentRect styleMask:windowStyle backing:bufferingType defer:deferCreation]; @@ -20,11 +16,9 @@ extern bool hasListeners(unsigned int); [self setMovableByWindowBackground:YES]; return self; } - - (BOOL)canBecomeKeyWindow { return YES; } - - (BOOL) canBecomeMainWindow { return YES; } @@ -38,9 +32,7 @@ extern bool hasListeners(unsigned int); return YES; } @end - @implementation WebviewWindowDelegate - - (BOOL)windowShouldClose:(NSWindow *)sender { if( self.hideOnClose ) { [NSApp hide:nil]; @@ -48,7 +40,6 @@ extern bool hasListeners(unsigned int); } return true; } - // Handle script messages from the external bridge - (void)userContentController:(nonnull WKUserContentController *)userContentController didReceiveScriptMessage:(nonnull WKScriptMessage *)message { NSString *m = message.body; @@ -83,11 +74,9 @@ extern bool hasListeners(unsigned int); - (void)handleLeftMouseUp:(NSWindow *)window { self.leftMouseEvent = nil; } - - (void)webView:(nonnull WKWebView *)webView startURLSchemeTask:(nonnull id)urlSchemeTask { processURLRequest(self.windowId, urlSchemeTask); } - - (void)webView:(nonnull WKWebView *)webView stopURLSchemeTask:(nonnull id)urlSchemeTask { NSInputStream *stream = urlSchemeTask.request.HTTPBodyStream; if (stream) { @@ -97,7 +86,6 @@ extern bool hasListeners(unsigned int); } } } - // GENERATED EVENTS START - (void)windowDidBecomeKey:(NSNotification *)notification { if( hasListeners(EventWindowDidBecomeKey) ) { @@ -561,5 +549,17 @@ extern bool hasListeners(unsigned int); } } +- (void)webView:(WKWebView *)webview draggingEntered:(WKNavigation *)navigation { + if( hasListeners(EventWebViewDraggingEntered) ) { + processWindowEvent(self.windowId, EventWebViewDraggingEntered); + } +} + +- (void)webView:(WKWebView *)webview draggingPerformed:(WKNavigation *)navigation { + if( hasListeners(EventWebViewDraggingPerformed) ) { + processWindowEvent(self.windowId, EventWebViewDraggingPerformed); + } +} + // GENERATED EVENTS END @end diff --git a/v3/pkg/events/events.go b/v3/pkg/events/events.go index f003e7c49..2a6238388 100644 --- a/v3/pkg/events/events.go +++ b/v3/pkg/events/events.go @@ -3,6 +3,10 @@ package events type ApplicationEventType uint type WindowEventType uint +const ( + FilesDropped WindowEventType = iota +) + var Mac = newMacEvents() type macEvents struct { @@ -126,129 +130,133 @@ type macEvents struct { WebViewDidReceiveServerRedirectForProvisionalNavigation WindowEventType WebViewDidFinishNavigation WindowEventType WebViewDidCommitNavigation WindowEventType + WebViewDraggingEntered WindowEventType + WebViewDraggingPerformed WindowEventType } func newMacEvents() macEvents { return macEvents{ - ApplicationDidBecomeActive: 0, - ApplicationDidChangeBackingProperties: 1, - ApplicationDidChangeEffectiveAppearance: 2, - ApplicationDidChangeIcon: 3, - ApplicationDidChangeOcclusionState: 4, - ApplicationDidChangeScreenParameters: 5, - ApplicationDidChangeStatusBarFrame: 6, - ApplicationDidChangeStatusBarOrientation: 7, - ApplicationDidFinishLaunching: 8, - ApplicationDidHide: 9, - ApplicationDidResignActive: 10, - ApplicationDidUnhide: 11, - ApplicationDidUpdate: 12, - ApplicationWillBecomeActive: 13, - ApplicationWillFinishLaunching: 14, - ApplicationWillHide: 15, - ApplicationWillResignActive: 16, - ApplicationWillTerminate: 17, - ApplicationWillUnhide: 18, - ApplicationWillUpdate: 19, - WindowDidBecomeKey: 20, - WindowDidBecomeMain: 21, - WindowDidBeginSheet: 22, - WindowDidChangeAlpha: 23, - WindowDidChangeBackingLocation: 24, - WindowDidChangeBackingProperties: 25, - WindowDidChangeCollectionBehavior: 26, - WindowDidChangeEffectiveAppearance: 27, - WindowDidChangeOcclusionState: 28, - WindowDidChangeOrderingMode: 29, - WindowDidChangeScreen: 30, - WindowDidChangeScreenParameters: 31, - WindowDidChangeScreenProfile: 32, - WindowDidChangeScreenSpace: 33, - WindowDidChangeScreenSpaceProperties: 34, - WindowDidChangeSharingType: 35, - WindowDidChangeSpace: 36, - WindowDidChangeSpaceOrderingMode: 37, - WindowDidChangeTitle: 38, - WindowDidChangeToolbar: 39, - WindowDidChangeVisibility: 40, - WindowDidClose: 41, - WindowDidDeminiaturize: 42, - WindowDidEndSheet: 43, - WindowDidEnterFullScreen: 44, - WindowDidEnterVersionBrowser: 45, - WindowDidExitFullScreen: 46, - WindowDidExitVersionBrowser: 47, - WindowDidExpose: 48, - WindowDidFocus: 49, - WindowDidMiniaturize: 50, - WindowDidMove: 51, - WindowDidOrderOffScreen: 52, - WindowDidOrderOnScreen: 53, - WindowDidResignKey: 54, - WindowDidResignMain: 55, - WindowDidResize: 56, - WindowDidUnfocus: 57, - WindowDidUpdate: 58, - WindowDidUpdateAlpha: 59, - WindowDidUpdateCollectionBehavior: 60, - WindowDidUpdateCollectionProperties: 61, - WindowDidUpdateShadow: 62, - WindowDidUpdateTitle: 63, - WindowDidUpdateToolbar: 64, - WindowDidUpdateVisibility: 65, - WindowWillBecomeKey: 66, - WindowWillBecomeMain: 67, - WindowWillBeginSheet: 68, - WindowWillChangeOrderingMode: 69, - WindowWillClose: 70, - WindowWillDeminiaturize: 71, - WindowWillEnterFullScreen: 72, - WindowWillEnterVersionBrowser: 73, - WindowWillExitFullScreen: 74, - WindowWillExitVersionBrowser: 75, - WindowWillFocus: 76, - WindowWillMiniaturize: 77, - WindowWillMove: 78, - WindowWillOrderOffScreen: 79, - WindowWillOrderOnScreen: 80, - WindowWillResignMain: 81, - WindowWillResize: 82, - WindowWillUnfocus: 83, - WindowWillUpdate: 84, - WindowWillUpdateAlpha: 85, - WindowWillUpdateCollectionBehavior: 86, - WindowWillUpdateCollectionProperties: 87, - WindowWillUpdateShadow: 88, - WindowWillUpdateTitle: 89, - WindowWillUpdateToolbar: 90, - WindowWillUpdateVisibility: 91, - WindowWillUseStandardFrame: 92, - MenuWillOpen: 93, - MenuDidOpen: 94, - MenuDidClose: 95, - MenuWillSendAction: 96, - MenuDidSendAction: 97, - MenuWillHighlightItem: 98, - MenuDidHighlightItem: 99, - MenuWillDisplayItem: 100, - MenuDidDisplayItem: 101, - MenuWillAddItem: 102, - MenuDidAddItem: 103, - MenuWillRemoveItem: 104, - MenuDidRemoveItem: 105, - MenuWillBeginTracking: 106, - MenuDidBeginTracking: 107, - MenuWillEndTracking: 108, - MenuDidEndTracking: 109, - MenuWillUpdate: 110, - MenuDidUpdate: 111, - MenuWillPopUp: 112, - MenuDidPopUp: 113, - MenuWillSendActionToItem: 114, - MenuDidSendActionToItem: 115, - WebViewDidStartProvisionalNavigation: 116, - WebViewDidReceiveServerRedirectForProvisionalNavigation: 117, - WebViewDidFinishNavigation: 118, - WebViewDidCommitNavigation: 119, + ApplicationDidBecomeActive: 1024, + ApplicationDidChangeBackingProperties: 1025, + ApplicationDidChangeEffectiveAppearance: 1026, + ApplicationDidChangeIcon: 1027, + ApplicationDidChangeOcclusionState: 1028, + ApplicationDidChangeScreenParameters: 1029, + ApplicationDidChangeStatusBarFrame: 1030, + ApplicationDidChangeStatusBarOrientation: 1031, + ApplicationDidFinishLaunching: 1032, + ApplicationDidHide: 1033, + ApplicationDidResignActive: 1034, + ApplicationDidUnhide: 1035, + ApplicationDidUpdate: 1036, + ApplicationWillBecomeActive: 1037, + ApplicationWillFinishLaunching: 1038, + ApplicationWillHide: 1039, + ApplicationWillResignActive: 1040, + ApplicationWillTerminate: 1041, + ApplicationWillUnhide: 1042, + ApplicationWillUpdate: 1043, + WindowDidBecomeKey: 1044, + WindowDidBecomeMain: 1045, + WindowDidBeginSheet: 1046, + WindowDidChangeAlpha: 1047, + WindowDidChangeBackingLocation: 1048, + WindowDidChangeBackingProperties: 1049, + WindowDidChangeCollectionBehavior: 1050, + WindowDidChangeEffectiveAppearance: 1051, + WindowDidChangeOcclusionState: 1052, + WindowDidChangeOrderingMode: 1053, + WindowDidChangeScreen: 1054, + WindowDidChangeScreenParameters: 1055, + WindowDidChangeScreenProfile: 1056, + WindowDidChangeScreenSpace: 1057, + WindowDidChangeScreenSpaceProperties: 1058, + WindowDidChangeSharingType: 1059, + WindowDidChangeSpace: 1060, + WindowDidChangeSpaceOrderingMode: 1061, + WindowDidChangeTitle: 1062, + WindowDidChangeToolbar: 1063, + WindowDidChangeVisibility: 1064, + WindowDidClose: 1065, + WindowDidDeminiaturize: 1066, + WindowDidEndSheet: 1067, + WindowDidEnterFullScreen: 1068, + WindowDidEnterVersionBrowser: 1069, + WindowDidExitFullScreen: 1070, + WindowDidExitVersionBrowser: 1071, + WindowDidExpose: 1072, + WindowDidFocus: 1073, + WindowDidMiniaturize: 1074, + WindowDidMove: 1075, + WindowDidOrderOffScreen: 1076, + WindowDidOrderOnScreen: 1077, + WindowDidResignKey: 1078, + WindowDidResignMain: 1079, + WindowDidResize: 1080, + WindowDidUnfocus: 1081, + WindowDidUpdate: 1082, + WindowDidUpdateAlpha: 1083, + WindowDidUpdateCollectionBehavior: 1084, + WindowDidUpdateCollectionProperties: 1085, + WindowDidUpdateShadow: 1086, + WindowDidUpdateTitle: 1087, + WindowDidUpdateToolbar: 1088, + WindowDidUpdateVisibility: 1089, + WindowWillBecomeKey: 1090, + WindowWillBecomeMain: 1091, + WindowWillBeginSheet: 1092, + WindowWillChangeOrderingMode: 1093, + WindowWillClose: 1094, + WindowWillDeminiaturize: 1095, + WindowWillEnterFullScreen: 1096, + WindowWillEnterVersionBrowser: 1097, + WindowWillExitFullScreen: 1098, + WindowWillExitVersionBrowser: 1099, + WindowWillFocus: 1100, + WindowWillMiniaturize: 1101, + WindowWillMove: 1102, + WindowWillOrderOffScreen: 1103, + WindowWillOrderOnScreen: 1104, + WindowWillResignMain: 1105, + WindowWillResize: 1106, + WindowWillUnfocus: 1107, + WindowWillUpdate: 1108, + WindowWillUpdateAlpha: 1109, + WindowWillUpdateCollectionBehavior: 1110, + WindowWillUpdateCollectionProperties: 1111, + WindowWillUpdateShadow: 1112, + WindowWillUpdateTitle: 1113, + WindowWillUpdateToolbar: 1114, + WindowWillUpdateVisibility: 1115, + WindowWillUseStandardFrame: 1116, + MenuWillOpen: 1117, + MenuDidOpen: 1118, + MenuDidClose: 1119, + MenuWillSendAction: 1120, + MenuDidSendAction: 1121, + MenuWillHighlightItem: 1122, + MenuDidHighlightItem: 1123, + MenuWillDisplayItem: 1124, + MenuDidDisplayItem: 1125, + MenuWillAddItem: 1126, + MenuDidAddItem: 1127, + MenuWillRemoveItem: 1128, + MenuDidRemoveItem: 1129, + MenuWillBeginTracking: 1130, + MenuDidBeginTracking: 1131, + MenuWillEndTracking: 1132, + MenuDidEndTracking: 1133, + MenuWillUpdate: 1134, + MenuDidUpdate: 1135, + MenuWillPopUp: 1136, + MenuDidPopUp: 1137, + MenuWillSendActionToItem: 1138, + MenuDidSendActionToItem: 1139, + WebViewDidStartProvisionalNavigation: 1140, + WebViewDidReceiveServerRedirectForProvisionalNavigation: 1141, + WebViewDidFinishNavigation: 1142, + WebViewDidCommitNavigation: 1143, + WebViewDraggingEntered: 1144, + WebViewDraggingPerformed: 1145, } } diff --git a/v3/pkg/events/events.h b/v3/pkg/events/events.h index 2d1e56d6d..0520a6480 100644 --- a/v3/pkg/events/events.h +++ b/v3/pkg/events/events.h @@ -6,128 +6,130 @@ extern void processApplicationEvent(unsigned int); extern void processWindowEvent(unsigned int, unsigned int); -#define EventApplicationDidBecomeActive 0 -#define EventApplicationDidChangeBackingProperties 1 -#define EventApplicationDidChangeEffectiveAppearance 2 -#define EventApplicationDidChangeIcon 3 -#define EventApplicationDidChangeOcclusionState 4 -#define EventApplicationDidChangeScreenParameters 5 -#define EventApplicationDidChangeStatusBarFrame 6 -#define EventApplicationDidChangeStatusBarOrientation 7 -#define EventApplicationDidFinishLaunching 8 -#define EventApplicationDidHide 9 -#define EventApplicationDidResignActive 10 -#define EventApplicationDidUnhide 11 -#define EventApplicationDidUpdate 12 -#define EventApplicationWillBecomeActive 13 -#define EventApplicationWillFinishLaunching 14 -#define EventApplicationWillHide 15 -#define EventApplicationWillResignActive 16 -#define EventApplicationWillTerminate 17 -#define EventApplicationWillUnhide 18 -#define EventApplicationWillUpdate 19 -#define EventWindowDidBecomeKey 20 -#define EventWindowDidBecomeMain 21 -#define EventWindowDidBeginSheet 22 -#define EventWindowDidChangeAlpha 23 -#define EventWindowDidChangeBackingLocation 24 -#define EventWindowDidChangeBackingProperties 25 -#define EventWindowDidChangeCollectionBehavior 26 -#define EventWindowDidChangeEffectiveAppearance 27 -#define EventWindowDidChangeOcclusionState 28 -#define EventWindowDidChangeOrderingMode 29 -#define EventWindowDidChangeScreen 30 -#define EventWindowDidChangeScreenParameters 31 -#define EventWindowDidChangeScreenProfile 32 -#define EventWindowDidChangeScreenSpace 33 -#define EventWindowDidChangeScreenSpaceProperties 34 -#define EventWindowDidChangeSharingType 35 -#define EventWindowDidChangeSpace 36 -#define EventWindowDidChangeSpaceOrderingMode 37 -#define EventWindowDidChangeTitle 38 -#define EventWindowDidChangeToolbar 39 -#define EventWindowDidChangeVisibility 40 -#define EventWindowDidClose 41 -#define EventWindowDidDeminiaturize 42 -#define EventWindowDidEndSheet 43 -#define EventWindowDidEnterFullScreen 44 -#define EventWindowDidEnterVersionBrowser 45 -#define EventWindowDidExitFullScreen 46 -#define EventWindowDidExitVersionBrowser 47 -#define EventWindowDidExpose 48 -#define EventWindowDidFocus 49 -#define EventWindowDidMiniaturize 50 -#define EventWindowDidMove 51 -#define EventWindowDidOrderOffScreen 52 -#define EventWindowDidOrderOnScreen 53 -#define EventWindowDidResignKey 54 -#define EventWindowDidResignMain 55 -#define EventWindowDidResize 56 -#define EventWindowDidUnfocus 57 -#define EventWindowDidUpdate 58 -#define EventWindowDidUpdateAlpha 59 -#define EventWindowDidUpdateCollectionBehavior 60 -#define EventWindowDidUpdateCollectionProperties 61 -#define EventWindowDidUpdateShadow 62 -#define EventWindowDidUpdateTitle 63 -#define EventWindowDidUpdateToolbar 64 -#define EventWindowDidUpdateVisibility 65 -#define EventWindowWillBecomeKey 66 -#define EventWindowWillBecomeMain 67 -#define EventWindowWillBeginSheet 68 -#define EventWindowWillChangeOrderingMode 69 -#define EventWindowWillClose 70 -#define EventWindowWillDeminiaturize 71 -#define EventWindowWillEnterFullScreen 72 -#define EventWindowWillEnterVersionBrowser 73 -#define EventWindowWillExitFullScreen 74 -#define EventWindowWillExitVersionBrowser 75 -#define EventWindowWillFocus 76 -#define EventWindowWillMiniaturize 77 -#define EventWindowWillMove 78 -#define EventWindowWillOrderOffScreen 79 -#define EventWindowWillOrderOnScreen 80 -#define EventWindowWillResignMain 81 -#define EventWindowWillResize 82 -#define EventWindowWillUnfocus 83 -#define EventWindowWillUpdate 84 -#define EventWindowWillUpdateAlpha 85 -#define EventWindowWillUpdateCollectionBehavior 86 -#define EventWindowWillUpdateCollectionProperties 87 -#define EventWindowWillUpdateShadow 88 -#define EventWindowWillUpdateTitle 89 -#define EventWindowWillUpdateToolbar 90 -#define EventWindowWillUpdateVisibility 91 -#define EventWindowWillUseStandardFrame 92 -#define EventMenuWillOpen 93 -#define EventMenuDidOpen 94 -#define EventMenuDidClose 95 -#define EventMenuWillSendAction 96 -#define EventMenuDidSendAction 97 -#define EventMenuWillHighlightItem 98 -#define EventMenuDidHighlightItem 99 -#define EventMenuWillDisplayItem 100 -#define EventMenuDidDisplayItem 101 -#define EventMenuWillAddItem 102 -#define EventMenuDidAddItem 103 -#define EventMenuWillRemoveItem 104 -#define EventMenuDidRemoveItem 105 -#define EventMenuWillBeginTracking 106 -#define EventMenuDidBeginTracking 107 -#define EventMenuWillEndTracking 108 -#define EventMenuDidEndTracking 109 -#define EventMenuWillUpdate 110 -#define EventMenuDidUpdate 111 -#define EventMenuWillPopUp 112 -#define EventMenuDidPopUp 113 -#define EventMenuWillSendActionToItem 114 -#define EventMenuDidSendActionToItem 115 -#define EventWebViewDidStartProvisionalNavigation 116 -#define EventWebViewDidReceiveServerRedirectForProvisionalNavigation 117 -#define EventWebViewDidFinishNavigation 118 -#define EventWebViewDidCommitNavigation 119 +#define EventApplicationDidBecomeActive 1024 +#define EventApplicationDidChangeBackingProperties 1025 +#define EventApplicationDidChangeEffectiveAppearance 1026 +#define EventApplicationDidChangeIcon 1027 +#define EventApplicationDidChangeOcclusionState 1028 +#define EventApplicationDidChangeScreenParameters 1029 +#define EventApplicationDidChangeStatusBarFrame 1030 +#define EventApplicationDidChangeStatusBarOrientation 1031 +#define EventApplicationDidFinishLaunching 1032 +#define EventApplicationDidHide 1033 +#define EventApplicationDidResignActive 1034 +#define EventApplicationDidUnhide 1035 +#define EventApplicationDidUpdate 1036 +#define EventApplicationWillBecomeActive 1037 +#define EventApplicationWillFinishLaunching 1038 +#define EventApplicationWillHide 1039 +#define EventApplicationWillResignActive 1040 +#define EventApplicationWillTerminate 1041 +#define EventApplicationWillUnhide 1042 +#define EventApplicationWillUpdate 1043 +#define EventWindowDidBecomeKey 1044 +#define EventWindowDidBecomeMain 1045 +#define EventWindowDidBeginSheet 1046 +#define EventWindowDidChangeAlpha 1047 +#define EventWindowDidChangeBackingLocation 1048 +#define EventWindowDidChangeBackingProperties 1049 +#define EventWindowDidChangeCollectionBehavior 1050 +#define EventWindowDidChangeEffectiveAppearance 1051 +#define EventWindowDidChangeOcclusionState 1052 +#define EventWindowDidChangeOrderingMode 1053 +#define EventWindowDidChangeScreen 1054 +#define EventWindowDidChangeScreenParameters 1055 +#define EventWindowDidChangeScreenProfile 1056 +#define EventWindowDidChangeScreenSpace 1057 +#define EventWindowDidChangeScreenSpaceProperties 1058 +#define EventWindowDidChangeSharingType 1059 +#define EventWindowDidChangeSpace 1060 +#define EventWindowDidChangeSpaceOrderingMode 1061 +#define EventWindowDidChangeTitle 1062 +#define EventWindowDidChangeToolbar 1063 +#define EventWindowDidChangeVisibility 1064 +#define EventWindowDidClose 1065 +#define EventWindowDidDeminiaturize 1066 +#define EventWindowDidEndSheet 1067 +#define EventWindowDidEnterFullScreen 1068 +#define EventWindowDidEnterVersionBrowser 1069 +#define EventWindowDidExitFullScreen 1070 +#define EventWindowDidExitVersionBrowser 1071 +#define EventWindowDidExpose 1072 +#define EventWindowDidFocus 1073 +#define EventWindowDidMiniaturize 1074 +#define EventWindowDidMove 1075 +#define EventWindowDidOrderOffScreen 1076 +#define EventWindowDidOrderOnScreen 1077 +#define EventWindowDidResignKey 1078 +#define EventWindowDidResignMain 1079 +#define EventWindowDidResize 1080 +#define EventWindowDidUnfocus 1081 +#define EventWindowDidUpdate 1082 +#define EventWindowDidUpdateAlpha 1083 +#define EventWindowDidUpdateCollectionBehavior 1084 +#define EventWindowDidUpdateCollectionProperties 1085 +#define EventWindowDidUpdateShadow 1086 +#define EventWindowDidUpdateTitle 1087 +#define EventWindowDidUpdateToolbar 1088 +#define EventWindowDidUpdateVisibility 1089 +#define EventWindowWillBecomeKey 1090 +#define EventWindowWillBecomeMain 1091 +#define EventWindowWillBeginSheet 1092 +#define EventWindowWillChangeOrderingMode 1093 +#define EventWindowWillClose 1094 +#define EventWindowWillDeminiaturize 1095 +#define EventWindowWillEnterFullScreen 1096 +#define EventWindowWillEnterVersionBrowser 1097 +#define EventWindowWillExitFullScreen 1098 +#define EventWindowWillExitVersionBrowser 1099 +#define EventWindowWillFocus 1100 +#define EventWindowWillMiniaturize 1101 +#define EventWindowWillMove 1102 +#define EventWindowWillOrderOffScreen 1103 +#define EventWindowWillOrderOnScreen 1104 +#define EventWindowWillResignMain 1105 +#define EventWindowWillResize 1106 +#define EventWindowWillUnfocus 1107 +#define EventWindowWillUpdate 1108 +#define EventWindowWillUpdateAlpha 1109 +#define EventWindowWillUpdateCollectionBehavior 1110 +#define EventWindowWillUpdateCollectionProperties 1111 +#define EventWindowWillUpdateShadow 1112 +#define EventWindowWillUpdateTitle 1113 +#define EventWindowWillUpdateToolbar 1114 +#define EventWindowWillUpdateVisibility 1115 +#define EventWindowWillUseStandardFrame 1116 +#define EventMenuWillOpen 1117 +#define EventMenuDidOpen 1118 +#define EventMenuDidClose 1119 +#define EventMenuWillSendAction 1120 +#define EventMenuDidSendAction 1121 +#define EventMenuWillHighlightItem 1122 +#define EventMenuDidHighlightItem 1123 +#define EventMenuWillDisplayItem 1124 +#define EventMenuDidDisplayItem 1125 +#define EventMenuWillAddItem 1126 +#define EventMenuDidAddItem 1127 +#define EventMenuWillRemoveItem 1128 +#define EventMenuDidRemoveItem 1129 +#define EventMenuWillBeginTracking 1130 +#define EventMenuDidBeginTracking 1131 +#define EventMenuWillEndTracking 1132 +#define EventMenuDidEndTracking 1133 +#define EventMenuWillUpdate 1134 +#define EventMenuDidUpdate 1135 +#define EventMenuWillPopUp 1136 +#define EventMenuDidPopUp 1137 +#define EventMenuWillSendActionToItem 1138 +#define EventMenuDidSendActionToItem 1139 +#define EventWebViewDidStartProvisionalNavigation 1140 +#define EventWebViewDidReceiveServerRedirectForProvisionalNavigation 1141 +#define EventWebViewDidFinishNavigation 1142 +#define EventWebViewDidCommitNavigation 1143 +#define EventWebViewDraggingEntered 1144 +#define EventWebViewDraggingPerformed 1145 -#define MAX_EVENTS 120 +#define MAX_EVENTS 1146 #endif \ No newline at end of file diff --git a/v3/pkg/events/events.txt b/v3/pkg/events/events.txt index 858bb2ad5..10ce2af5a 100644 --- a/v3/pkg/events/events.txt +++ b/v3/pkg/events/events.txt @@ -118,4 +118,7 @@ mac:WebViewDidStartProvisionalNavigation mac:WebViewDidReceiveServerRedirectForProvisionalNavigation mac:WebViewDidFinishNavigation mac:WebViewDidCommitNavigation +mac:WebViewDraggingEntered +mac:WebViewDraggingPerformed + diff --git a/v3/tasks/events/generate.go b/v3/tasks/events/generate.go index b14af8b7c..eafa27f89 100644 --- a/v3/tasks/events/generate.go +++ b/v3/tasks/events/generate.go @@ -12,6 +12,10 @@ var eventsGo = `package events type ApplicationEventType uint type WindowEventType uint +const ( + FilesDropped WindowEventType = iota +) + var Mac = newMacEvents() type macEvents struct { @@ -54,6 +58,9 @@ func main() { // Loop over each line in the file for id, line = range bytes.Split(eventNames, []byte{'\n'}) { + // First 1024 is reserved + id = id + 1024 + // Skip empty lines if len(line) == 0 { continue @@ -143,7 +150,7 @@ func main() { } // Load the window_delegate.m file - windowDelegate, err := os.ReadFile("../../pkg/application/window_delegate.m") + windowDelegate, err := os.ReadFile("../../pkg/application/webview_window.m") if err != nil { panic(err) } @@ -173,7 +180,7 @@ func main() { } } } - err = os.WriteFile("../../pkg/application/window_delegate.m", buffer.Bytes(), 0755) + err = os.WriteFile("../../pkg/application/webview_window.m", buffer.Bytes(), 0755) if err != nil { panic(err) }