5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-02 20:03:01 +08:00

Add GetEnvironment() - Fixes #1126

This commit is contained in:
Lea Anthony 2022-02-04 07:52:45 +11:00
parent 0c6864c7ed
commit 082af614ff
4 changed files with 40 additions and 0 deletions

View File

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

View File

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

View File

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

View File

@ -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"
}
```