
* Added appData * Updated changelog * Updated doc and added error handling and fallbacks * Updated doc * Expose XDG methods * Refactor Path method. Add Paths method * Fix changelog --------- Co-authored-by: Anshuman <anshuman@instasafe.com> Co-authored-by: Lea Anthony <lea.anthony@gmail.com>
5.2 KiB
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.
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.
// 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.
// Get the application capabilities
capabilities := app.Capabilities()
if capabilities.HasNativeDrag {
// Do something
}
GetPID
API: GetPID() int
GetPID()
returns the Process ID of the application.
pid := app.GetPID()
Run
API: Run() error
Run()
starts the execution of the application and its components.
app := application.New(application.Options{
//options
})
// Run the application
err := application.Run()
if err != nil {
// Handle error
}
Quit
API: Quit()
Quit()
quits the application by destroying windows and potentially other
components.
// 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.
// Check if dark mode is enabled
if app.IsDarkMode() {
// Do something
}
Hide
API: Hide()
Hide()
hides the application window.
// Hide the application window
app.Hide()
Show
API: Show()
Show()
shows the application window.
// Show the application window
app.Show()
Path
API: Path(selector Path) string
Path(selector Path)
returns the full path for the given path type. It provides a cross-platform way to query common application directories.
The Path
type is an enum with the following values:
PathHome
: Returns the user's home directoryPathDataHome
: Returns the path to the user's data directoryPathConfigHome
: Returns the path to the user's configuration directoryPathStateHome
: Returns the path to the user's state directoryPathCacheHome
: Returns the path to the user's cache directoryPathRuntimeDir
: Returns the path to the user's runtime directoryPathDesktop
: Returns the path to the user's desktop directoryPathDownload
: Returns the path to the user's download directoryPathDocuments
: Returns the path to the user's documents directoryPathMusic
: Returns the path to the user's music directoryPathPictures
: Returns the path to the user's pictures directoryPathVideos
: Returns the path to the user's videos directoryPathTemplates
: Returns the path to the user's templates directoryPathPublicShare
: Returns the path to the user's public share directory
// Get the data home directory path
dataHomePath := app.Path(application.PathDataHome)
fmt.Println("DataHome path:", dataHomePath)
// Output: DataHome path: /home/username/.local/share // Linux
// Output: DataHome path: /Users/username/Library/Application Support // macOS
// Output: DataHome path: C:\Users\Username\AppData\Roaming // Windows
// Get the CacheHome directory path
cacheHomePath := app.Path(application.CacheHome)
fmt.Println("CacheHome path:", cacheHomePath)
// Output: CacheHome path: /home/username/.cache // Linux
// Output: CacheHome path: /Users/username/Library/Caches // macOS
// Output: CacheHome path: C:\Users\Username\AppData\Local\Temp // Windows
Paths
API: Paths(selector Paths) []string
Paths(selector Path)
returns a list of paths for the given path type. It provides a cross-platform way to query common directory paths.
The Paths
type is an enum with the following values:
PathsDataDirs
: Returns the list of data directoriesPathsConfigDirs
: Returns the list of configuration directoriesPathsCacheDirs
: Returns the list of cache directoriesPathsRuntimeDirs
: Returns the list of runtime directories
--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<--
Options
--8<--
../v3/pkg/application/application_options.go
--8<--