-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0526213
commit 7cdab16
Showing
24 changed files
with
657 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
Oops, something went wrong.