Files

152 lines
2.9 KiB
Markdown
Raw Permalink Normal View History

2023-09-24 08:57:22 +10:00
# Application
2023-11-05 18:06:11 +11:00
The application API assists in creating an application using the Wails
framework.
2023-09-24 08:57:22 +10:00
### New
API: `New(appOptions Options) *App`
2023-09-25 20:56:29 +10:00
`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.
2023-09-24 08:57:22 +10:00
2023-09-25 20:56:29 +10:00
In case of an error during initialization, the application is stopped with the
error message provided.
2023-09-24 08:57:22 +10:00
2023-09-25 20:56:29 +10:00
It should be noted that if a global application instance already exists, that
instance will be returned instead of creating a new one.
2023-09-24 17:03:42 +10:00
```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
})
2023-09-25 20:56:29 +10:00
2023-09-24 17:03:42 +10:00
// Rest of application
}
```
2023-09-24 08:57:22 +10:00
### Get
2023-09-25 20:56:29 +10:00
`Get()` returns the global application instance. It's useful when you need to
access the application from different parts of your code.
2023-09-24 08:57:22 +10:00
2023-09-24 17:03:42 +10:00
```go
// Get the application instance
app := application.Get()
```
2023-09-24 08:57:22 +10:00
### Capabilities
API: `Capabilities() capabilities.Capabilities`
2023-09-25 20:56:29 +10:00
`Capabilities()` retrieves a map of capabilities that the application currently
has. Capabilities can be about different features the operating system provides,
like webview features.
2023-09-24 08:57:22 +10:00
2023-09-24 17:03:42 +10:00
```go
// Get the application capabilities
capabilities := app.Capabilities()
if capabilities.HasNativeDrag {
// Do something
2023-09-25 20:56:29 +10:00
}
2023-09-24 17:03:42 +10:00
```
2023-09-24 08:57:22 +10:00
### GetPID
API: `GetPID() int`
`GetPID()` returns the Process ID of the application.
2023-09-24 17:03:42 +10:00
```go
pid := app.GetPID()
```
2023-09-24 08:57:22 +10:00
### Run
API: `Run() error`
`Run()` starts the execution of the application and its components.
2023-09-24 17:03:42 +10:00
```go
2023-09-25 20:56:29 +10:00
app := application.New(application.Options{
//options
2023-09-24 17:03:42 +10:00
})
// Run the application
err := application.Run()
if err != nil {
// Handle error
2023-09-25 20:56:29 +10:00
}
2023-09-24 17:03:42 +10:00
```
2023-09-24 08:57:22 +10:00
### Quit
API: `Quit()`
2023-09-25 20:56:29 +10:00
`Quit()` quits the application by destroying windows and potentially other
components.
2023-09-24 08:57:22 +10:00
2023-09-24 17:03:42 +10:00
```go
// Quit the application
app.Quit()
```
2023-09-24 08:57:22 +10:00
### IsDarkMode
API: `IsDarkMode() bool`
2023-09-25 20:56:29 +10:00
`IsDarkMode()` checks if the application is running in dark mode. It returns a
boolean indicating whether dark mode is enabled.
2023-09-24 08:57:22 +10:00
2023-09-24 17:03:42 +10:00
```go
// Check if dark mode is enabled
if app.IsDarkMode() {
// Do something
}
```
2023-09-24 08:57:22 +10:00
### Hide
API: `Hide()`
`Hide()` hides the application window.
2023-09-24 17:03:42 +10:00
```go
// Hide the application window
app.Hide()
```
2023-09-24 08:57:22 +10:00
### Show
API: `Show()`
`Show()` shows the application window.
2023-09-24 17:03:42 +10:00
```go
// Show the application window
app.Show()
```
2024-03-18 20:47:33 +11:00
--8<--
./docs/en/API/application_window.md
./docs/en/API/application_menu.md
./docs/en/API/application_dialogs.md
./docs/en/API/application_events.md
./docs/en/API/application_screens.md
--8<--
2023-09-24 08:57:22 +10:00
## Options
2024-03-18 20:47:33 +11:00
```go title="pkg/application/application_options.go"
2023-09-24 17:03:42 +10:00
--8<--
2024-03-18 20:47:33 +11:00
../v3/pkg/application/application_options.go
2023-09-24 17:23:24 +10:00
--8<--
2023-09-25 20:56:29 +10:00
```