5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-04 19:21:21 +08:00
wails/mkdocs-website/docs/en/API/application.md
2024-03-18 20:47:33 +11:00

2.9 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()

--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<--