mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-06 17:01:33 +08:00
Add some more API docs.
This commit is contained in:
parent
7cdab16ba9
commit
31c167b412
@ -12,28 +12,71 @@ In case of an error during initialization, the application is stopped with the e
|
||||
|
||||
It should be noted that if a global application instance already exists, that instance will be returned instead of creating a new one.
|
||||
|
||||
|
||||
```go title="main.go" hl_lines="6-9"
|
||||
package main
|
||||
|
||||
import "github.com/wailsapp/wails/v3/pkg/application"
|
||||
|
||||
func main() {
|
||||
app := application.New(application.Options{
|
||||
Name: "WebviewWindow Demo",
|
||||
// Other options
|
||||
})
|
||||
|
||||
// Rest of application
|
||||
}
|
||||
```
|
||||
|
||||
### Get
|
||||
|
||||
`Get()` returns the global application instance. It's useful when you need to access the application from different parts of your code.
|
||||
|
||||
```go
|
||||
// Get the application instance
|
||||
app := application.Get()
|
||||
```
|
||||
|
||||
### 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.
|
||||
|
||||
```go
|
||||
// Get the application capabilities
|
||||
capabilities := app.Capabilities()
|
||||
if capabilities.HasNativeDrag {
|
||||
// Do something
|
||||
}
|
||||
```
|
||||
|
||||
### GetPID
|
||||
|
||||
API: `GetPID() int`
|
||||
|
||||
`GetPID()` returns the Process ID of the application.
|
||||
|
||||
```go
|
||||
pid := app.GetPID()
|
||||
```
|
||||
|
||||
### Run
|
||||
|
||||
API: `Run() error`
|
||||
|
||||
`Run()` starts the execution of the application and its components.
|
||||
|
||||
```go
|
||||
app := application.New(application.Options{
|
||||
//options
|
||||
})
|
||||
// Run the application
|
||||
err := application.Run()
|
||||
if err != nil {
|
||||
// Handle error
|
||||
}
|
||||
```
|
||||
|
||||
### Quit
|
||||
|
||||
@ -41,54 +84,107 @@ API: `Quit()`
|
||||
|
||||
`Quit()` quits the application by destroying windows and potentially other components.
|
||||
|
||||
```go
|
||||
// Quit the application
|
||||
app.Quit()
|
||||
```
|
||||
|
||||
### IsDarkMode
|
||||
|
||||
API: `IsDarkMode() bool`
|
||||
|
||||
`IsDarkMode()` checks if the application is running in dark mode. It returns a boolean indicating whether dark mode is enabled.
|
||||
|
||||
```go
|
||||
// Check if dark mode is enabled
|
||||
if app.IsDarkMode() {
|
||||
// Do something
|
||||
}
|
||||
```
|
||||
|
||||
### Hide
|
||||
|
||||
API: `Hide()`
|
||||
|
||||
`Hide()` hides the application window.
|
||||
|
||||
```go
|
||||
// Hide the application window
|
||||
app.Hide()
|
||||
```
|
||||
|
||||
### Show
|
||||
|
||||
API: `Show()`
|
||||
|
||||
`Show()` shows the application window.
|
||||
|
||||
```go
|
||||
// Show the application window
|
||||
app.Show()
|
||||
```
|
||||
|
||||
### NewWebviewWindow
|
||||
|
||||
API: `NewWebviewWindow() *WebviewWindow`
|
||||
|
||||
`NewWebviewWindow()` creates a new Webview window with default options, and returns it.
|
||||
|
||||
```go
|
||||
// Create a new webview window
|
||||
window := app.NewWebviewWindow()
|
||||
```
|
||||
|
||||
### 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.
|
||||
|
||||
```go
|
||||
// Create a new webview window with custom options
|
||||
window := app.NewWebviewWindowWithOptions(WebviewWindowOptions{
|
||||
Name: "Main",
|
||||
Title: "My Window",
|
||||
Width: 800,
|
||||
Height: 600,
|
||||
})
|
||||
```
|
||||
|
||||
### OnWindowCreation
|
||||
|
||||
API: `OnWindowCreation(callback func(window *WebviewWindow))`
|
||||
|
||||
`OnWindowCreation()` registers a callback function to be called when a window is created.
|
||||
|
||||
```go
|
||||
// Register a callback to be called when a window is created
|
||||
app.OnWindowCreation(func(window *WebviewWindow) {
|
||||
// Do something
|
||||
})
|
||||
```
|
||||
|
||||
### GetWindowByName
|
||||
|
||||
API: `GetWindowByName(name string) *WebviewWindow`
|
||||
|
||||
`GetWindowByName()` fetches and returns a window with a specific name.
|
||||
|
||||
```go
|
||||
// Get a window by name
|
||||
window := app.GetWindowByName("Main")
|
||||
```
|
||||
|
||||
### 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.
|
||||
|
||||
```go
|
||||
// Get the current window
|
||||
window := app.CurrentWindow()
|
||||
```
|
||||
|
||||
### NewSystemTray
|
||||
|
||||
@ -96,6 +192,10 @@ API: `NewSystemTray() *SystemTray`
|
||||
|
||||
`NewSystemTray()` creates and returns a new system tray instance.
|
||||
|
||||
```go
|
||||
// Create a new system tray
|
||||
tray := app.NewSystemTray()
|
||||
```
|
||||
|
||||
|
||||
### NewMenu
|
||||
@ -104,7 +204,10 @@ API: `NewMenu() *Menu`
|
||||
|
||||
This method, belonging to App struct and not Menu struct, also initialises and returns a new `Menu`.
|
||||
|
||||
|
||||
```go
|
||||
// Create a new menu
|
||||
menu := app.NewMenu()
|
||||
```
|
||||
|
||||
### RegisterContextMenu
|
||||
|
||||
@ -112,11 +215,28 @@ API: `RegisterContextMenu(name string, menu *Menu)`
|
||||
|
||||
`RegisterContextMenu()` registers a context menu with a given name. This menu can be used later in the application.
|
||||
|
||||
```go
|
||||
|
||||
// Create a new menu
|
||||
ctxmenu := app.NewMenu()
|
||||
|
||||
// Register the menu as a context menu
|
||||
app.RegisterContextMenu("MyContextMenu", ctxmenu)
|
||||
```
|
||||
|
||||
### SetMenu
|
||||
|
||||
API: `SetMenu(menu *Menu)`
|
||||
|
||||
`SetMenu()` sets the menu for the application.
|
||||
`SetMenu()` sets the menu for the application. On Mac, this will be the global menu. For Windows and Linux, this will be the default menu for any new window created.
|
||||
|
||||
```go
|
||||
// Create a new menu
|
||||
menu := app.NewMenu()
|
||||
|
||||
// Set the menu for the application
|
||||
app.SetMenu(menu)
|
||||
```
|
||||
|
||||
### ShowAboutDialog
|
||||
|
||||
@ -124,6 +244,11 @@ API: `ShowAboutDialog()`
|
||||
|
||||
`ShowAboutDialog()` shows an "About" dialog box. It can show the application's name, description and icon.
|
||||
|
||||
```go
|
||||
// Show the about dialog
|
||||
app.ShowAboutDialog()
|
||||
```
|
||||
|
||||
### 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.
|
||||
@ -132,6 +257,7 @@ API: `ShowAboutDialog()`
|
||||
|
||||
`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.
|
||||
@ -181,4 +307,8 @@ This is a brief summary of the exported methods in the provided `App` struct. Do
|
||||
|
||||
## Options
|
||||
|
||||
--8<-- "../../../v3/pkg/application/options_application.go"
|
||||
```go title="application_options.go"
|
||||
--8<--
|
||||
../v3/pkg/application/options_application.go
|
||||
--8<--
|
||||
```
|
@ -106,7 +106,8 @@ markdown_extensions:
|
||||
- pymdownx.tasklist:
|
||||
custom_checkbox: true
|
||||
- pymdownx.inlinehilite
|
||||
- pymdownx.snippets
|
||||
- pymdownx.snippets:
|
||||
restrict_base_path: false
|
||||
- pymdownx.details
|
||||
- pymdownx.superfences
|
||||
- pymdownx.mark
|
||||
|
Loading…
Reference in New Issue
Block a user