diff --git a/mkdocs-website/docs/API/application.md b/mkdocs-website/docs/API/application.md new file mode 100644 index 00000000000..eae421e08d4 --- /dev/null +++ b/mkdocs-website/docs/API/application.md @@ -0,0 +1,184 @@ +# Application + +The application API assists in creating an application using the Wails framework. + +### New + +API: `New(appOptions Options) *App` + +`New(appOptions Options)` creates a new application using the given application options . It applies default values for unspecified options, merges them with the provided ones, initializes and returns an instance of the application. + +In case of an error during initialization, the application is stopped with the error message provided. + +It should be noted that if a global application instance already exists, that instance will be returned instead of creating a new one. + +### Get + +`Get()` returns the global application instance. It's useful when you need to access the application from different parts of your code. + +### Capabilities + +API: `Capabilities() capabilities.Capabilities` + +`Capabilities()` retrieves a map of capabilities that the application currently has. Capabilities can be about different features the operating system provides, like webview features. + +### GetPID + +API: `GetPID() int` + +`GetPID()` returns the Process ID of the application. + +### Run + +API: `Run() error` + +`Run()` starts the execution of the application and its components. + + +### Quit + +API: `Quit()` + +`Quit()` quits the application by destroying windows and potentially other components. + +### IsDarkMode + +API: `IsDarkMode() bool` + +`IsDarkMode()` checks if the application is running in dark mode. It returns a boolean indicating whether dark mode is enabled. + +### Hide + +API: `Hide()` + +`Hide()` hides the application window. + +### Show + +API: `Show()` + +`Show()` shows the application window. + +### NewWebviewWindow + +API: `NewWebviewWindow() *WebviewWindow` + +`NewWebviewWindow()` creates a new Webview window with default options, and returns it. + +### NewWebviewWindowWithOptions + +API: `NewWebviewWindowWithOptions(windowOptions WebviewWindowOptions) *WebviewWindow` + +`NewWebviewWindowWithOptions()` creates a new webview window with custom options. The newly created window is added to a map of windows managed by the application. + +### OnWindowCreation + +API: `OnWindowCreation(callback func(window *WebviewWindow))` + +`OnWindowCreation()` registers a callback function to be called when a window is created. + +### GetWindowByName + +API: `GetWindowByName(name string) *WebviewWindow` + +`GetWindowByName()` fetches and returns a window with a specific name. + +### CurrentWindow + +API: `CurrentWindow() *WebviewWindow` + +`CurrentWindow()` fetches and returns a pointer to the currently active window in the application. If there is no window, it returns nil. + + +### NewSystemTray + +API: `NewSystemTray() *SystemTray` + +`NewSystemTray()` creates and returns a new system tray instance. + + + +### NewMenu + +API: `NewMenu() *Menu` + +This method, belonging to App struct and not Menu struct, also initialises and returns a new `Menu`. + + + +### RegisterContextMenu + +API: `RegisterContextMenu(name string, menu *Menu)` + +`RegisterContextMenu()` registers a context menu with a given name. This menu can be used later in the application. + +### SetMenu + +API: `SetMenu(menu *Menu)` + +`SetMenu()` sets the menu for the application. + +### ShowAboutDialog + +API: `ShowAboutDialog()` + +`ShowAboutDialog()` shows an "About" dialog box. It can show the application's name, description and icon. + +### Info + +`InfoDialog()` creates and returns a new instance of `MessageDialog` with an `InfoDialogType`. This dialog is typically used to display informational messages to the user. + +### Question + +`QuestionDialog()` creates and returns a new instance of `MessageDialog` with a `QuestionDialogType`. This dialog is often used to ask a question to the user and expect a response. + +### Warning + +`WarningDialog()` creates and returns a new instance of `MessageDialog` with a `WarningDialogType`. As the name suggests, this dialog is primarily used to display warning messages to the user. + +### Error + +`ErrorDialog()` creates and returns a new instance of `MessageDialog` with an `ErrorDialogType`. This dialog is designed to be used when you need to display an error message to the user. + +### OpenFile + +`OpenFileDialog()` creates and returns a new `OpenFileDialogStruct`. This dialog prompts the user to select one or more files from their file system. + +### SaveFile + +`SaveFileDialog()` creates and returns a new `SaveFileDialogStruct`. This dialog prompts the user to choose a location on their file system where a file should be saved. + +### OpenDirectory + +`OpenDirectoryDialog()` creates and returns a new instance of `MessageDialog` with an `OpenDirectoryDialogType`. This dialog enables the user to choose a directory from their file system. + + +### On + +API: `On(eventType events.ApplicationEventType, callback func(event *Event)) func()` + +`On()` registers an event listener for specific application events. The callback function provided will be triggered when the corresponding event occurs. The function returns a function that can be called to remove the listener. + +### RegisterHook + +API: `RegisterHook(eventType events.ApplicationEventType, callback func(event *Event)) func()` + +`RegisterHook()` registers a callback to be run as a hook during specific events. These hooks are run before listeners attached with `On()`. The function returns a function that can be called to remove the hook. + +### GetPrimaryScreen + +API: `GetPrimaryScreen() (*Screen, error)` + +`GetPrimaryScreen()` returns the primary screen of the system. + +### GetScreens + +API: `GetScreens() ([]*Screen, error)` + +`GetScreens()` returns information about all screens attached to the system. + +This is a brief summary of the exported methods in the provided `App` struct. Do note that for more detailed functionality or considerations, refer to the actual Go code or further internal documentation. + +## Options + +--8<-- "../../../v3/pkg/application/options_application.go" diff --git a/mkdocs-website/docs/API/mainthread.md b/mkdocs-website/docs/API/mainthread.md new file mode 100644 index 00000000000..d62f0c4251f --- /dev/null +++ b/mkdocs-website/docs/API/mainthread.md @@ -0,0 +1,38 @@ +# Main Thread Functions + +These methods are utility functions to run code on the main thread. This is required when you want to run +custom code on the UI thread. + +### InvokeSync + +API: `InvokeSync(fn func())` + +This function runs the passed function (`fn`) synchronously. It uses a WaitGroup (`wg`) to ensure that the main thread waits for the `fn` function to finish before it continues. If a panic occurs inside `fn`, it will be passed to the handler function `PanicHandler`, defined in the application options. + +### InvokeSyncWithResult + +API: `InvokeSyncWithResult[T any](fn func() T) (res T)` + +This function works similarly to `InvokeSync(fn func())`, however, it yields a result. Use this for calling any function with a single return. + +### InvokeSyncWithError + +API: `InvokeSyncWithError(fn func() error) (err error)` + +This function runs `fn` synchronously and returns any error that `fn` produces. Note that this function will recover from a panic if one occurs during `fn`'s execution. + +### InvokeSyncWithResultAndError + +API: `InvokeSyncWithResultAndError[T any](fn func() (T, error)) (res T, err error)` + +This function runs `fn` synchronously and returns both a result of type `T` and an error. + +### InvokeAsync + +API: `InvokeAsync(fn func())` + +This function runs `fn` asynchronously. It runs the given function on the main thread. If a panic occurs inside `fn`, it will be passed to the handler function `PanicHandler`, defined in the application options. + +--- + +_Note_: These functions will block execution until `fn` has finished. It's critical to ensure that `fn` doesn't block. If you need to run a function that blocks, use `InvokeAsync` instead. \ No newline at end of file diff --git a/mkdocs-website/docs/API/menu.md b/mkdocs-website/docs/API/menu.md new file mode 100644 index 00000000000..905ce6d3799 --- /dev/null +++ b/mkdocs-website/docs/API/menu.md @@ -0,0 +1,57 @@ +# Menu + +### `type Menu struct` + +The `Menu` struct holds information about a menu, including which items it contains and its label. + +### `func NewMenu() *Menu` + +This function initializes a new Menu. + +### Add + +API: `Add(label string) *MenuItem` + +This method takes a `label` of type `string` as an input and adds a new `MenuItem` with the given label to the menu. It returns the `MenuItem` added. + +### AddSeparator + +API: `AddSeparator()` + +This method adds a new separator `MenuItem` to the menu. + +### AddCheckbox + +API: `AddCheckbox(label string, enabled bool) *MenuItem` + +This method takes a `label` of type `string` and `enabled` of type `bool` as inputs and adds a new checkbox `MenuItem` with the given label and enabled state to the menu. It returns the `MenuItem` added. + +### AddRadio + +API: `AddRadio(label string, enabled bool) *MenuItem` + +This method takes a `label` of type `string` and `enabled` of type `bool` as inputs and adds a new radio `MenuItem` with the given label and enabled state to the menu. It returns the `MenuItem` added. + +### Update + +API: `Update()` + +This method processes any radio groups and updates the menu if a menu implementation is not initialized. + +### AddSubmenu + +API: `AddSubmenu(s string) *Menu` + +This method takes a `s` of type `string` as input and adds a new submenu `MenuItem` with the given label to the menu. It returns the submenu added. + +### AddRole + +API: `AddRole(role Role) *Menu` + +This method takes `role` of type `Role` as input, adds it to the menu if it is not `nil` and returns the `Menu`. + +### SetLabel + +API: `SetLabel(label string)` + +This method sets the `label` of the `Menu`. diff --git a/mkdocs-website/docs/API/systray.md b/mkdocs-website/docs/API/systray.md new file mode 100644 index 00000000000..6e62aaba1f9 --- /dev/null +++ b/mkdocs-website/docs/API/systray.md @@ -0,0 +1,99 @@ +# System Tray + +The system tray houses notification area on a desktop environment, which can contain both icons of currently-running applications and specific system notifications. + +### NewSystemTray + +API: `NewSystemTray(id uint) *SystemTray` + +The `NewSystemTray` function constructs an instance of the `SystemTray` struct. This function takes a unique identifier of type `uint`. It returns a pointer to a `SystemTray` instance. + +### SetLabel + +API: `SetLabel(label string)` + +The `SetLabel` method sets the tray's label. + +### Label + +API: `Label() string` + +The `Label` method retrieves the tray's label. + +### PositionWindow + +API: `PositionWindow(*WebviewWindow, offset int) error` + +The `PositionWindow` method calls both `AttachWindow` and `WindowOffset` methods. + +### SetIcon + +API: `SetIcon(icon []byte) *SystemTray` + +The `SetIcon` method sets the system tray's icon. + +### SetDarkModeIcon + +API: `SetDarkModeIcon(icon []byte) *SystemTray` + +The `SetDarkModeIcon` method sets the system tray's icon when in dark mode. + +### SetMenu + +API: `SetMenu(menu *Menu) *SystemTray` + +The `SetMenu` method sets the system tray's menu. + +### Destroy + +API: `Destroy()` + +The `Destroy` method destroys the system tray instance. + +### OnClick + +API: `OnClick(handler func()) *SystemTray` + +The `OnClick` method sets the function to execute when the tray icon is clicked. + +### OnRightClick + +API: `OnRightClick(handler func()) *SystemTray` + +The `OnRightClick` method sets the function to execute when right-clicking the tray icon. + +### OnDoubleClick + +API: `OnDoubleClick(handler func()) *SystemTray` + +The `OnDoubleClick` method sets the function to execute when double-clicking the tray icon. + +### OnRightDoubleClick + +API: `OnRightDoubleClick(handler func()) *SystemTray` + +The `OnRightDoubleClick` method sets the function to execute when right double-clicking the tray icon. + +### AttachWindow + +API: `AttachWindow(window *WebviewWindow) *SystemTray` + +The `AttachWindow` method attaches a window to the system tray. The window will be shown when the system tray icon is clicked. + +### WindowOffset + +API: `WindowOffset(offset int) *SystemTray` + +The `WindowOffset` method sets the gap in pixels between the system tray and the window. + +### WindowDebounce + +API: `WindowDebounce(debounce time.Duration) *SystemTray` + +The `WindowDebounce` method sets a debounce time. In the context of Windows, this is used to specify how long to wait before responding to a mouse up event on the notification icon. + +### OpenMenu + +API: `OpenMenu()` + +The `OpenMenu` method opens the menu associated with the system tray. diff --git a/mkdocs-website/docs/API/window.md b/mkdocs-website/docs/API/window.md new file mode 100644 index 00000000000..99b7180a5cd --- /dev/null +++ b/mkdocs-website/docs/API/window.md @@ -0,0 +1,115 @@ +# Window + +To create a window, use [Application.NewWebviewWindow](application.md#newwebviewwindow) or [Application.NewWebviewWindowWithOptions](application.md#newwebviewwindowwithoptions). The former creates a window with default options, while the latter allows you to specify custom options. + +These methods are callable on the returned WebviewWindow object: + +### SetTitle + +API: `SetTitle(title string) *WebviewWindow` + +This method updates the window title to the provided string. It returns the WebviewWindow object, allowing for method chaining. + + +### Name + +API: `Name() string` + +This function returns the name of the WebviewWindow. + + +### SetSize + +API: `SetSize(width, height int) *WebviewWindow` + +This method sets the size of the WebviewWindow to the provided width and height parameters. If the dimensions provided exceed the constraints, they are adjusted appropriately. + + +### SetAlwaysOnTop + +API: `SetAlwaysOnTop(b bool) *WebviewWindow` + +This function sets the window to stay on top based on the boolean flag provided. + + +### Show + +API: `Show() *WebviewWindow` + +`Show` method is used to make the window visible. If the window is not running, it first invokes the `run` method to start the window and then makes it visible. + + +### Hide + +API: `Hide() *WebviewWindow` + +`Hide` method is used to hide the window. It sets the hidden status of the window to true and emits the window hide event. + + +### SetURL + +API: `SetURL(s string) *WebviewWindow` + +`SetURL` method is used to set the URL of the window to the given URL string. + + +### SetZoom + +API: `SetZoom(magnification float64) *WebviewWindow` + +`SetZoom` method sets the zoom level of the window content to the provided magnification level. + + +### GetZoom + +API: `GetZoom() float64` + +`GetZoom` function returns the current zoom level of the window content. + + +### GetScreen + +API: `GetScreen() (*Screen, error)` + +`GetScreen` method returns the screen on which the window is displayed. + +#### SetFrameless + +API: `SetFrameless(frameless bool) *WebviewWindow` + +This function is used to remove the window frame and title bar. It toggles the framelessness of the window according to the boolean value provided (true for frameless, false for framed). + + +#### RegisterContextMenu + +API: `RegisterContextMenu(name string, menu *Menu)` + +This function is used to register a context menu and assigns it the given name. + + +#### NativeWindowHandle + +API: `NativeWindowHandle() (uintptr, error)` + +This function is used to fetch the platform native window handle for the window. + + +#### Focus + +API: `Focus()` + +This function is used to focus the window. + + +#### SetEnabled + +API: `SetEnabled(enabled bool)` + +This function is used to enable/disable the window based on the provided boolean value. + + +#### SetAbsolutePosition + +API: `SetAbsolutePosition(x int, y int)` + +This function sets the absolute position of the window in the screen. diff --git a/mkdocs-website/docs/favicon.ico b/mkdocs-website/docs/favicon.ico index fb362effe51..256f9ec1992 100644 Binary files a/mkdocs-website/docs/favicon.ico and b/mkdocs-website/docs/favicon.ico differ diff --git a/mkdocs-website/mkdocs.yml b/mkdocs-website/mkdocs.yml index afc281f2b39..7490f09eb8f 100644 --- a/mkdocs-website/mkdocs.yml +++ b/mkdocs-website/mkdocs.yml @@ -84,6 +84,12 @@ nav: - Next Steps: getting-started/next-steps.md - Feedback: getting-started/feedback.md - What's New in v3?: whats-new.md + - API: + - Application: API/application.md + - Window: API/window.md + - System Tray: API/systray.md + - Menu: API/menu.md + - Main Thread: API/mainthread.md - Development: - Introduction: development/introduction.md - Status: development/status.md diff --git a/v3/examples/systray/main.go b/v3/examples/systray/main.go index 1c77a14d9b6..cf57606ecc3 100644 --- a/v3/examples/systray/main.go +++ b/v3/examples/systray/main.go @@ -43,8 +43,6 @@ func main() { if runtime.GOOS == "darwin" { systemTray.SetTemplateIcon(icons.SystrayMacTemplate) - systemTray.SetLabel("\u001B[1;31mW\u001B[1;32ma\u001B[1;33mi\u001B[1;34ml\u001B[1;35ms\u001B[0m") - } myMenu := app.NewMenu() diff --git a/v3/pkg/application/application.go b/v3/pkg/application/application.go index b4cd7fe2c5b..ad89d408b04 100644 --- a/v3/pkg/application/application.go +++ b/v3/pkg/application/application.go @@ -377,7 +377,7 @@ func (a *App) error(message string, args ...any) { } func (a *App) NewWebviewWindowWithOptions(windowOptions WebviewWindowOptions) *WebviewWindow { - newWindow := NewWindow(windowOptions) + newWindow := newWindow(windowOptions) id := newWindow.id a.windowsLock.Lock() @@ -396,7 +396,7 @@ func (a *App) NewWebviewWindowWithOptions(windowOptions WebviewWindowOptions) *W func (a *App) NewSystemTray() *SystemTray { id := a.getSystemTrayID() - newSystemTray := NewSystemTray(id) + newSystemTray := newSystemTray(id) a.systemTraysLock.Lock() a.systemTrays[id] = newSystemTray @@ -571,7 +571,7 @@ func (a *App) CurrentWindow() *WebviewWindow { } func (a *App) Quit() { - invokeSync(func() { + InvokeSync(func() { a.windowsLock.Lock() for _, window := range a.windows { window.Destroy() @@ -767,50 +767,3 @@ func (a *App) handleWindowKeyEvent(event *windowKeyEvent) { // Get callback from window window.handleKeyEvent(event.acceleratorString) } - -func invokeSync(fn func()) { - var wg sync.WaitGroup - wg.Add(1) - globalApplication.dispatchOnMainThread(func() { - defer processPanicHandlerRecover() - fn() - wg.Done() - }) - wg.Wait() -} - -func invokeSyncWithResult[T any](fn func() T) (res T) { - var wg sync.WaitGroup - wg.Add(1) - globalApplication.dispatchOnMainThread(func() { - defer processPanicHandlerRecover() - res = fn() - wg.Done() - }) - wg.Wait() - return res -} - -func invokeSyncWithError(fn func() error) (err error) { - var wg sync.WaitGroup - wg.Add(1) - globalApplication.dispatchOnMainThread(func() { - defer processPanicHandlerRecover() - err = fn() - wg.Done() - }) - wg.Wait() - return -} - -func invokeSyncWithResultAndError[T any](fn func() (T, error)) (res T, err error) { - var wg sync.WaitGroup - wg.Add(1) - globalApplication.dispatchOnMainThread(func() { - defer processPanicHandlerRecover() - res, err = fn() - wg.Done() - }) - wg.Wait() - return res, err -} diff --git a/v3/pkg/application/application_darwin.go b/v3/pkg/application/application_darwin.go index 75549583f2b..4a5e28b016c 100644 --- a/v3/pkg/application/application_darwin.go +++ b/v3/pkg/application/application_darwin.go @@ -238,7 +238,7 @@ func newPlatformApp(app *App) *macosApp { //export processApplicationEvent func processApplicationEvent(eventID C.uint, _ unsafe.Pointer) { - event := NewApplicationEvent(int(eventID)) + event := newApplicationEvent(int(eventID)) switch event.Id { case uint(events.Mac.ApplicationDidChangeTheme): isDark := globalApplication.IsDarkMode() diff --git a/v3/pkg/application/application_linux.go b/v3/pkg/application/application_linux.go index a899b799edd..17dc6a7cd50 100644 --- a/v3/pkg/application/application_linux.go +++ b/v3/pkg/application/application_linux.go @@ -82,7 +82,7 @@ func (m *linuxApp) getApplicationMenu() pointer { menu := globalApplication.ApplicationMenu if menu != nil { - invokeSync(func() { + InvokeSync(func() { menu.Update() }) m.applicationMenu = (menu.impl).(*linuxMenu).native diff --git a/v3/pkg/application/application_windows.go b/v3/pkg/application/application_windows.go index de4d647d4a7..840e0400442 100644 --- a/v3/pkg/application/application_windows.go +++ b/v3/pkg/application/application_windows.go @@ -250,15 +250,15 @@ func (m *windowsApp) wndProc(hwnd w32.HWND, msg uint32, wParam, lParam uintptr) case w32.WM_POWERBROADCAST: switch wParam { case w32.PBT_APMPOWERSTATUSCHANGE: - applicationEvents <- NewApplicationEvent(int(events.Windows.APMPowerStatusChange)) + applicationEvents <- newApplicationEvent(int(events.Windows.APMPowerStatusChange)) case w32.PBT_APMSUSPEND: - applicationEvents <- NewApplicationEvent(int(events.Windows.APMSuspend)) + applicationEvents <- newApplicationEvent(int(events.Windows.APMSuspend)) case w32.PBT_APMRESUMEAUTOMATIC: - applicationEvents <- NewApplicationEvent(int(events.Windows.APMResumeAutomatic)) + applicationEvents <- newApplicationEvent(int(events.Windows.APMResumeAutomatic)) case w32.PBT_APMRESUMESUSPEND: - applicationEvents <- NewApplicationEvent(int(events.Windows.APMResumeSuspend)) + applicationEvents <- newApplicationEvent(int(events.Windows.APMResumeSuspend)) case w32.PBT_POWERSETTINGCHANGE: - applicationEvents <- NewApplicationEvent(int(events.Windows.APMPowerSettingChange)) + applicationEvents <- newApplicationEvent(int(events.Windows.APMPowerSettingChange)) } return 0 } diff --git a/v3/pkg/application/dialogs.go b/v3/pkg/application/dialogs.go index 2a127a34693..52a034c54e9 100644 --- a/v3/pkg/application/dialogs.go +++ b/v3/pkg/application/dialogs.go @@ -111,7 +111,7 @@ func (d *MessageDialog) Show() { if d.impl == nil { d.impl = newDialogImpl(d) } - invokeSync(d.impl.show) + InvokeSync(d.impl.show) } func (d *MessageDialog) SetIcon(icon []byte) *MessageDialog { @@ -265,7 +265,7 @@ func (d *OpenFileDialogStruct) PromptForSingleSelection() (string, error) { if d.impl == nil { d.impl = newOpenFileDialogImpl(d) } - selection, err := invokeSyncWithResultAndError(d.impl.show) + selection, err := InvokeSyncWithResultAndError(d.impl.show) var result string if len(selection) > 0 { result = selection[0] @@ -289,7 +289,7 @@ func (d *OpenFileDialogStruct) PromptForMultipleSelection() ([]string, error) { if d.impl == nil { d.impl = newOpenFileDialogImpl(d) } - return invokeSyncWithResultAndError(d.impl.show) + return InvokeSyncWithResultAndError(d.impl.show) } func (d *OpenFileDialogStruct) SetMessage(message string) *OpenFileDialogStruct { @@ -448,7 +448,7 @@ func (d *SaveFileDialogStruct) PromptForSingleSelection() (string, error) { if d.impl == nil { d.impl = newSaveFileDialogImpl(d) } - return invokeSyncWithResultAndError(d.impl.show) + return InvokeSyncWithResultAndError(d.impl.show) } func (d *SaveFileDialogStruct) SetButtonText(text string) *SaveFileDialogStruct { diff --git a/v3/pkg/application/events.go b/v3/pkg/application/events.go index dbf6bc9febd..3e815510163 100644 --- a/v3/pkg/application/events.go +++ b/v3/pkg/application/events.go @@ -17,7 +17,7 @@ func (w *Event) Context() *ApplicationEventContext { return w.ctx } -func NewApplicationEvent(id int) *Event { +func newApplicationEvent(id int) *Event { return &Event{ Id: uint(id), ctx: newApplicationEventContext(), @@ -50,7 +50,7 @@ func (e *WailsEvent) Cancel() { e.Cancelled = true } -func (e WailsEvent) ToJSON() string { +func (e WailsEvent) toJSON() string { marshal, err := json.Marshal(&e) if err != nil { // TODO: Fatal error? log? diff --git a/v3/pkg/application/mainthread.go b/v3/pkg/application/mainthread.go index f0ae2803b85..d7b0af371dd 100644 --- a/v3/pkg/application/mainthread.go +++ b/v3/pkg/application/mainthread.go @@ -19,3 +19,57 @@ func generateFunctionStoreID() uint { } } } + +func InvokeSync(fn func()) { + var wg sync.WaitGroup + wg.Add(1) + globalApplication.dispatchOnMainThread(func() { + defer processPanicHandlerRecover() + fn() + wg.Done() + }) + wg.Wait() +} + +func InvokeSyncWithResult[T any](fn func() T) (res T) { + var wg sync.WaitGroup + wg.Add(1) + globalApplication.dispatchOnMainThread(func() { + defer processPanicHandlerRecover() + res = fn() + wg.Done() + }) + wg.Wait() + return res +} + +func InvokeSyncWithError(fn func() error) (err error) { + var wg sync.WaitGroup + wg.Add(1) + globalApplication.dispatchOnMainThread(func() { + defer processPanicHandlerRecover() + err = fn() + wg.Done() + }) + wg.Wait() + return +} + +func InvokeSyncWithResultAndError[T any](fn func() (T, error)) (res T, err error) { + var wg sync.WaitGroup + wg.Add(1) + globalApplication.dispatchOnMainThread(func() { + defer processPanicHandlerRecover() + res, err = fn() + wg.Done() + }) + wg.Wait() + return res, err +} + +func InvokeAsync(fn func()) { + globalApplication.dispatchOnMainThread(func() { + defer processPanicHandlerRecover() + fn() + }) +} diff --git a/v3/pkg/application/menu_windows.go b/v3/pkg/application/menu_windows.go index efa1bd0ee96..a7278d72dd8 100644 --- a/v3/pkg/application/menu_windows.go +++ b/v3/pkg/application/menu_windows.go @@ -82,7 +82,7 @@ func (w *windowsMenu) processMenu(parentMenu w32.HMENU, inputMenu *Menu) { } func (w *windowsMenu) ShowAtCursor() { - invokeSync(func() { + InvokeSync(func() { x, y, ok := w32.GetCursorPos() if !ok { return diff --git a/v3/pkg/application/menuitem_linux.go b/v3/pkg/application/menuitem_linux.go index 575c4b5942f..cce9414bbd7 100644 --- a/v3/pkg/application/menuitem_linux.go +++ b/v3/pkg/application/menuitem_linux.go @@ -14,7 +14,7 @@ type linuxMenuItem struct { } func (l linuxMenuItem) setTooltip(tooltip string) { - invokeSync(func(){ + InvokeSync(func() { l.blockSignal() defer l.unBlockSignal() menuItemSetToolTip(l.native, tooltip) @@ -34,7 +34,7 @@ func (l linuxMenuItem) unBlockSignal() { } func (l linuxMenuItem) setLabel(s string) { - invokeSync(func() { + InvokeSync(func() { l.blockSignal() defer l.unBlockSignal() menuItemSetLabel(l.native, s) @@ -46,7 +46,7 @@ func (l linuxMenuItem) isChecked() bool { } func (l linuxMenuItem) setDisabled(disabled bool) { - invokeSync(func() { + InvokeSync(func() { l.blockSignal() defer l.unBlockSignal() menuItemSetDisabled(l.native, disabled) @@ -54,7 +54,7 @@ func (l linuxMenuItem) setDisabled(disabled bool) { } func (l linuxMenuItem) setChecked(checked bool) { - invokeSync(func() { + InvokeSync(func() { l.blockSignal() defer l.unBlockSignal() menuItemSetChecked(l.native, checked) @@ -62,7 +62,7 @@ func (l linuxMenuItem) setChecked(checked bool) { } func (l linuxMenuItem) setHidden(hidden bool) { - invokeSync(func() { + InvokeSync(func() { l.blockSignal() defer l.unBlockSignal() widgetSetVisible(l.native, hidden) diff --git a/v3/pkg/application/options_application.go b/v3/pkg/application/options_application.go index 4cc3036abb3..4d606c5c894 100644 --- a/v3/pkg/application/options_application.go +++ b/v3/pkg/application/options_application.go @@ -70,7 +70,7 @@ type AssetOptions struct { // Other request: `http.StatusMethodNotAllowed` Handler http.Handler - // Middleware is a HTTP Middleware which allows to hook into the AssetServer request chain. It allows to skip the default + // Middleware is HTTP Middleware which allows to hook into the AssetServer request chain. It allows to skip the default // request handler dynamically, e.g. implement specialized Routing etc. // The Middleware is called to build a new `http.Handler` used by the AssetSever and it also receives the default // handler used by the AssetServer as an argument. @@ -86,7 +86,7 @@ type AssetOptions struct { ExternalURL string } -// Middleware defines a HTTP middleware that can be applied to the AssetServer. +// Middleware defines HTTP middleware that can be applied to the AssetServer. // The handler passed as next is the next handler in the chain. One can decide to call the next handler // or implement a specialized handling. type Middleware func(next http.Handler) http.Handler diff --git a/v3/pkg/application/screen_linux.go b/v3/pkg/application/screen_linux.go index 07b021074ca..36411045486 100644 --- a/v3/pkg/application/screen_linux.go +++ b/v3/pkg/application/screen_linux.go @@ -16,7 +16,7 @@ func (m *linuxApp) getScreens() ([]*Screen, error) { var screens []*Screen var err error wg.Add(1) - invokeSync(func() { + InvokeSync(func() { screens, err = getScreens(m.application) wg.Done() }) diff --git a/v3/pkg/application/systemtray.go b/v3/pkg/application/systemtray.go index 01cfd844233..0dc81836d3a 100644 --- a/v3/pkg/application/systemtray.go +++ b/v3/pkg/application/systemtray.go @@ -65,7 +65,7 @@ type SystemTray struct { attachedWindow WindowAttachConfig } -func NewSystemTray(id uint) *SystemTray { +func newSystemTray(id uint) *SystemTray { result := &SystemTray{ id: id, label: "", @@ -85,7 +85,7 @@ func (s *SystemTray) SetLabel(label string) { s.label = label return } - invokeSync(func() { + InvokeSync(func() { s.impl.setLabel(label) }) } @@ -116,14 +116,14 @@ func (s *SystemTray) run() { }) } - invokeSync(s.impl.run) + InvokeSync(s.impl.run) } func (s *SystemTray) PositionWindow(window *WebviewWindow, offset int) error { if s.impl == nil { return fmt.Errorf("system tray not running") } - return invokeSyncWithError(func() error { + return InvokeSyncWithError(func() error { return s.impl.positionWindow(window, offset) }) } @@ -132,7 +132,7 @@ func (s *SystemTray) SetIcon(icon []byte) *SystemTray { if s.impl == nil { s.icon = icon } else { - invokeSync(func() { + InvokeSync(func() { s.impl.setIcon(icon) }) } @@ -143,7 +143,7 @@ func (s *SystemTray) SetDarkModeIcon(icon []byte) *SystemTray { if s.impl == nil { s.darkModeIcon = icon } else { - invokeSync(func() { + InvokeSync(func() { s.impl.setDarkModeIcon(icon) }) } @@ -154,7 +154,7 @@ func (s *SystemTray) SetMenu(menu *Menu) *SystemTray { if s.impl == nil { s.menu = menu } else { - invokeSync(func() { + InvokeSync(func() { s.impl.setMenu(menu) }) } @@ -165,7 +165,7 @@ func (s *SystemTray) SetIconPosition(iconPosition int) *SystemTray { if s.impl == nil { s.iconPosition = iconPosition } else { - invokeSync(func() { + InvokeSync(func() { s.impl.setIconPosition(iconPosition) }) } @@ -177,7 +177,7 @@ func (s *SystemTray) SetTemplateIcon(icon []byte) *SystemTray { s.icon = icon s.isTemplateIcon = true } else { - invokeSync(func() { + InvokeSync(func() { s.impl.setTemplateIcon(icon) }) } @@ -294,5 +294,5 @@ func (s *SystemTray) OpenMenu() { if s.impl == nil { return } - invokeSync(s.impl.openMenu) + InvokeSync(s.impl.openMenu) } diff --git a/v3/pkg/application/systemtray_linux.go b/v3/pkg/application/systemtray_linux.go index 2f496868e3e..79149e1d7d4 100644 --- a/v3/pkg/application/systemtray_linux.go +++ b/v3/pkg/application/systemtray_linux.go @@ -36,7 +36,7 @@ func (s *linuxSystemTray) bounds() (*Rect, error) { } func (s *linuxSystemTray) run() { - invokeSync(func() { + InvokeSync(func() { // if s.nsStatusItem != nil { // Fatal("System tray '%d' already running", s.id) // } @@ -60,7 +60,7 @@ func (s *linuxSystemTray) run() { func (s *linuxSystemTray) setIcon(icon []byte) { s.icon = icon - invokeSync(func() { + InvokeSync(func() { // s.nsImage = unsafe.Pointer(C.imageFromBytes((*C.uchar)(&icon[0]), C.int(len(icon)))) // C.systemTraySetIcon(s.nsStatusItem, s.nsImage, C.int(s.iconPosition), C.bool(s.isTemplateIcon)) }) @@ -68,7 +68,7 @@ func (s *linuxSystemTray) setIcon(icon []byte) { func (s *linuxSystemTray) setDarkModeIcon(icon []byte) { s.icon = icon - invokeSync(func() { + InvokeSync(func() { // s.nsImage = unsafe.Pointer(C.imageFromBytes((*C.uchar)(&icon[0]), C.int(len(icon)))) // C.systemTraySetIcon(s.nsStatusItem, s.nsImage, C.int(s.iconPosition), C.bool(s.isTemplateIcon)) }) diff --git a/v3/pkg/application/webview_window.go b/v3/pkg/application/webview_window.go index 0ba7e26877c..7af9e3222c5 100644 --- a/v3/pkg/application/webview_window.go +++ b/v3/pkg/application/webview_window.go @@ -156,8 +156,8 @@ func (w *WebviewWindow) setupEventMapping() { } } -// NewWindow creates a new window with the given options -func NewWindow(options WebviewWindowOptions) *WebviewWindow { +// newWindow creates a new window with the given options +func newWindow(options WebviewWindowOptions) *WebviewWindow { if options.Width == 0 { options.Width = 800 } @@ -186,7 +186,7 @@ func NewWindow(options WebviewWindowOptions) *WebviewWindow { } if shouldClose { globalApplication.deleteWindowByID(result.id) - invokeSync(result.impl.close) + InvokeSync(result.impl.close) } }) @@ -223,7 +223,7 @@ func (w *WebviewWindow) addCancellationFunction(canceller func()) { func (w *WebviewWindow) SetTitle(title string) *WebviewWindow { w.options.Title = title if w.impl != nil { - invokeSync(func() { + InvokeSync(func() { w.impl.setTitle(title) }) } @@ -271,7 +271,7 @@ func (w *WebviewWindow) SetSize(width, height int) *WebviewWindow { } if w.impl != nil { - invokeSync(func() { + InvokeSync(func() { w.impl.setSize(width, height) }) } @@ -283,14 +283,14 @@ func (w *WebviewWindow) run() { return } w.impl = newWindowImpl(w) - invokeSync(w.impl.run) + InvokeSync(w.impl.run) } // SetAlwaysOnTop sets the window to be always on top. func (w *WebviewWindow) SetAlwaysOnTop(b bool) *WebviewWindow { w.options.AlwaysOnTop = b if w.impl != nil { - invokeSync(func() { + InvokeSync(func() { w.impl.setAlwaysOnTop(b) }) } @@ -303,10 +303,10 @@ func (w *WebviewWindow) Show() *WebviewWindow { return w } if w.impl == nil { - invokeSync(w.run) + InvokeSync(w.run) return w } - invokeSync(w.impl.show) + InvokeSync(w.impl.show) w.emit(events.Common.WindowShow) return w } @@ -315,7 +315,7 @@ func (w *WebviewWindow) Show() *WebviewWindow { func (w *WebviewWindow) Hide() *WebviewWindow { w.options.Hidden = true if w.impl != nil { - invokeSync(w.impl.hide) + InvokeSync(w.impl.hide) w.emit(events.Common.WindowHide) } return w @@ -324,7 +324,7 @@ func (w *WebviewWindow) Hide() *WebviewWindow { func (w *WebviewWindow) SetURL(s string) *WebviewWindow { w.options.URL = s if w.impl != nil { - invokeSync(func() { + InvokeSync(func() { w.impl.setURL(s) }) } @@ -335,7 +335,7 @@ func (w *WebviewWindow) SetURL(s string) *WebviewWindow { func (w *WebviewWindow) SetZoom(magnification float64) *WebviewWindow { w.options.Zoom = magnification if w.impl != nil { - invokeSync(func() { + InvokeSync(func() { w.impl.setZoom(magnification) }) } @@ -345,7 +345,7 @@ func (w *WebviewWindow) SetZoom(magnification float64) *WebviewWindow { // GetZoom returns the current zoom level of the window. func (w *WebviewWindow) GetZoom() float64 { if w.impl != nil { - return invokeSyncWithResult(w.impl.getZoom) + return InvokeSyncWithResult(w.impl.getZoom) } return 1 } @@ -354,7 +354,7 @@ func (w *WebviewWindow) GetZoom() float64 { func (w *WebviewWindow) SetResizable(b bool) *WebviewWindow { w.options.DisableResize = !b if w.impl != nil { - invokeSync(func() { + InvokeSync(func() { w.impl.setResizable(b) }) } @@ -387,11 +387,11 @@ func (w *WebviewWindow) SetMinSize(minWidth, minHeight int) *WebviewWindow { } if w.impl != nil { if newSize { - invokeSync(func() { + InvokeSync(func() { w.impl.setSize(newWidth, newHeight) }) } - invokeSync(func() { + InvokeSync(func() { w.impl.setMinSize(minWidth, minHeight) }) } @@ -419,11 +419,11 @@ func (w *WebviewWindow) SetMaxSize(maxWidth, maxHeight int) *WebviewWindow { } if w.impl != nil { if newSize { - invokeSync(func() { + InvokeSync(func() { w.impl.setSize(newWidth, newHeight) }) } - invokeSync(func() { + InvokeSync(func() { w.impl.setMaxSize(maxWidth, maxHeight) }) } @@ -446,7 +446,7 @@ func (w *WebviewWindow) Fullscreen() *WebviewWindow { } if !w.IsFullscreen() { w.disableSizeConstraints() - invokeSync(w.impl.fullscreen) + InvokeSync(w.impl.fullscreen) } return w } @@ -454,7 +454,7 @@ func (w *WebviewWindow) Fullscreen() *WebviewWindow { func (w *WebviewWindow) SetFullscreenButtonEnabled(enabled bool) *WebviewWindow { w.options.FullscreenButtonEnabled = enabled if w.impl != nil { - invokeSync(func() { + InvokeSync(func() { w.impl.setFullscreenButtonEnabled(enabled) }) } @@ -466,7 +466,7 @@ func (w *WebviewWindow) Flash(enabled bool) { if w.impl == nil { return } - invokeSync(func() { + InvokeSync(func() { w.impl.flash(enabled) }) } @@ -476,7 +476,7 @@ func (w *WebviewWindow) IsMinimised() bool { if w.impl == nil { return false } - return invokeSyncWithResult(w.impl.isMinimised) + return InvokeSyncWithResult(w.impl.isMinimised) } // IsVisible returns true if the window is visible @@ -484,7 +484,7 @@ func (w *WebviewWindow) IsVisible() bool { if w.impl == nil { return false } - return invokeSyncWithResult(w.impl.isVisible) + return InvokeSyncWithResult(w.impl.isVisible) } // IsMaximised returns true if the window is maximised @@ -492,7 +492,7 @@ func (w *WebviewWindow) IsMaximised() bool { if w.impl == nil { return false } - return invokeSyncWithResult(w.impl.isMaximised) + return InvokeSyncWithResult(w.impl.isMaximised) } // Size returns the size of the window @@ -501,7 +501,7 @@ func (w *WebviewWindow) Size() (int, int) { return 0, 0 } var width, height int - invokeSync(func() { + InvokeSync(func() { width, height = w.impl.size() }) return width, height @@ -512,7 +512,7 @@ func (w *WebviewWindow) IsFocused() bool { if w.impl == nil { return false } - return invokeSyncWithResult(w.impl.isFocused) + return InvokeSyncWithResult(w.impl.isFocused) } // IsFullscreen returns true if the window is fullscreen @@ -520,14 +520,14 @@ func (w *WebviewWindow) IsFullscreen() bool { if w.impl == nil { return false } - return invokeSyncWithResult(w.impl.isFullscreen) + return InvokeSyncWithResult(w.impl.isFullscreen) } // SetBackgroundColour sets the background colour of the window func (w *WebviewWindow) SetBackgroundColour(colour RGBA) *WebviewWindow { w.options.BackgroundColour = colour if w.impl != nil { - invokeSync(func() { + InvokeSync(func() { w.impl.setBackgroundColour(colour) }) } @@ -538,7 +538,7 @@ func (w *WebviewWindow) handleMessage(message string) { // Check for special messages if message == "drag" { if !w.IsFullscreen() { - invokeSync(func() { + InvokeSync(func() { err := w.startDrag() if err != nil { w.error("Failed to start drag: %s", err) @@ -571,7 +571,7 @@ func (w *WebviewWindow) startResize(border string) error { if w.impl == nil { return nil } - return invokeSyncWithResult(func() error { + return InvokeSyncWithResult(func() error { return w.impl.startResize(border) }) } @@ -582,7 +582,7 @@ func (w *WebviewWindow) Center() { w.options.Centered = true return } - invokeSync(w.impl.center) + InvokeSync(w.impl.center) } // On registers a callback for the given window event @@ -652,7 +652,7 @@ func (w *WebviewWindow) Width() int { if w.impl == nil { return 0 } - return invokeSyncWithResult(w.impl.width) + return InvokeSyncWithResult(w.impl.width) } // Height returns the height of the window @@ -660,7 +660,7 @@ func (w *WebviewWindow) Height() int { if w.impl == nil { return 0 } - return invokeSyncWithResult(w.impl.height) + return InvokeSyncWithResult(w.impl.height) } // RelativePosition returns the relative position of the window to the screen @@ -669,7 +669,7 @@ func (w *WebviewWindow) RelativePosition() (int, int) { return 0, 0 } var x, y int - invokeSync(func() { + InvokeSync(func() { x, y = w.impl.relativePosition() }) return x, y @@ -681,7 +681,7 @@ func (w *WebviewWindow) AbsolutePosition() (int, int) { return 0, 0 } var x, y int - invokeSync(func() { + InvokeSync(func() { x, y = w.impl.absolutePosition() }) return x, y @@ -697,7 +697,7 @@ func (w *WebviewWindow) Destroy() { cancelFunc() } - invokeSync(w.impl.destroy) + InvokeSync(w.impl.destroy) } // Reload reloads the page assets @@ -705,7 +705,7 @@ func (w *WebviewWindow) Reload() { if w.impl == nil { return } - invokeSync(w.impl.reload) + InvokeSync(w.impl.reload) } // ForceReload forces the window to reload the page assets @@ -713,7 +713,7 @@ func (w *WebviewWindow) ForceReload() { if w.impl == nil { return } - invokeSync(w.impl.forceReload) + InvokeSync(w.impl.forceReload) } // ToggleFullscreen toggles the window between fullscreen and normal @@ -721,7 +721,7 @@ func (w *WebviewWindow) ToggleFullscreen() { if w.impl == nil { return } - invokeSync(func() { + InvokeSync(func() { if w.IsFullscreen() { w.UnFullscreen() } else { @@ -734,13 +734,13 @@ func (w *WebviewWindow) ToggleDevTools() { if w.impl == nil { return } - invokeSync(w.impl.toggleDevTools) + InvokeSync(w.impl.toggleDevTools) } // ZoomReset resets the zoom level of the webview content to 100% func (w *WebviewWindow) ZoomReset() *WebviewWindow { if w.impl != nil { - invokeSync(w.impl.zoomReset) + InvokeSync(w.impl.zoomReset) w.emit(events.Common.WindowZoomReset) } return w @@ -752,7 +752,7 @@ func (w *WebviewWindow) ZoomIn() { if w.impl == nil { return } - invokeSync(w.impl.zoomIn) + InvokeSync(w.impl.zoomIn) w.emit(events.Common.WindowZoomIn) } @@ -762,7 +762,7 @@ func (w *WebviewWindow) ZoomOut() { if w.impl == nil { return } - invokeSync(w.impl.zoomOut) + InvokeSync(w.impl.zoomOut) w.emit(events.Common.WindowZoomOut) } @@ -778,7 +778,7 @@ func (w *WebviewWindow) Zoom() { if w.impl == nil { return } - invokeSync(w.impl.zoom) + InvokeSync(w.impl.zoom) w.emit(events.Common.WindowZoom) } @@ -786,7 +786,7 @@ func (w *WebviewWindow) Zoom() { func (w *WebviewWindow) SetHTML(html string) *WebviewWindow { w.options.HTML = html if w.impl != nil { - invokeSync(func() { + InvokeSync(func() { w.impl.setHTML(html) }) } @@ -798,7 +798,7 @@ func (w *WebviewWindow) SetRelativePosition(x, y int) *WebviewWindow { w.options.X = x w.options.Y = y if w.impl != nil { - invokeSync(func() { + InvokeSync(func() { w.impl.setRelativePosition(x, y) }) } @@ -812,7 +812,7 @@ func (w *WebviewWindow) Minimise() *WebviewWindow { return w } if !w.IsMinimised() { - invokeSync(w.impl.minimise) + InvokeSync(w.impl.minimise) w.emit(events.Common.WindowMinimise) } return w @@ -826,7 +826,7 @@ func (w *WebviewWindow) Maximise() *WebviewWindow { } if !w.IsMaximised() { w.disableSizeConstraints() - invokeSync(w.impl.maximise) + InvokeSync(w.impl.maximise) w.emit(events.Common.WindowMaximise) } return w @@ -838,7 +838,7 @@ func (w *WebviewWindow) UnMinimise() { return } if w.IsMinimised() { - invokeSync(w.impl.unminimise) + InvokeSync(w.impl.unminimise) w.emit(events.Common.WindowUnMinimise) } } @@ -850,7 +850,7 @@ func (w *WebviewWindow) UnMaximise() { } if w.IsMaximised() { w.enableSizeConstraints() - invokeSync(w.impl.unmaximise) + InvokeSync(w.impl.unmaximise) w.emit(events.Common.WindowUnMaximise) } } @@ -862,7 +862,7 @@ func (w *WebviewWindow) UnFullscreen() { } if w.IsFullscreen() { w.enableSizeConstraints() - invokeSync(w.impl.unfullscreen) + InvokeSync(w.impl.unfullscreen) w.emit(events.Common.WindowUnFullscreen) } } @@ -872,7 +872,7 @@ func (w *WebviewWindow) Restore() { if w.impl == nil { return } - invokeSync(func() { + InvokeSync(func() { if w.IsMinimised() { w.UnMinimise() } else if w.IsMaximised() { @@ -888,7 +888,7 @@ func (w *WebviewWindow) disableSizeConstraints() { if w.impl == nil { return } - invokeSync(func() { + InvokeSync(func() { if w.options.MinWidth > 0 && w.options.MinHeight > 0 { w.impl.setMinSize(0, 0) } @@ -902,7 +902,7 @@ func (w *WebviewWindow) enableSizeConstraints() { if w.impl == nil { return } - invokeSync(func() { + InvokeSync(func() { if w.options.MinWidth > 0 && w.options.MinHeight > 0 { w.SetMinSize(w.options.MinWidth, w.options.MinHeight) } @@ -917,14 +917,14 @@ func (w *WebviewWindow) GetScreen() (*Screen, error) { if w.impl == nil { return nil, nil } - return invokeSyncWithResultAndError(w.impl.getScreen) + return InvokeSyncWithResultAndError(w.impl.getScreen) } // SetFrameless removes the window frame and title bar func (w *WebviewWindow) SetFrameless(frameless bool) *WebviewWindow { w.options.Frameless = frameless if w.impl != nil { - invokeSync(func() { + InvokeSync(func() { w.impl.setFrameless(frameless) }) } @@ -932,7 +932,7 @@ func (w *WebviewWindow) SetFrameless(frameless bool) *WebviewWindow { } func (w *WebviewWindow) dispatchWailsEvent(event *WailsEvent) { - msg := fmt.Sprintf("_wails.dispatchWailsEvent(%s);", event.ToJSON()) + msg := fmt.Sprintf("_wails.dispatchWailsEvent(%s);", event.toJSON()) w.ExecJS(msg) } @@ -1006,7 +1006,7 @@ func (w *WebviewWindow) Focus() { w.options.Focused = true return } - invokeSync(w.impl.focus) + InvokeSync(w.impl.focus) w.emit(events.Common.WindowFocus) } @@ -1021,21 +1021,21 @@ func (w *WebviewWindow) startDrag() error { if w.impl == nil { return nil } - return invokeSyncWithError(w.impl.startDrag) + return InvokeSyncWithError(w.impl.startDrag) } func (w *WebviewWindow) Print() error { if w.impl == nil { return nil } - return invokeSyncWithError(w.impl.print) + return InvokeSyncWithError(w.impl.print) } func (w *WebviewWindow) SetEnabled(enabled bool) { if w.impl == nil { return } - invokeSync(func() { + InvokeSync(func() { w.impl.setEnabled(enabled) }) } @@ -1045,7 +1045,7 @@ func (w *WebviewWindow) SetAbsolutePosition(x int, y int) { if w.impl == nil { return } - invokeSync(func() { + InvokeSync(func() { w.impl.setAbsolutePosition(x, y) }) } @@ -1071,7 +1071,7 @@ func (w *WebviewWindow) handleKeyEvent(acceleratorString string) { if w.impl == nil { return } - invokeSync(func() { + InvokeSync(func() { w.impl.handleKeyEvent(acceleratorString) }) } diff --git a/v3/pkg/application/webview_window_darwin.go b/v3/pkg/application/webview_window_darwin.go index 7d481281c2d..39657b755b2 100644 --- a/v3/pkg/application/webview_window_darwin.go +++ b/v3/pkg/application/webview_window_darwin.go @@ -1146,7 +1146,7 @@ func (w *macosWebviewWindow) setBackgroundColour(colour RGBA) { func (w *macosWebviewWindow) relativePosition() (int, int) { var x, y C.int - invokeSync(func() { + InvokeSync(func() { C.windowGetRelativePosition(w.nsWindow, &x, &y) }) @@ -1155,7 +1155,7 @@ func (w *macosWebviewWindow) relativePosition() (int, int) { func (w *macosWebviewWindow) absolutePosition() (int, int) { var x, y C.int - invokeSync(func() { + InvokeSync(func() { C.windowGetAbsolutePosition(w.nsWindow, &x, &y) }) diff --git a/v3/pkg/application/webview_window_windows.go b/v3/pkg/application/webview_window_windows.go index a24eab69862..1c6c4351a87 100644 --- a/v3/pkg/application/webview_window_windows.go +++ b/v3/pkg/application/webview_window_windows.go @@ -967,7 +967,7 @@ func (w *windowsWebviewWindow) WndProc(msg uint32, wparam, lparam uintptr) uintp // depends on the content in the WebView, see https://github.com/wailsapp/wails/issues/1319 } else if w.resizeDebouncer != nil { w.resizeDebouncer(func() { - invokeSync(func() { + InvokeSync(func() { w.chromium.Resize() }) })