diff --git a/docs/src/content/docs/concepts/architecture.mdx b/docs/src/content/docs/concepts/architecture.mdx index 5b4fdd823e8..d72affe3b2b 100644 --- a/docs/src/content/docs/concepts/architecture.mdx +++ b/docs/src/content/docs/concepts/architecture.mdx @@ -264,7 +264,7 @@ Frontend2 -> EventBus: "On('data-updated', handler)" **Example:** ```go // Go: Emit an event -app.EmitEvent("user-logged-in", user) +app.Event.Emit("user-logged-in", user) ``` ```javascript diff --git a/docs/src/content/docs/concepts/bridge.mdx b/docs/src/content/docs/concepts/bridge.mdx index 6ee3745d1bf..7593d896af2 100644 --- a/docs/src/content/docs/concepts/bridge.mdx +++ b/docs/src/content/docs/concepts/bridge.mdx @@ -538,7 +538,7 @@ func ProcessLargeFile(path string) error { for scanner.Scan() { lineNum++ // Emit progress events - app.EmitEvent("file-progress", map[string]interface{}{ + app.Event.Emit("file-progress", map[string]interface{}{ "line": lineNum, "text": scanner.Text(), }) diff --git a/docs/src/content/docs/concepts/build-system.mdx b/docs/src/content/docs/concepts/build-system.mdx index 0ac7d435e20..f9de52bc5e4 100644 --- a/docs/src/content/docs/concepts/build-system.mdx +++ b/docs/src/content/docs/concepts/build-system.mdx @@ -325,7 +325,7 @@ func main() { }, }) - app.NewWebviewWindow() + app.Window.New() app.Run() } ``` diff --git a/docs/src/content/docs/contributing/runtime-internals.mdx b/docs/src/content/docs/contributing/runtime-internals.mdx index 7d35ae91b7b..a569526273d 100644 --- a/docs/src/content/docs/contributing/runtime-internals.mdx +++ b/docs/src/content/docs/contributing/runtime-internals.mdx @@ -39,7 +39,7 @@ win := app.Window.New(&application.WebviewWindowOptions{ win.Show() ``` -`NewWebviewWindow` delegates to `internal/runtime/webview_window_*.go` where +`app.Window.New()` delegates to `internal/runtime/webview_window_*.go` where platform-specific constructors live: ``` diff --git a/docs/src/content/docs/faq.mdx b/docs/src/content/docs/faq.mdx index ffa28275c60..3e0a6bd1700 100644 --- a/docs/src/content/docs/faq.mdx +++ b/docs/src/content/docs/faq.mdx @@ -123,8 +123,8 @@ Use SignTool with your certificate. Yes! Wails v3 has native multi-window support: ```go -window1 := app.NewWebviewWindow() -window2 := app.NewWebviewWindow() +window1 := app.Window.New() +window2 := app.Window.New() ``` ### Does Wails support system tray? @@ -132,7 +132,7 @@ window2 := app.NewWebviewWindow() Yes! Create system tray applications: ```go -tray := app.NewSystemTray() +tray := app.SystemTray.New() tray.SetIcon(iconBytes) tray.SetMenu(menu) ``` @@ -142,7 +142,7 @@ tray.SetMenu(menu) Yes! Wails provides native dialogs: ```go -path, _ := app.OpenFileDialog(). +path, _ := app.Dialog.OpenFile(). SetTitle("Select File"). PromptForSingleSelection() ``` @@ -194,7 +194,7 @@ wails3 generate bindings Check if you called `Show()`: ```go -window := app.NewWebviewWindow() +window := app.Window.New() window.Show() // Don't forget this! ``` @@ -204,7 +204,7 @@ Ensure event names match exactly: ```go // Go -app.EmitEvent("my-event", data) +app.Event.Emit("my-event", data) // JavaScript OnEvent("my-event", handler) // Must match diff --git a/docs/src/content/docs/features/bindings/best-practices.mdx b/docs/src/content/docs/features/bindings/best-practices.mdx index bfaa77f7edd..5b2d71d8d73 100644 --- a/docs/src/content/docs/features/bindings/best-practices.mdx +++ b/docs/src/content/docs/features/bindings/best-practices.mdx @@ -274,7 +274,7 @@ func (s *Service) ProcessLargeFile(path string) error { processed++ // Emit progress - s.app.EmitEvent("progress", map[string]interface{}{ + s.app.Event.Emit("progress", map[string]interface{}{ "processed": processed, "total": total, "percent": int(float64(processed) / float64(total) * 100), diff --git a/docs/src/content/docs/features/bindings/methods.mdx b/docs/src/content/docs/features/bindings/methods.mdx index b67f0017c9e..f8348269d0a 100644 --- a/docs/src/content/docs/features/bindings/methods.mdx +++ b/docs/src/content/docs/features/bindings/methods.mdx @@ -461,7 +461,7 @@ const config = await GetConfig() func ProcessLargeFile(path string) error { // Emit progress events for line := range lines { - app.EmitEvent("progress", line) + app.Event.Emit("progress", line) } return nil } @@ -530,7 +530,7 @@ func main() { }, }) - app.NewWebviewWindow() + app.Window.New() app.Run() } ``` diff --git a/docs/src/content/docs/features/bindings/models.mdx b/docs/src/content/docs/features/bindings/models.mdx index f177545aecd..f393eb694a5 100644 --- a/docs/src/content/docs/features/bindings/models.mdx +++ b/docs/src/content/docs/features/bindings/models.mdx @@ -628,7 +628,7 @@ func main() { }, }) - app.NewWebviewWindow() + app.Window.New() app.Run() } ``` diff --git a/docs/src/content/docs/features/bindings/services.mdx b/docs/src/content/docs/features/bindings/services.mdx index ace565d66b2..3d95606c3af 100644 --- a/docs/src/content/docs/features/bindings/services.mdx +++ b/docs/src/content/docs/features/bindings/services.mdx @@ -438,7 +438,7 @@ func (o *OrderService) CreateOrder(items []Item) (*Order, error) { } // Emit event - o.app.EmitEvent("order-created", order) + o.app.Event.Emit("order-created", order) return order, nil } @@ -485,7 +485,7 @@ func NewNotificationService(app *application.Application) *NotificationService { func (n *NotificationService) Notify(message string) { // Use application to emit events - n.app.EmitEvent("notification", message) + n.app.Event.Emit("notification", message) // Or show system notification n.app.ShowNotification(message) @@ -780,7 +780,7 @@ func main() { }, }) - app.NewWebviewWindow() + app.Window.New() app.Run() } ``` diff --git a/docs/src/content/docs/features/clipboard/basics.mdx b/docs/src/content/docs/features/clipboard/basics.mdx index 3ecba9c0a69..b75570acaeb 100644 --- a/docs/src/content/docs/features/clipboard/basics.mdx +++ b/docs/src/content/docs/features/clipboard/basics.mdx @@ -64,12 +64,12 @@ await CopyToClipboard("Text to copy") ```go func copyWithFeedback(text string) { if app.Clipboard.SetText(text) { - app.InfoDialog(). + app.Dialog.Info(). SetTitle("Copied"). SetMessage("Text copied to clipboard!"). Show() } else { - app.ErrorDialog(). + app.Dialog.Error(). SetTitle("Copy Failed"). SetMessage("Failed to copy to clipboard."). Show() @@ -296,7 +296,7 @@ func (cm *ClipboardMonitor) checkClipboard() { if text != cm.lastText { cm.lastText = text - cm.app.EmitEvent("clipboard-changed", text) + cm.app.Event.Emit("clipboard-changed", text) } } ``` diff --git a/docs/src/content/docs/features/dialogs/custom.mdx b/docs/src/content/docs/features/dialogs/custom.mdx index 8cb35477294..591d68db2a3 100644 --- a/docs/src/content/docs/features/dialogs/custom.mdx +++ b/docs/src/content/docs/features/dialogs/custom.mdx @@ -14,7 +14,7 @@ Create **custom dialog windows** using regular Wails windows with dialog-like be ```go // Create custom dialog window -dialog := app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ +dialog := app.Window.NewWithOptions(application.WebviewWindowOptions{ Title: "Custom dialog", Width: 400, Height: 300, @@ -48,7 +48,7 @@ func NewCustomdialog(app *application.Application) *Customdialog { result: make(chan string, 1), } - dialog.window = app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ + dialog.window = app.Window.NewWithOptions(application.WebviewWindowOptions{ Title: "Custom dialog", Width: 400, Height: 300, @@ -79,7 +79,7 @@ func (d *Customdialog) Close(result string) { ```go func ShowModaldialog(parent *application.WebviewWindow, title string) string { // Create dialog - dialog := app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ + dialog := app.Window.NewWithOptions(application.WebviewWindowOptions{ Title: title, Width: 400, Height: 200, @@ -119,7 +119,7 @@ func NewFormdialog(app *application.Application) *Formdialog { done: make(chan bool, 1), } - fd.window = app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ + fd.window = app.Window.NewWithOptions(application.WebviewWindowOptions{ Title: "Enter Information", Width: 500, Height: 400, @@ -156,7 +156,7 @@ func (fd *Formdialog) Cancel() { ```go func ShowConfirmdialog(message string) bool { - dialog := app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ + dialog := app.Window.NewWithOptions(application.WebviewWindowOptions{ Title: "Confirm", Width: 400, Height: 150, @@ -172,12 +172,12 @@ func ShowConfirmdialog(message string) bool { result := make(chan bool, 1) // Handle responses - app.OnEvent("confirm-yes", func(e *application.CustomEvent) { + app.Event.On("confirm-yes", func(e *application.CustomEvent) { result <- true dialog.Close() }) - app.OnEvent("confirm-no", func(e *application.CustomEvent) { + app.Event.On("confirm-no", func(e *application.CustomEvent) { result <- false dialog.Close() }) @@ -215,7 +215,7 @@ function confirm(result) { ```go func ShowInputdialog(prompt string, defaultValue string) (string, bool) { - dialog := app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ + dialog := app.Window.NewWithOptions(application.WebviewWindowOptions{ Title: "Input", Width: 400, Height: 150, @@ -234,7 +234,7 @@ func ShowInputdialog(prompt string, defaultValue string) (string, bool) { }) }) - app.OnEvent("input-submit", func(e *application.CustomEvent) { + app.Event.On("input-submit", func(e *application.CustomEvent) { result <- struct { value string ok bool @@ -242,7 +242,7 @@ func ShowInputdialog(prompt string, defaultValue string) (string, bool) { dialog.Close() }) - app.OnEvent("input-cancel", func(e *application.CustomEvent) { + app.Event.On("input-cancel", func(e *application.CustomEvent) { result <- struct { value string ok bool @@ -266,7 +266,7 @@ type Progressdialog struct { func NewProgressdialog(title string) *Progressdialog { pd := &Progressdialog{} - pd.window = app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ + pd.window = app.Window.NewWithOptions(application.WebviewWindowOptions{ Title: title, Width: 400, Height: 150, @@ -336,7 +336,7 @@ func NewLogindialog(app *application.Application) *Logindialog { }, 1), } - ld.window = app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ + ld.window = app.Window.NewWithOptions(application.WebviewWindowOptions{ Title: "Login", Width: 400, Height: 250, @@ -421,7 +421,7 @@ func NewSettingsdialog(app *application.Application, current map[string]interfac done: make(chan bool, 1), } - sd.window = app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ + sd.window = app.Window.NewWithOptions(application.WebviewWindowOptions{ Title: "Settings", Width: 600, Height: 500, @@ -470,7 +470,7 @@ func NewWizarddialog(app *application.Application) *Wizarddialog { done: make(chan bool, 1), } - wd.window = app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ + wd.window = app.Window.NewWithOptions(application.WebviewWindowOptions{ Title: "Setup Wizard", Width: 600, Height: 400, diff --git a/docs/src/content/docs/features/drag-and-drop/files.mdx b/docs/src/content/docs/features/drag-and-drop/files.mdx index 6d53d7934a8..ffc75093ac1 100644 --- a/docs/src/content/docs/features/drag-and-drop/files.mdx +++ b/docs/src/content/docs/features/drag-and-drop/files.mdx @@ -115,7 +115,7 @@ window.OnWindowEvent(events.Common.WindowFilesDropped, func(event *application.W details := event.Context().DropTargetDetails() // Send to frontend - app.EmitEvent("files-dropped", map[string]any{ + app.Event.Emit("files-dropped", map[string]any{ "files": files, "target": details.ElementID, }) diff --git a/docs/src/content/docs/features/events/system.mdx b/docs/src/content/docs/features/events/system.mdx index f55ffca036d..259add09c41 100644 --- a/docs/src/content/docs/features/events/system.mdx +++ b/docs/src/content/docs/features/events/system.mdx @@ -16,7 +16,7 @@ Wails provides a **unified event system** for pub/sub communication. Emit events **Go (emit):** ```go -app.EmitEvent("user-logged-in", map[string]interface{}{ +app.Event.Emit("user-logged-in", map[string]interface{}{ "userId": 123, "name": "Alice", }) @@ -42,9 +42,9 @@ Your application-specific events: ```go // Emit from Go -app.EmitEvent("order-created", order) -app.EmitEvent("payment-processed", payment) -app.EmitEvent("notification", message) +app.Event.Emit("order-created", order) +app.Event.Emit("payment-processed", payment) +app.Event.Emit("notification", message) ``` ```javascript @@ -62,14 +62,14 @@ Built-in OS and application events: import "github.com/wailsapp/wails/v3/pkg/events" // Theme changes -app.OnApplicationEvent(events.Common.ThemeChanged, func(e *application.ApplicationEvent) { +app.Event.OnApplicationEvent(events.Common.ThemeChanged, func(e *application.ApplicationEvent) { if e.Context().IsDarkMode() { app.Logger.Info("Dark mode enabled") } }) // Application lifecycle -app.OnApplicationEvent(events.Common.ApplicationStarted, func(e *application.ApplicationEvent) { +app.Event.OnApplicationEvent(events.Common.ApplicationStarted, func(e *application.ApplicationEvent) { app.Logger.Info("Application started") }) ``` @@ -95,29 +95,29 @@ window.OnWindowEvent(events.Common.WindowClosing, func(e *application.WindowEven **Basic emit:** ```go -app.EmitEvent("event-name", data) +app.Event.Emit("event-name", data) ``` **With different data types:** ```go // String -app.EmitEvent("message", "Hello") +app.Event.Emit("message", "Hello") // Number -app.EmitEvent("count", 42) +app.Event.Emit("count", 42) // Struct -app.EmitEvent("user", User{ID: 1, Name: "Alice"}) +app.Event.Emit("user", User{ID: 1, Name: "Alice"}) // Map -app.EmitEvent("config", map[string]interface{}{ +app.Event.Emit("config", map[string]interface{}{ "theme": "dark", "fontSize": 14, }) // Array -app.EmitEvent("items", []string{"a", "b", "c"}) +app.Event.Emit("items", []string{"a", "b", "c"}) ``` **To specific window:** @@ -145,7 +145,7 @@ Emit("broadcast-message", "Hello everyone") **Application events:** ```go -app.OnEvent("custom-event", func(e *application.CustomEvent) { +app.Event.On("custom-event", func(e *application.CustomEvent) { data := e.Data // Handle event }) @@ -154,7 +154,7 @@ app.OnEvent("custom-event", func(e *application.CustomEvent) { **With type assertion:** ```go -app.OnEvent("user-updated", func(e *application.CustomEvent) { +app.Event.On("user-updated", func(e *application.CustomEvent) { user := e.Data.(User) app.Logger.Info("User updated", "name", user.Name) }) @@ -164,9 +164,9 @@ app.OnEvent("user-updated", func(e *application.CustomEvent) { ```go // All handlers will be called -app.OnEvent("order-created", logOrder) -app.OnEvent("order-created", sendEmail) -app.OnEvent("order-created", updateInventory) +app.Event.On("order-created", logOrder) +app.Event.On("order-created", sendEmail) +app.Event.On("order-created", updateInventory) ``` ### In JavaScript @@ -208,18 +208,18 @@ OnEvent("data-updated", logChange) import "github.com/wailsapp/wails/v3/pkg/events" // Application started -app.OnApplicationEvent(events.Common.ApplicationStarted, func(e *application.ApplicationEvent) { +app.Event.OnApplicationEvent(events.Common.ApplicationStarted, func(e *application.ApplicationEvent) { app.Logger.Info("App started") }) // Theme changed -app.OnApplicationEvent(events.Common.ThemeChanged, func(e *application.ApplicationEvent) { +app.Event.OnApplicationEvent(events.Common.ThemeChanged, func(e *application.ApplicationEvent) { isDark := e.Context().IsDarkMode() - app.EmitEvent("theme-changed", isDark) + app.Event.Emit("theme-changed", isDark) }) // File opened -app.OnApplicationEvent(events.Common.ApplicationOpenedWithFile, func(e *application.ApplicationEvent) { +app.Event.OnApplicationEvent(events.Common.ApplicationOpenedWithFile, func(e *application.ApplicationEvent) { filePath := e.Context().OpenedFile() openFile(filePath) }) @@ -231,12 +231,12 @@ app.OnApplicationEvent(events.Common.ApplicationOpenedWithFile, func(e *applicat ```go // Application became active - app.OnApplicationEvent(events.Mac.ApplicationDidBecomeActive, func(e *application.ApplicationEvent) { + app.Event.OnApplicationEvent(events.Mac.ApplicationDidBecomeActive, func(e *application.ApplicationEvent) { app.Logger.Info("App became active") }) // Application will terminate - app.OnApplicationEvent(events.Mac.ApplicationWillTerminate, func(e *application.ApplicationEvent) { + app.Event.OnApplicationEvent(events.Mac.ApplicationWillTerminate, func(e *application.ApplicationEvent) { cleanup() }) ``` @@ -245,12 +245,12 @@ app.OnApplicationEvent(events.Common.ApplicationOpenedWithFile, func(e *applicat ```go // Power status changed - app.OnApplicationEvent(events.Windows.APMPowerStatusChange, func(e *application.ApplicationEvent) { + app.Event.OnApplicationEvent(events.Windows.APMPowerStatusChange, func(e *application.ApplicationEvent) { app.Logger.Info("Power status changed") }) // System suspending - app.OnApplicationEvent(events.Windows.APMSuspend, func(e *application.ApplicationEvent) { + app.Event.OnApplicationEvent(events.Windows.APMSuspend, func(e *application.ApplicationEvent) { saveState() }) ``` @@ -259,12 +259,12 @@ app.OnApplicationEvent(events.Common.ApplicationOpenedWithFile, func(e *applicat ```go // Application startup - app.OnApplicationEvent(events.Linux.ApplicationStartup, func(e *application.ApplicationEvent) { + app.Event.OnApplicationEvent(events.Linux.ApplicationStartup, func(e *application.ApplicationEvent) { app.Logger.Info("App starting") }) // Theme changed - app.OnApplicationEvent(events.Linux.SystemThemeChanged, func(e *application.ApplicationEvent) { + app.Event.OnApplicationEvent(events.Linux.SystemThemeChanged, func(e *application.ApplicationEvent) { updateTheme() }) ``` @@ -347,23 +347,23 @@ func (o *OrderService) CreateOrder(items []Item) (*Order, error) { } // Publish event - o.app.EmitEvent("order-created", order) + o.app.Event.Emit("order-created", order) return order, nil } // Subscribers -app.OnEvent("order-created", func(e *application.CustomEvent) { +app.Event.On("order-created", func(e *application.CustomEvent) { order := e.Data.(*Order) sendConfirmationEmail(order) }) -app.OnEvent("order-created", func(e *application.CustomEvent) { +app.Event.On("order-created", func(e *application.CustomEvent) { order := e.Data.(*Order) updateInventory(order) }) -app.OnEvent("order-created", func(e *application.CustomEvent) { +app.Event.On("order-created", func(e *application.CustomEvent) { order := e.Data.(*Order) logOrder(order) }) @@ -376,14 +376,14 @@ app.OnEvent("order-created", func(e *application.CustomEvent) { Emit("get-user-data", { userId: 123 }) // Backend responds -app.OnEvent("get-user-data", func(e *application.CustomEvent) { +app.Event.On("get-user-data", func(e *application.CustomEvent) { data := e.Data.(map[string]interface{}) userId := int(data["userId"].(float64)) user := getUserFromDB(userId) // Send response - app.EmitEvent("user-data-response", user) + app.Event.Emit("user-data-response", user) }) // Frontend receives response @@ -398,7 +398,7 @@ OnEvent("user-data-response", (user) => { ```go // Broadcast to all windows -app.EmitEvent("global-notification", "System update available") +app.Event.Emit("global-notification", "System update available") // Each window handles it OnEvent("global-notification", (message) => { @@ -422,7 +422,7 @@ func (ea *EventAggregator) Add(event Event) { // Emit batch every 100 events if len(ea.events) >= 100 { - app.EmitEvent("event-batch", ea.events) + app.Event.Emit("event-batch", ea.events) ea.events = nil } } @@ -446,7 +446,7 @@ type NotificationService struct { func (n *NotificationService) Notify(message string) { // Emit to all windows - n.app.EmitEvent("notification", map[string]interface{}{ + n.app.Event.Emit("notification", map[string]interface{}{ "message": message, "timestamp": time.Now(), }) @@ -460,13 +460,13 @@ func main() { notifService := &NotificationService{app: app} // System events - app.OnApplicationEvent(events.Common.ThemeChanged, func(e *application.ApplicationEvent) { + app.Event.OnApplicationEvent(events.Common.ThemeChanged, func(e *application.ApplicationEvent) { isDark := e.Context().IsDarkMode() - app.EmitEvent("theme-changed", isDark) + app.Event.Emit("theme-changed", isDark) }) // Custom events from frontend - app.OnEvent("user-action", func(e *application.CustomEvent) { + app.Event.On("user-action", func(e *application.CustomEvent) { data := e.Data.(map[string]interface{}) action := data["action"].(string) @@ -477,15 +477,15 @@ func main() { }) // Window events - window := app.NewWebviewWindow() + window := app.Window.New() window.OnWindowEvent(events.Common.WindowFocus, func(e *application.WindowEvent) { - app.EmitEvent("window-focused", window.Name()) + app.Event.Emit("window-focused", window.Name()) }) window.RegisterHook(events.Common.WindowClosing, func(e *application.WindowEvent) { // Confirm before close - app.EmitEvent("confirm-close", nil) + app.Event.Emit("confirm-close", nil) e.Cancel() // Wait for confirmation }) diff --git a/docs/src/content/docs/features/menus/application.mdx b/docs/src/content/docs/features/menus/application.mdx index 92d9ff74adc..9e39e5cafc5 100644 --- a/docs/src/content/docs/features/menus/application.mdx +++ b/docs/src/content/docs/features/menus/application.mdx @@ -60,7 +60,7 @@ func main() { app.SetMenu(menu) // Create window and run - app.NewWebviewWindow() + app.Window.New() app.Run() } ``` @@ -487,7 +487,7 @@ func main() { createMenu(app) // Create main window - app.NewWebviewWindow() + app.Window.New() app.Run() } diff --git a/docs/src/content/docs/features/menus/context.mdx b/docs/src/content/docs/features/menus/context.mdx index 3321cc85d47..ab7eb630a2c 100644 --- a/docs/src/content/docs/features/menus/context.mdx +++ b/docs/src/content/docs/features/menus/context.mdx @@ -482,7 +482,7 @@ func main() { textMenu := createTextMenu(app) app.RegisterContextMenu("text-menu", textMenu) - app.NewWebviewWindow() + app.Window.New() app.Run() } diff --git a/docs/src/content/docs/features/menus/systray.mdx b/docs/src/content/docs/features/menus/systray.mdx index beb81393d93..a0c8a722b46 100644 --- a/docs/src/content/docs/features/menus/systray.mdx +++ b/docs/src/content/docs/features/menus/systray.mdx @@ -38,7 +38,7 @@ func main() { }) // Create system tray - systray := app.NewSystemTray() + systray := app.SystemTray.New() systray.SetIcon(icon) systray.SetLabel("My App") @@ -53,7 +53,7 @@ func main() { systray.SetMenu(menu) // Create hidden window - window := app.NewWebviewWindow() + window := app.Window.New() window.Hide() app.Run() @@ -68,7 +68,7 @@ func main() { ```go // Create system tray -systray := app.NewSystemTray() +systray := app.SystemTray.New() // Set icon systray.SetIcon(iconBytes) @@ -95,7 +95,7 @@ func main() { Name: "My App", }) - systray := app.NewSystemTray() + systray := app.SystemTray.New() systray.SetIcon(icon) systray.SetDarkModeIcon(iconDark) // macOS dark mode @@ -162,7 +162,7 @@ Attach a window to the tray icon for automatic show/hide: ```go // Create window -window := app.NewWebviewWindow() +window := app.Window.New() // Attach to tray systray.AttachWindow(window) @@ -181,7 +181,7 @@ systray.SetWindowDebounce(200 * time.Millisecond) // Click debounce **Example: Popup window** ```go -window := app.NewWebviewWindow(application.WebviewWindowOptions{ +window := app.Window.NewWithOptions(application.WebviewWindowOptions{ Title: "Quick Access", Width: 300, Height: 400, @@ -198,7 +198,7 @@ systray.SetWindowOffset(5) Handle tray icon clicks: ```go -systray := app.NewSystemTray() +systray := app.SystemTray.New() // Left click systray.OnClick(func() { @@ -445,7 +445,7 @@ func main() { func (t *TrayApp) setup() { // Create system tray - t.systray = t.app.NewSystemTray() + t.systray = t.app.SystemTray.New() t.systray.SetIcon(icon) t.systray.SetLabel("Inactive") @@ -453,7 +453,7 @@ func (t *TrayApp) setup() { t.createMenu() // Create window (hidden by default) - t.window = t.app.NewWebviewWindow(application.WebviewWindowOptions{ + t.window = t.app.Window.NewWithOptions(application.WebviewWindowOptions{ Title: "Tray Application", Width: 400, Height: 600, diff --git a/docs/src/content/docs/features/screens/info.mdx b/docs/src/content/docs/features/screens/info.mdx index 98c744f886e..a1ade0a2748 100644 --- a/docs/src/content/docs/features/screens/info.mdx +++ b/docs/src/content/docs/features/screens/info.mdx @@ -266,7 +266,7 @@ func (m *MultiMonitorManager) CreateWindowOnScreen(screenIndex int) error { screen := screens[screenIndex] // Create window - window := m.app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ + window := m.app.Window.NewWithOptions(application.WebviewWindowOptions{ Title: fmt.Sprintf("Window on %s", screen.Name), Width: 800, Height: 600, @@ -346,7 +346,7 @@ func createDPIAwareWindow(screen *Screen) *application.WebviewWindow { width := int(float32(baseWidth) * screen.ScaleFactor) height := int(float32(baseHeight) * screen.ScaleFactor) - window := app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ + window := app.Window.NewWithOptions(application.WebviewWindowOptions{ Title: "DPI-Aware Window", Width: width, Height: height, diff --git a/docs/src/content/docs/features/windows/basics.mdx b/docs/src/content/docs/features/windows/basics.mdx index 3137111ac64..54bbb04fab9 100644 --- a/docs/src/content/docs/features/windows/basics.mdx +++ b/docs/src/content/docs/features/windows/basics.mdx @@ -24,7 +24,7 @@ func main() { }) // Create a window - window := app.NewWebviewWindow() + window := app.Window.New() // Configure it window.SetTitle("Hello Wails") @@ -47,7 +47,7 @@ func main() { The simplest way to create a window: ```go -window := app.NewWebviewWindow() +window := app.Window.New() ``` **What you get:** @@ -61,7 +61,7 @@ window := app.NewWebviewWindow() Create a window with custom configuration: ```go -window := app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ +window := app.Window.NewWithOptions(application.WebviewWindowOptions{ Title: "My Application", Width: 1200, Height: 800, @@ -101,7 +101,7 @@ window := app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ Give windows names for easy retrieval: ```go -window := app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ +window := app.Window.NewWithOptions(application.WebviewWindowOptions{ Name: "main-window", Title: "Main Application", }) @@ -259,7 +259,7 @@ foundWindow := app.GetWindowByID(id) Get the currently focused window: ```go -current := app.CurrentWindow() +current := app.Window.Current() if current != nil { current.SetTitle("Active Window") } @@ -270,7 +270,7 @@ if current != nil { Get all windows: ```go -windows := app.GetAllWindows() +windows := app.Window.GetAll() fmt.Printf("Total windows: %d\n", len(windows)) for _, w := range windows { @@ -323,7 +323,7 @@ window.OnDestroy(func() { ```go // Main window -mainWindow := app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ +mainWindow := app.Window.NewWithOptions(application.WebviewWindowOptions{ Name: "main", Title: "Main Application", Width: 1200, @@ -331,7 +331,7 @@ mainWindow := app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ }) // Settings window -settingsWindow := app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ +settingsWindow := app.Window.NewWithOptions(application.WebviewWindowOptions{ Name: "settings", Title: "Settings", Width: 600, @@ -349,12 +349,12 @@ Windows can communicate via events: ```go // In main window -app.EmitEvent("data-updated", map[string]interface{}{ +app.Event.Emit("data-updated", map[string]interface{}{ "value": 42, }) // In settings window -app.OnEvent("data-updated", func(event *application.WailsEvent) { +app.Event.On("data-updated", func(event *application.WailsEvent) { data := event.Data.(map[string]interface{}) value := data["value"].(int) fmt.Printf("Received: %d\n", value) @@ -367,7 +367,7 @@ app.OnEvent("data-updated", func(event *application.WailsEvent) { ```go // Create child window -childWindow := app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ +childWindow := app.Window.NewWithOptions(application.WebviewWindowOptions{ Title: "Child Window", Parent: mainWindow, // Set parent }) @@ -413,7 +413,7 @@ childWindow := app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ ```go // Transparent title bar - window := app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ + window := app.Window.NewWithOptions(application.WebviewWindowOptions{ Mac: application.MacWindow{ TitleBar: application.MacTitleBar{ AppearsTransparent: true, @@ -442,7 +442,7 @@ childWindow := app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ ```go // Set window icon - window := app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ + window := app.Window.NewWithOptions(application.WebviewWindowOptions{ Linux: application.LinuxOptions{ Icon: iconBytes, }, @@ -467,7 +467,7 @@ childWindow := app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ ```go // Create splash screen -splash := app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ +splash := app.Window.NewWithOptions(application.WebviewWindowOptions{ Title: "Loading...", Width: 400, Height: 300, @@ -493,7 +493,7 @@ var settingsWindow *application.WebviewWindow func showSettings() { if settingsWindow == nil { - settingsWindow = app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ + settingsWindow = app.Window.NewWithOptions(application.WebviewWindowOptions{ Name: "settings", Title: "Settings", Width: 600, diff --git a/docs/src/content/docs/features/windows/events.mdx b/docs/src/content/docs/features/windows/events.mdx index 8d3ba317d71..b45c6596ca7 100644 --- a/docs/src/content/docs/features/windows/events.mdx +++ b/docs/src/content/docs/features/windows/events.mdx @@ -74,7 +74,7 @@ window.OnClose(func() bool { } // Show confirmation dialog - dialog := app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ + dialog := app.Window.NewWithOptions(application.WebviewWindowOptions{ Title: "Confirm Close", Width: 400, Height: 150, @@ -164,7 +164,7 @@ window.OnFocus(func() { refreshContent() // Notify other windows - app.EmitEvent("window-focused", window.ID()) + app.Event.Emit("window-focused", window.ID()) }) ``` @@ -437,7 +437,7 @@ func main() { } func (mw *ManagedWindow) CreateWindow() { - mw.window = mw.app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ + mw.window = mw.app.Window.NewWithOptions(application.WebviewWindowOptions{ Name: "main", Title: "Event Demo", Width: 800, @@ -566,11 +566,11 @@ Coordinate between multiple windows: // In main window mainWindow.OnFocus(func() { // Notify all windows - app.EmitEvent("main-window-focused", nil) + app.Event.Emit("main-window-focused", nil) }) // In other windows -app.OnEvent("main-window-focused", func(event *application.WailsEvent) { +app.Event.On("main-window-focused", func(event *application.WailsEvent) { // Update UI updateRelativeToMain() }) @@ -589,7 +589,7 @@ window.OnMaximise(func() { window.EmitEvent("layout-changed", "maximised") // Notify other windows - app.EmitEvent("window-maximised", window.ID()) + app.Event.Emit("window-maximised", window.ID()) }) ``` @@ -656,7 +656,7 @@ window.Destroy() ```go // Register handlers immediately after creation -window := app.NewWebviewWindow() +window := app.Window.New() window.OnClose(func() bool { return true }) ``` diff --git a/docs/src/content/docs/features/windows/frameless.mdx b/docs/src/content/docs/features/windows/frameless.mdx index 4c6b266f899..c13cb9d4da9 100644 --- a/docs/src/content/docs/features/windows/frameless.mdx +++ b/docs/src/content/docs/features/windows/frameless.mdx @@ -14,7 +14,7 @@ Wails provides **frameless window support** with CSS-based drag regions and plat ## Quick Start ```go -window := app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ +window := app.Window.NewWithOptions(application.WebviewWindowOptions{ Title: "Frameless App", Width: 800, Height: 600, @@ -52,7 +52,7 @@ window := app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ ### Basic Frameless Window ```go -window := app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ +window := app.Window.NewWithOptions(application.WebviewWindowOptions{ Frameless: true, Width: 800, Height: 600, @@ -73,7 +73,7 @@ window := app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ ### With Transparent Background ```go -window := app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ +window := app.Window.NewWithOptions(application.WebviewWindowOptions{ Frameless: true, BackgroundType: application.BackgroundTypeTransparent, }) @@ -336,7 +336,7 @@ body { **Windows frameless windows:** ```go - window := app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ + window := app.Window.NewWithOptions(application.WebviewWindowOptions{ Frameless: true, Windows: application.WindowsOptions{ DisableFramelessWindowDecorations: false, @@ -371,7 +371,7 @@ body { **macOS frameless windows:** ```go - window := app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ + window := app.Window.NewWithOptions(application.WebviewWindowOptions{ Frameless: true, Mac: application.MacOptions{ TitleBarAppearsTransparent: true, @@ -406,7 +406,7 @@ body { **Linux frameless windows:** ```go - window := app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ + window := app.Window.NewWithOptions(application.WebviewWindowOptions{ Frameless: true, }) ``` @@ -500,7 +500,7 @@ body { ### Pattern 2: Splash Screen ```go -splash := app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ +splash := app.Window.NewWithOptions(application.WebviewWindowOptions{ Title: "Loading...", Width: 400, Height: 300, @@ -530,7 +530,7 @@ body { ### Pattern 3: Rounded Window ```go -window := app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ +window := app.Window.NewWithOptions(application.WebviewWindowOptions{ Frameless: true, BackgroundType: application.BackgroundTypeTransparent, }) @@ -560,7 +560,7 @@ body { ### Pattern 4: Overlay Window ```go -overlay := app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ +overlay := app.Window.NewWithOptions(application.WebviewWindowOptions{ Frameless: true, AlwaysOnTop: true, BackgroundType: application.BackgroundTypeTransparent, @@ -602,7 +602,7 @@ func main() { Name: "Frameless App", }) - window := app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ + window := app.Window.NewWithOptions(application.WebviewWindowOptions{ Title: "Frameless Application", Width: 1000, Height: 700, diff --git a/docs/src/content/docs/features/windows/multiple.mdx b/docs/src/content/docs/features/windows/multiple.mdx index 3fa42abb795..41d5a18fe7f 100644 --- a/docs/src/content/docs/features/windows/multiple.mdx +++ b/docs/src/content/docs/features/windows/multiple.mdx @@ -32,7 +32,7 @@ func main() { }) // Create main window - app.mainWindow = app.app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ + app.mainWindow = app.app.Window.NewWithOptions(application.WebviewWindowOptions{ Name: "main", Title: "Main Application", Width: 1200, @@ -40,7 +40,7 @@ func main() { }) // Create settings window (hidden initially) - app.settingsWindow = app.app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ + app.settingsWindow = app.app.Window.NewWithOptions(application.WebviewWindowOptions{ Name: "settings", Title: "Settings", Width: 600, @@ -71,7 +71,7 @@ func (a *App) ShowSettings() { ### Get All Windows ```go -windows := app.GetAllWindows() +windows := app.Window.GetAll() fmt.Printf("Total windows: %d\n", len(windows)) for _, window := range windows { @@ -92,7 +92,7 @@ if settings != nil { window := app.GetWindowByID(123) // Current (focused) window -current := app.CurrentWindow() +current := app.Window.Current() ``` ### Window Registry Pattern @@ -132,13 +132,13 @@ Windows communicate via the event system: ```go // In main window - emit event -app.EmitEvent("settings-changed", map[string]interface{}{ +app.Event.Emit("settings-changed", map[string]interface{}{ "theme": "dark", "fontSize": 14, }) // In settings window - listen for event -app.OnEvent("settings-changed", func(event *application.WailsEvent) { +app.Event.On("settings-changed", func(event *application.WailsEvent) { data := event.Data.(map[string]interface{}) theme := data["theme"].(string) fontSize := data["fontSize"].(int) @@ -170,7 +170,7 @@ func (s *AppState) SetTheme(theme string) { s.mu.Unlock() // Notify all windows - app.EmitEvent("theme-changed", theme) + app.Event.Emit("theme-changed", theme) } func (s *AppState) GetTheme() string { @@ -204,7 +204,7 @@ var settingsWindow *application.WebviewWindow func ShowSettings(app *application.Application) { // Create if doesn't exist if settingsWindow == nil { - settingsWindow = app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ + settingsWindow = app.Window.NewWithOptions(application.WebviewWindowOptions{ Name: "settings", Title: "Settings", Width: 600, @@ -245,7 +245,7 @@ func OpenDocument(app *application.Application, filePath string) { } // Create new document window - window := app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ + window := app.Window.NewWithOptions(application.WebviewWindowOptions{ Title: filepath.Base(filePath), Width: 800, Height: 600, @@ -275,7 +275,7 @@ Floating windows that stay on top: ```go func CreateToolPalette(app *application.Application) *application.WebviewWindow { - palette := app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ + palette := app.Window.NewWithOptions(application.WebviewWindowOptions{ Name: "tools", Title: "Tools", Width: 200, @@ -294,7 +294,7 @@ Child windows that block parent: ```go func ShowModaldialog(parent *application.WebviewWindow, title string) { - dialog := app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ + dialog := app.Window.NewWithOptions(application.WebviewWindowOptions{ Title: title, Width: 400, Height: 200, @@ -332,7 +332,7 @@ func (e *EditorApp) UpdatePreview(content string) { func (e *EditorApp) TogglePreview() { if e.preview == nil { - e.preview = app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ + e.preview = app.Window.NewWithOptions(application.WebviewWindowOptions{ Name: "preview", Title: "Preview", Width: 600, @@ -357,7 +357,7 @@ func (e *EditorApp) TogglePreview() { ### Creating Child Windows ```go -childWindow := app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ +childWindow := app.Window.NewWithOptions(application.WebviewWindowOptions{ Title: "Child Window", Parent: parentWindow, }) @@ -382,7 +382,7 @@ Create modal-like behaviour: ```go func ShowModal(parent *application.WebviewWindow) { - modal := app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ + modal := app.Window.NewWithOptions(application.WebviewWindowOptions{ Title: "Modal dialog", Width: 400, Height: 200, @@ -463,7 +463,7 @@ Always clean up window references: var windows = make(map[string]*application.WebviewWindow) func CreateWindow(name string) { - window := app.NewWebviewWindow() + window := app.Window.New() windows[name] = window // IMPORTANT: Clean up on destroy @@ -530,7 +530,7 @@ func (wp *WindowPool) Acquire() *application.WebviewWindow { } // Create new window - window := app.NewWebviewWindow() + window := app.Window.New() wp.inUse[window.ID()] = window return window } @@ -598,7 +598,7 @@ type WindowState struct { func SaveLayout() *WindowLayout { layout := &WindowLayout{} - for _, window := range app.GetAllWindows() { + for _, window := range app.Window.GetAll() { x, y := window.Position() width, height := window.Size() @@ -667,7 +667,7 @@ func main() { } func (mwa *MultiWindowApp) CreateMainWindow() { - window := mwa.app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ + window := mwa.app.Window.NewWithOptions(application.WebviewWindowOptions{ Name: "main", Title: "Main Application", Width: 1200, @@ -684,7 +684,7 @@ func (mwa *MultiWindowApp) ShowSettings() { return } - window := mwa.app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ + window := mwa.app.Window.NewWithOptions(application.WebviewWindowOptions{ Name: "settings", Title: "Settings", Width: 600, @@ -703,7 +703,7 @@ func (mwa *MultiWindowApp) OpenDocument(path string) { return } - window := mwa.app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ + window := mwa.app.Window.NewWithOptions(application.WebviewWindowOptions{ Name: name, Title: path, Width: 800, diff --git a/docs/src/content/docs/features/windows/options.mdx b/docs/src/content/docs/features/windows/options.mdx index d2f338fc955..b7cea7f85d5 100644 --- a/docs/src/content/docs/features/windows/options.mdx +++ b/docs/src/content/docs/features/windows/options.mdx @@ -86,7 +86,7 @@ Name: "main-window" **Example:** ```go -window := app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ +window := app.Window.NewWithOptions(application.WebviewWindowOptions{ Name: "settings-window", }) @@ -161,7 +161,7 @@ Y: 100, // 100px from top edge **Example:** ```go -settings := app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ +settings := app.Window.NewWithOptions(application.WebviewWindowOptions{ Name: "coordinate-window", InitialPosition: application.WindowXY, // use coordinate system X: 100, @@ -171,7 +171,7 @@ settings := app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ **Best practice:** Use `Center()` to center the window: ```go -window := app.NewWebviewWindow() +window := app.Window.New() window.Center() ``` @@ -248,7 +248,7 @@ Hidden: true, ```go // Create hidden window -window := app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ +window := app.Window.NewWithOptions(application.WebviewWindowOptions{ Name: "main-window", Hidden: true, BackgroundColour: application.RGBA{R: 30, G: 30, B: 30, A: 255}, // Match your theme @@ -264,7 +264,7 @@ window.Show() **Example:** ```go -settings := app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ +settings := app.Window.NewWithOptions(application.WebviewWindowOptions{ Name: "settings", Hidden: true, }) @@ -574,7 +574,7 @@ When enabled: **Example:** ```go -window := app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ +window := app.Window.NewWithOptions(application.WebviewWindowOptions{ Title: "File Uploader", EnableFileDrop: true, }) @@ -635,7 +635,7 @@ ContentProtectionEnabled: true, **Example:** ```go -window := app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ +window := app.Window.NewWithOptions(application.WebviewWindowOptions{ Title: "Secure Window", ContentProtectionEnabled: true, }) @@ -892,7 +892,7 @@ func main() { Name: "My Application", }) - window := app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ + window := app.Window.NewWithOptions(application.WebviewWindowOptions{ // Identity Name: "main-window", Title: "My Application", diff --git a/docs/src/content/docs/guides/distribution/custom-protocols.mdx b/docs/src/content/docs/guides/distribution/custom-protocols.mdx index 760e8e2d87c..39a9b157c87 100644 --- a/docs/src/content/docs/guides/distribution/custom-protocols.mdx +++ b/docs/src/content/docs/guides/distribution/custom-protocols.mdx @@ -42,7 +42,7 @@ func main() { }) // Register handler for protocol events - app.OnEvent(application.Events.ApplicationOpenedWithURL, func(event *application.ApplicationEvent) { + app.Event.On(application.Events.ApplicationOpenedWithURL, func(event *application.ApplicationEvent) { url := event.Context().ClickedURL() handleCustomURL(url) }) @@ -62,7 +62,7 @@ func handleCustomURL(url string) { Listen for protocol events to handle incoming URLs: ```go -app.OnEvent(application.Events.ApplicationOpenedWithURL, func(event *application.ApplicationEvent) { +app.Event.On(application.Events.ApplicationOpenedWithURL, func(event *application.ApplicationEvent) { url := event.Context().ClickedURL() // Parse the URL @@ -362,7 +362,7 @@ func main() { func (a *App) setup() { // Create window - a.window = a.app.NewWebviewWindow(application.WebviewWindowOptions{ + a.window = a.app.Window.NewWithOptions(application.WebviewWindowOptions{ Title: "DeepLink Demo", Width: 800, Height: 600, @@ -370,7 +370,7 @@ func (a *App) setup() { }) // Handle custom protocol URLs - a.app.OnEvent(application.Events.ApplicationOpenedWithURL, func(event *application.ApplicationEvent) { + a.app.Event.On(application.Events.ApplicationOpenedWithURL, func(event *application.ApplicationEvent) { customURL := event.Context().ClickedURL() a.handleDeepLink(customURL) }) diff --git a/docs/src/content/docs/guides/performance.mdx b/docs/src/content/docs/guides/performance.mdx index 9b4f280644b..1d38a1ef46b 100644 --- a/docs/src/content/docs/guides/performance.mdx +++ b/docs/src/content/docs/guides/performance.mdx @@ -116,10 +116,10 @@ func (s *Service) ProcessLargeFile(path string) error { go func() { result, err := s.process(path) if err != nil { - s.app.EmitEvent("process-error", err.Error()) + s.app.Event.Emit("process-error", err.Error()) return } - s.app.EmitEvent("process-complete", result) + s.app.Event.Emit("process-complete", result) }() return nil diff --git a/docs/src/content/docs/guides/raw-messages.mdx b/docs/src/content/docs/guides/raw-messages.mdx index 72b067102e7..5f2a7a65324 100644 --- a/docs/src/content/docs/guides/raw-messages.mdx +++ b/docs/src/content/docs/guides/raw-messages.mdx @@ -47,7 +47,7 @@ func main() { }, }) - app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ + app.Window.NewWithOptions(application.WebviewWindowOptions{ Title: "My App", Name: "main", }) @@ -291,7 +291,7 @@ func main() { }, }) - app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ + app.Window.NewWithOptions(application.WebviewWindowOptions{ Title: "Raw Message Demo", Name: "main", Width: 400, @@ -382,7 +382,7 @@ RawMessageHandler: func(window application.Window, message string, originInfo *a window.EmitEvent("response", result) // Or broadcast to all windows - app.EmitEvent("broadcast", result) + app.Event.Emit("broadcast", result) } ``` diff --git a/docs/src/content/docs/migration/v2-to-v3.mdx b/docs/src/content/docs/migration/v2-to-v3.mdx index 6fea62912b1..5eb94ca6752 100644 --- a/docs/src/content/docs/migration/v2-to-v3.mdx +++ b/docs/src/content/docs/migration/v2-to-v3.mdx @@ -49,7 +49,7 @@ app := application.New(application.Options{ }, }) -window := app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ +window := app.Window.NewWithOptions(application.WebviewWindowOptions{ Title: "My App", Width: 1024, Height: 768, @@ -137,12 +137,12 @@ type MyService struct { } func (s *MyService) UpdateTitle() { - window := s.app.CurrentWindow() + window := s.app.Window.Current() window.SetTitle("New Title") } func (s *MyService) EmitEvent() { - s.app.EmitEvent("event-name", data) + s.app.Event.Emit("event-name", data) } ``` @@ -203,19 +203,19 @@ runtime.EventsEmit(ctx, "event-name", data) **v3:** ```go -app.OnEvent("event-name", func(e *application.CustomEvent) { +app.Event.On("event-name", func(e *application.CustomEvent) { data := e.Data // Handle event }) -app.EmitEvent("event-name", data) +app.Event.Emit("event-name", data) ``` **Why this is better:** - **Type safety**: Events use proper event objects instead of `...interface{}` - **Better debugging**: Event objects contain metadata like event name, making debugging easier -- **Clearer API**: `app.OnEvent()` and `app.EmitEvent()` are more intuitive than runtime functions +- **Clearer API**: `app.Event.On()` and `app.Event.Emit()` are more intuitive than runtime functions - **No context needed**: Events work directly on the app object without threading context - **Simpler handlers**: Event handlers have a clear signature instead of variadic parameters @@ -236,10 +236,10 @@ runtime.WindowSetSize(ctx, 800, 600) ```go // Multiple windows supported -window1 := app.NewWebviewWindow() +window1 := app.Window.New() window1.SetSize(800, 600) -window2 := app.NewWebviewWindow() +window2 := app.Window.New() window2.SetSize(1024, 768) ``` @@ -339,7 +339,7 @@ func main() { }, }) - app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ + app.Window.NewWithOptions(application.WebviewWindowOptions{ Title: "My App", Width: 1024, Height: 768, @@ -416,10 +416,10 @@ func (a *App) DoSomething() { ```go func (s *MyService) DoSomething() { - window := s.app.CurrentWindow() + window := s.app.Window.Current() window.SetTitle("New Title") - s.app.EmitEvent("update", data) + s.app.Event.Emit("update", data) s.app.Logger.Info("Message") } @@ -510,7 +510,7 @@ selection, err := runtime.OpenFileDialog(ctx, runtime.OpenDialogOptions{ **v3:** ```go -selection, err := app.OpenFileDialog(application.OpenFileDialogOptions{ +selection, err := app.Dialog.OpenFile(application.OpenFileDialogOptions{ Title: "Select File", }) ``` @@ -549,7 +549,7 @@ fileMenu.Add("Quit").OnClick(func(ctx *application.Context) { **v3:** ```go -systray := app.NewSystemTray() +systray := app.SystemTray.New() systray.SetIcon(iconBytes) systray.SetLabel("My App") @@ -602,7 +602,7 @@ func NewMyService(app *application.Application) *MyService { Use window methods directly: ```go -window := s.app.CurrentWindow() +window := s.app.Window.Current() window.SetTitle("New Title") ``` @@ -616,7 +616,7 @@ Check event names match exactly: ```go // Go -app.EmitEvent("my-event", data) +app.Event.Emit("my-event", data) // JavaScript OnEvent("my-event", handler) // Must match exactly diff --git a/docs/src/content/docs/reference/application.mdx b/docs/src/content/docs/reference/application.mdx index 050578a622e..0fbc63b02ff 100644 --- a/docs/src/content/docs/reference/application.mdx +++ b/docs/src/content/docs/reference/application.mdx @@ -80,33 +80,33 @@ fmt.Println("App name:", config.Name) ## Window Management -### NewWebviewWindow() +### app.Window.New() Creates a new webview window with default options. ```go -func (a *App) NewWebviewWindow() *WebviewWindow +func (wm *WindowManager) New() *WebviewWindow ``` **Example:** ```go -window := app.NewWebviewWindow() +window := app.Window.New() window.Show() ``` -### NewWebviewWindowWithOptions() +### app.Window.NewWithOptions() Creates a new webview window with custom options. ```go -func (a *App) NewWebviewWindowWithOptions(options WebviewWindowOptions) *WebviewWindow +func (wm *WindowManager) NewWithOptions(options WebviewWindowOptions) *WebviewWindow ``` **Example:** ```go -window := app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ +window := app.Window.NewWithOptions(application.WebviewWindowOptions{ Title: "My Window", Width: 800, Height: 600, @@ -114,35 +114,35 @@ window := app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ }) ``` -### GetWindowByName() +### app.Window.GetByName() Gets a window by its name. ```go -func (a *App) GetWindowByName(name string) Window +func (wm *WindowManager) GetByName(name string) Window ``` **Example:** ```go -window := app.GetWindowByName("main") +window := app.Window.GetByName("main") if window != nil { window.Show() } ``` -### GetWindows() +### app.Window.GetAll() Returns all application windows. ```go -func (a *App) GetWindows() []Window +func (wm *WindowManager) GetAll() []Window ``` **Example:** ```go -windows := app.GetWindows() +windows := app.Window.GetAll() for _, window := range windows { fmt.Println("Window:", window.Name()) } @@ -168,7 +168,7 @@ app.Env // Environment variables ```go // Create window -window := app.Window.NewWebviewWindow() +window := app.Window.New() // Show dialog app.Dialog.Info().SetMessage("Hello!").Show() @@ -207,55 +207,55 @@ app.RegisterService(application.NewService(NewMyService(app))) ## Event Management -### EmitEvent() +### app.Event.Emit() Emits a custom event. ```go -func (a *App) EmitEvent(name string, data ...interface{}) +func (em *EventManager) Emit(name string, data ...interface{}) ``` **Example:** ```go // Emit event with data -app.EmitEvent("user-logged-in", map[string]interface{}{ +app.Event.Emit("user-logged-in", map[string]interface{}{ "username": "john", "timestamp": time.Now(), }) ``` -### OnEvent() +### app.Event.On() Listens for custom events. ```go -func (a *App) OnEvent(name string, callback func(*CustomEvent)) +func (em *EventManager) On(name string, callback func(*CustomEvent)) ``` **Example:** ```go -app.OnEvent("user-logged-in", func(e *application.CustomEvent) { +app.Event.On("user-logged-in", func(e *application.CustomEvent) { data := e.Data.(map[string]interface{}) username := data["username"].(string) fmt.Println("User logged in:", username) }) ``` -### OnApplicationEvent() +### app.Event.OnApplicationEvent() Listens for application lifecycle events. ```go -func (a *App) OnApplicationEvent(eventType ApplicationEventType, callback func(*ApplicationEvent)) func() +func (em *EventManager) OnApplicationEvent(eventType ApplicationEventType, callback func(*ApplicationEvent)) func() ``` **Example:** ```go // Listen for shutdown -app.OnApplicationEvent(application.EventApplicationShutdown, func(e *application.ApplicationEvent) { +app.Event.OnApplicationEvent(application.EventApplicationShutdown, func(e *application.ApplicationEvent) { fmt.Println("Application shutting down") // Cleanup }) @@ -415,7 +415,7 @@ func main() { }) // Create main window - window := app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ + window := app.Window.NewWithOptions(application.WebviewWindowOptions{ Title: "My App", Width: 1024, Height: 768, diff --git a/docs/src/content/docs/reference/events.mdx b/docs/src/content/docs/reference/events.mdx index a75ea62d568..d6286018eac 100644 --- a/docs/src/content/docs/reference/events.mdx +++ b/docs/src/content/docs/reference/events.mdx @@ -24,12 +24,12 @@ The Events API provides methods to emit and listen to events, enabling communica ## Event Methods (Go) -### EmitEvent() +### app.Event.Emit() Emits a custom event to all windows. ```go -func (a *App) EmitEvent(name string, data ...interface{}) +func (em *EventManager) Emit(name string, data ...interface{}) ``` **Parameters:** @@ -39,24 +39,24 @@ func (a *App) EmitEvent(name string, data ...interface{}) **Example:** ```go // Emit simple event -app.EmitEvent("user-logged-in") +app.Event.Emit("user-logged-in") // Emit with data -app.EmitEvent("data-updated", map[string]interface{}{ +app.Event.Emit("data-updated", map[string]interface{}{ "count": 42, "status": "success", }) // Emit multiple values -app.EmitEvent("progress", 75, "Processing files...") +app.Event.Emit("progress", 75, "Processing files...") ``` -### OnEvent() +### app.Event.On() Listens for custom events in Go. ```go -func (a *App) OnEvent(name string, callback func(*CustomEvent)) func() +func (em *EventManager) On(name string, callback func(*CustomEvent)) func() ``` **Parameters:** @@ -68,7 +68,7 @@ func (a *App) OnEvent(name string, callback func(*CustomEvent)) func() **Example:** ```go // Listen for events -cleanup := app.OnEvent("user-action", func(e *application.CustomEvent) { +cleanup := app.Event.On("user-action", func(e *application.CustomEvent) { data := e.Data.(map[string]interface{}) action := data["action"].(string) app.Logger.Info("User action", "action", action) @@ -87,7 +87,7 @@ Emit events to a specific window: window.EmitEvent("notification", "Hello from Go!") // Emit to all windows -app.EmitEvent("global-update", data) +app.Event.Emit("global-update", data) ``` ## Event Methods (Frontend) @@ -187,12 +187,12 @@ OffAll('data-updated') ## Application Events -### OnApplicationEvent() +### app.Event.OnApplicationEvent() Listens for application lifecycle events. ```go -func (a *App) OnApplicationEvent(eventType ApplicationEventType, callback func(*ApplicationEvent)) func() +func (em *EventManager) OnApplicationEvent(eventType ApplicationEventType, callback func(*ApplicationEvent)) func() ``` **Event Types:** @@ -203,13 +203,13 @@ func (a *App) OnApplicationEvent(eventType ApplicationEventType, callback func(* **Example:** ```go // Handle application startup -app.OnApplicationEvent(application.EventApplicationStarted, func(e *application.ApplicationEvent) { +app.Event.OnApplicationEvent(application.EventApplicationStarted, func(e *application.ApplicationEvent) { app.Logger.Info("Application started") // Initialize resources }) // Handle application shutdown -app.OnApplicationEvent(application.EventApplicationShutdown, func(e *application.ApplicationEvent) { +app.Event.OnApplicationEvent(application.EventApplicationShutdown, func(e *application.ApplicationEvent) { app.Logger.Info("Application shutting down") // Cleanup resources, save state database.Close() @@ -268,7 +268,7 @@ func (s *DataService) FetchData(query string) ([]Item, error) { items := fetchFromDatabase(query) // Emit event when done - s.app.EmitEvent("data-fetched", map[string]interface{}{ + s.app.Event.Emit("data-fetched", map[string]interface{}{ "query": query, "count": len(items), }) @@ -309,7 +309,7 @@ func (s *Service) ProcessFiles(files []string) error { processFile(file) // Emit progress event - s.app.EmitEvent("progress", map[string]interface{}{ + s.app.Event.Emit("progress", map[string]interface{}{ "current": i + 1, "total": total, "percent": float64(i+1) / float64(total) * 100, @@ -317,7 +317,7 @@ func (s *Service) ProcessFiles(files []string) error { }) } - s.app.EmitEvent("processing-complete") + s.app.Event.Emit("processing-complete") return nil } ``` @@ -349,7 +349,7 @@ Perfect for applications with multiple windows like settings panels, dashboards, ```go // Broadcast to all windows -app.EmitEvent("theme-changed", "dark") +app.Event.Emit("theme-changed", "dark") // Send to specific window preferencesWindow.EmitEvent("settings-updated", settings) @@ -391,7 +391,7 @@ func (s *StateService) UpdateState(key string, value interface{}) { s.mu.Unlock() // Notify all windows - s.app.EmitEvent("state-updated", map[string]interface{}{ + s.app.Event.Emit("state-updated", map[string]interface{}{ "key": key, "value": value, }) @@ -435,21 +435,21 @@ type NotificationService struct { } func (s *NotificationService) Success(message string) { - s.app.EmitEvent("notification", map[string]interface{}{ + s.app.Event.Emit("notification", map[string]interface{}{ "type": "success", "message": message, }) } func (s *NotificationService) Error(message string) { - s.app.EmitEvent("notification", map[string]interface{}{ + s.app.Event.Emit("notification", map[string]interface{}{ "type": "error", "message": message, }) } func (s *NotificationService) Info(message string) { - s.app.EmitEvent("notification", map[string]interface{}{ + s.app.Event.Emit("notification", map[string]interface{}{ "type": "info", "message": message, }) @@ -498,7 +498,7 @@ func NewEventDemoService(app *application.Application) *EventDemoService { service := &EventDemoService{app: app} // Listen for custom events - app.OnEvent("user-action", func(e *application.CustomEvent) { + app.Event.On("user-action", func(e *application.CustomEvent) { data := e.Data.(map[string]interface{}) app.Logger.Info("User action received", "data", data) }) @@ -508,26 +508,26 @@ func NewEventDemoService(app *application.Application) *EventDemoService { func (s *EventDemoService) StartLongTask() { go func() { - s.app.EmitEvent("task-started") + s.app.Event.Emit("task-started") for i := 1; i <= 10; i++ { time.Sleep(500 * time.Millisecond) - s.app.EmitEvent("task-progress", map[string]interface{}{ + s.app.Event.Emit("task-progress", map[string]interface{}{ "step": i, "total": 10, "percent": i * 10, }) } - s.app.EmitEvent("task-completed", map[string]interface{}{ + s.app.Event.Emit("task-completed", map[string]interface{}{ "message": "Task finished successfully!", }) }() } func (s *EventDemoService) BroadcastMessage(message string) { - s.app.EmitEvent("broadcast", message) + s.app.Event.Emit("broadcast", message) } func main() { @@ -536,11 +536,11 @@ func main() { }) // Handle application lifecycle - app.OnApplicationEvent(application.EventApplicationStarted, func(e *application.ApplicationEvent) { + app.Event.OnApplicationEvent(application.EventApplicationStarted, func(e *application.ApplicationEvent) { app.Logger.Info("Application started!") }) - app.OnApplicationEvent(application.EventApplicationShutdown, func(e *application.ApplicationEvent) { + app.Event.OnApplicationEvent(application.EventApplicationShutdown, func(e *application.ApplicationEvent) { app.Logger.Info("Application shutting down...") }) @@ -549,7 +549,7 @@ func main() { app.RegisterService(application.NewService(service)) // Create window - window := app.NewWebviewWindow() + window := app.Window.New() // Handle window events window.OnWindowEvent(events.Common.WindowFocus, func(e *application.WindowEvent) { @@ -673,11 +673,11 @@ This mapping happens automatically in the background, so when you listen for `ev ```go import "github.com/wailsapp/wails/v3/pkg/events" -app.OnApplicationEvent(events.Common.ApplicationStarted, func(e *application.ApplicationEvent) { +app.Event.OnApplicationEvent(events.Common.ApplicationStarted, func(e *application.ApplicationEvent) { app.Logger.Info("Application ready!") }) -app.OnApplicationEvent(events.Common.ThemeChanged, func(e *application.ApplicationEvent) { +app.Event.OnApplicationEvent(events.Common.ThemeChanged, func(e *application.ApplicationEvent) { // Update app theme }) ``` @@ -720,7 +720,7 @@ window.OnWindowEvent(events.Common.WindowFocus, func(e *application.WindowEvent) // Cancel window close window.RegisterHook(events.Common.WindowClosing, func(e *application.WindowEvent) { - result, _ := app.QuestionDialog(). + result, _ := app.Dialog.Question(). SetMessage("Close window?"). SetButtons("Yes", "No"). Show() @@ -749,14 +749,14 @@ window.OnWindowEvent(events.Common.WindowRuntimeReady, func(e *application.Windo ```go // Good - descriptive and specific -app.EmitEvent("user:logged-in", user) -app.EmitEvent("data:fetch:complete", results) -app.EmitEvent("ui:theme:changed", theme) +app.Event.Emit("user:logged-in", user) +app.Event.Emit("data:fetch:complete", results) +app.Event.Emit("ui:theme:changed", theme) // Bad - vague and unclear -app.EmitEvent("event1", data) -app.EmitEvent("update", stuff) -app.EmitEvent("e", value) +app.Event.Emit("event1", data) +app.Event.Emit("update", stuff) +app.Event.Emit("e", value) ``` ## Performance Considerations @@ -776,7 +776,7 @@ func (s *Service) EmitWithDebounce(event string, data interface{}) { return // Skip this emission } - s.app.EmitEvent(event, data) + s.app.Event.Emit(event, data) s.lastEmit = now } ``` diff --git a/docs/src/content/docs/reference/menu.mdx b/docs/src/content/docs/reference/menu.mdx index 48535707330..f0b9f064009 100644 --- a/docs/src/content/docs/reference/menu.mdx +++ b/docs/src/content/docs/reference/menu.mdx @@ -316,12 +316,12 @@ menu.Update() ## Application Menu -### SetApplicationMenu() +### app.Menu.Set() Sets the application's main menu bar. ```go -func (a *App) SetApplicationMenu(menu *Menu) +func (mm *MenuManager) Set(menu *Menu) ``` **Example:** @@ -347,7 +347,7 @@ editMenu.Add("Cut").SetAccelerator("Ctrl+X").OnClick(cut) editMenu.Add("Copy").SetAccelerator("Ctrl+C").OnClick(copy) editMenu.Add("Paste").SetAccelerator("Ctrl+V").OnClick(paste) -app.SetApplicationMenu(menu) +app.Menu.Set(menu) ``` **Platform notes:** @@ -357,12 +357,12 @@ app.SetApplicationMenu(menu) ## Context Menus -### RegisterContextMenu() +### app.ContextMenu.Add() Registers a context menu (right-click menu) with a specific name. ```go -func (a *App) RegisterContextMenu(name string, menu *Menu) +func (cm *ContextMenuManager) Add(name string, menu *Menu) ``` **Parameters:** @@ -412,17 +412,17 @@ func updateContextMenu() { ## System Tray Menu -### NewSystemTray() +### app.SystemTray.New() Creates a new system tray icon. ```go -func (a *App) NewSystemTray() *SystemTray +func (sm *SystemTrayManager) New() *SystemTray ``` **Example:** ```go -tray := app.NewSystemTray() +tray := app.SystemTray.New() ``` ### SetIcon() @@ -572,9 +572,9 @@ func main() { }) menu := createMenu(app) - app.SetApplicationMenu(menu) + app.Menu.Set(menu) - window := app.NewWebviewWindow() + window := app.Window.New() window.Show() app.Run() @@ -586,7 +586,7 @@ func main() { ```go func setupSystemTray(app *application.Application, window *application.Window) { // Create system tray - tray := app.NewSystemTray() + tray := app.SystemTray.New() // Set icon iconData, _ := os.ReadFile("icon.png") @@ -667,7 +667,7 @@ func (e *Editor) createMenu() { }) e.updateMenuState() - e.app.SetApplicationMenu(e.menu) + e.app.Menu.Set(e.menu) } func (e *Editor) updateMenuState() { diff --git a/docs/src/content/docs/reference/overview.mdx b/docs/src/content/docs/reference/overview.mdx index 44b2a819c6a..8a3b77bc389 100644 --- a/docs/src/content/docs/reference/overview.mdx +++ b/docs/src/content/docs/reference/overview.mdx @@ -37,7 +37,7 @@ This is the complete API reference for Wails v3. It documents every public type, Most methods that can fail return `error` as the last return value: ```go -window, err := app.NewWebviewWindow() +window, err := app.Window.New() if err != nil { log.Fatal(err) } diff --git a/docs/src/content/docs/reference/window.mdx b/docs/src/content/docs/reference/window.mdx index 33d0a8b5533..c376ee42605 100644 --- a/docs/src/content/docs/reference/window.mdx +++ b/docs/src/content/docs/reference/window.mdx @@ -30,7 +30,7 @@ func (w *Window) Show() **Example:** ```go -window := app.NewWebviewWindow() +window := app.Window.New() window.Show() ``` @@ -202,7 +202,7 @@ func (w *Window) Centre() **Example:** ```go -window := app.NewWebviewWindow() +window := app.Window.New() window.Centre() window.Show() ``` @@ -441,7 +441,7 @@ func (w *Window) RegisterHook( import "github.com/wailsapp/wails/v3/pkg/events" window.RegisterHook(events.Common.WindowClosing, func(e *application.WindowEvent) { - result, _ := app.QuestionDialog(). + result, _ := app.Dialog.Question(). SetTitle("Confirm Close"). SetMessage("Are you sure you want to close this window?"). SetButtons("Yes", "No"). @@ -457,7 +457,7 @@ window.RegisterHook(events.Common.WindowClosing, func(e *application.WindowEvent ```go window.RegisterHook(events.Common.WindowClosing, func(e *application.WindowEvent) { if hasUnsavedChanges { - result, _ := app.QuestionDialog(). + result, _ := app.Dialog.Question(). SetMessage("Save changes before closing?"). SetButtons("Save", "Don't Save", "Cancel"). Show() @@ -620,7 +620,7 @@ func main() { }) // Create window with options - window := app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ + window := app.Window.NewWithOptions(application.WebviewWindowOptions{ Title: "My Application", Width: 1024, Height: 768, @@ -638,7 +638,7 @@ func main() { // Set up event hooks window.RegisterHook(events.Common.WindowClosing, func(e *application.WindowEvent) { // Confirm before closing - result, _ := app.QuestionDialog(). + result, _ := app.Dialog.Question(). SetTitle("Confirm Close"). SetMessage("Are you sure you want to close this window?"). SetButtons("Yes", "No"). diff --git a/v3/UNRELEASED_CHANGELOG.md b/v3/UNRELEASED_CHANGELOG.md index 8e46480384f..ff79bbb3dc0 100644 --- a/v3/UNRELEASED_CHANGELOG.md +++ b/v3/UNRELEASED_CHANGELOG.md @@ -23,6 +23,7 @@ After processing, the content will be moved to the main changelog and this file ## Fixed +- Fix outdated Manager API references in documentation (31 files updated to use new pattern like `app.Window.New()`, `app.Event.Emit()`, etc.) by @leaanthony ## Deprecated