diff --git a/v2/internal/appng/app_dev.go b/v2/internal/appng/app_dev.go index cf1bcdef7..7069ccaa2 100644 --- a/v2/internal/appng/app_dev.go +++ b/v2/internal/appng/app_dev.go @@ -129,6 +129,7 @@ func CreateApp(appoptions *options.App) (*App, error) { // Attach logger to context ctx = context.WithValue(ctx, "logger", myLogger) + ctx = context.WithValue(ctx, "buildtype", "dev") // Preflight checks err = PreflightChecks(appoptions, myLogger) diff --git a/v2/internal/appng/app_production.go b/v2/internal/appng/app_production.go index 4161d2405..8cd4f59f7 100644 --- a/v2/internal/appng/app_production.go +++ b/v2/internal/appng/app_production.go @@ -82,6 +82,11 @@ func CreateApp(appoptions *options.App) (*App, error) { ctx = context.WithValue(ctx, "debug", debug) // Attach logger to context ctx = context.WithValue(ctx, "logger", myLogger) + if debug { + ctx = context.WithValue(ctx, "buildtype", "debug") + } else { + ctx = context.WithValue(ctx, "buildtype", "production") + } appFrontend := desktop.NewFrontend(ctx, appoptions, myLogger, appBindings, messageDispatcher) eventHandler.AddFrontend(appFrontend) diff --git a/v2/pkg/runtime/runtime.go b/v2/pkg/runtime/runtime.go index b10dc436d..18097e29b 100644 --- a/v2/pkg/runtime/runtime.go +++ b/v2/pkg/runtime/runtime.go @@ -66,3 +66,16 @@ func Quit(ctx context.Context) { appFrontend := getFrontend(ctx) appFrontend.Quit() } + +type EnvironmentInfo struct { + BuildType string `json:"buildtype"` +} + +func Environment(ctx context.Context) EnvironmentInfo { + var result EnvironmentInfo + buildType := ctx.Value("buildtype") + if buildType != nil { + result.BuildType = buildType.(string) + } + return result +} diff --git a/website/docs/reference/runtime/intro.mdx b/website/docs/reference/runtime/intro.mdx index acf77a678..c47f0ed8d 100644 --- a/website/docs/reference/runtime/intro.mdx +++ b/website/docs/reference/runtime/intro.mdx @@ -24,3 +24,24 @@ The Javascript library is available to the frontend via the `window.runtime` map mode that provides Typescript declarations for the runtime. This should be located in the `wailsjs` directory in your frontend directory. +### Quit + +Go Signature: `LogPrint(ctx context.Context, message string)` + +Quits the application. + +### Environment + +Go Signature: `Enviromnent() EnvironmentInfo` + +Returns details of the current environment. + +#### EnvironmentInfo + +```go +type EnvironmentInfo struct { + BuildType string // Either "production", "debug" or "dev" +} +``` + +