diff --git a/v2/internal/app/app_dev.go b/v2/internal/app/app_dev.go index 6de845f96..8b1aee212 100644 --- a/v2/internal/app/app_dev.go +++ b/v2/internal/app/app_dev.go @@ -45,6 +45,7 @@ func CreateApp(appoptions *options.App) (*App, error) { ctx := context.Background() ctx = context.WithValue(ctx, "debug", true) ctx = context.WithValue(ctx, "devtoolsEnabled", true) + ctx = injectProductInfo(ctx) // Set up logger if the appoptions.LogLevel is an invalid value, set it to the default log level appoptions.LogLevel, err = pkglogger.StringToLogLevel(appoptions.LogLevel.String()) diff --git a/v2/internal/app/app_product_info.go b/v2/internal/app/app_product_info.go new file mode 100644 index 000000000..3cf130c27 --- /dev/null +++ b/v2/internal/app/app_product_info.go @@ -0,0 +1,19 @@ +package app + +import "context" + +var ( + ProductName = "Unset" + ProductVersion = "Unset" + CompanyName = "Unset" + Copyright = "Unset" + Comments = "Unset" +) + +func injectProductInfo(ctx context.Context) context.Context { + ctx = context.WithValue(ctx, "productName", ProductName) + ctx = context.WithValue(ctx, "productVersion", ProductVersion) + ctx = context.WithValue(ctx, "companyName", CompanyName) + ctx = context.WithValue(ctx, "copyright", Copyright) + return context.WithValue(ctx, "comments", Comments) +} diff --git a/v2/internal/app/app_production.go b/v2/internal/app/app_production.go index 9eb0e5a66..6b6e0000f 100644 --- a/v2/internal/app/app_production.go +++ b/v2/internal/app/app_production.go @@ -37,6 +37,7 @@ func CreateApp(appoptions *options.App) (*App, error) { devtoolsEnabled := IsDevtoolsEnabled() ctx = context.WithValue(ctx, "debug", debug) ctx = context.WithValue(ctx, "devtoolsEnabled", devtoolsEnabled) + ctx = injectProductInfo(ctx) // Set up logger myLogger := logger.New(appoptions.Logger) diff --git a/v2/internal/frontend/dispatcher/systemcalls.go b/v2/internal/frontend/dispatcher/systemcalls.go index b090a416e..3f8fa069b 100644 --- a/v2/internal/frontend/dispatcher/systemcalls.go +++ b/v2/internal/frontend/dispatcher/systemcalls.go @@ -46,6 +46,8 @@ func (d *Dispatcher) processSystemCall(payload callMessage, sender frontend.Fron return sender.WindowIsFullscreen(), nil case "Environment": return runtime.Environment(d.ctx), nil + case "ProductInfo": + return runtime.ProductInfo(d.ctx), nil case "ClipboardGetText": t, err := sender.ClipboardGetText() return t, err diff --git a/v2/internal/frontend/runtime/desktop/main.js b/v2/internal/frontend/runtime/desktop/main.js index 3fda7ef36..c39dc36cb 100644 --- a/v2/internal/frontend/runtime/desktop/main.js +++ b/v2/internal/frontend/runtime/desktop/main.js @@ -44,6 +44,10 @@ export function Environment() { return Call(":wails:Environment"); } +export function ProductInfo() { + return Call(":wails:ProductInfo"); +} + // The JS runtime window.runtime = { ...Log, @@ -59,6 +63,7 @@ window.runtime = { EventsOff, EventsOffAll, Environment, + ProductInfo, Show, Hide, Quit diff --git a/v2/internal/frontend/runtime/wrapper/runtime.d.ts b/v2/internal/frontend/runtime/wrapper/runtime.d.ts index 4445dac21..cf0f25965 100644 --- a/v2/internal/frontend/runtime/wrapper/runtime.d.ts +++ b/v2/internal/frontend/runtime/wrapper/runtime.d.ts @@ -32,6 +32,15 @@ export interface EnvironmentInfo { arch: string; } +// ProductBuildInfo contains product information from the original wails.json file +export interface ProductBuildInfo { + productName: string; + productVersion: string; + companyName: string; + copyright: string; + comments: string; +} + // [EventsEmit](https://wails.io/docs/reference/runtime/events#eventsemit) // emits the given event. Optional data may be passed with the event. // This will trigger any event listeners. @@ -214,6 +223,9 @@ export function BrowserOpenURL(url: string): void; // Returns information about the environment export function Environment(): Promise; +// Returns product information from the original wails.json file +export function ProductInfo(): Promise; + // [Quit](https://wails.io/docs/reference/runtime/intro#quit) // Quits the application. export function Quit(): void; diff --git a/v2/internal/frontend/runtime/wrapper/runtime.js b/v2/internal/frontend/runtime/wrapper/runtime.js index 7cb89d750..9e42e78c1 100644 --- a/v2/internal/frontend/runtime/wrapper/runtime.js +++ b/v2/internal/frontend/runtime/wrapper/runtime.js @@ -185,6 +185,10 @@ export function Environment() { return window.runtime.Environment(); } +export function ProductInfo() { + return window.runtime.ProductInfo(); +} + export function Quit() { window.runtime.Quit(); } diff --git a/v2/pkg/commands/build/base.go b/v2/pkg/commands/build/base.go index 239932ce8..d882939b6 100644 --- a/v2/pkg/commands/build/base.go +++ b/v2/pkg/commands/build/base.go @@ -258,6 +258,18 @@ func (b *BaseBuilder) CompileProject(options *Options) error { } } + // Inject the product info variable values + productInfo := options.ProjectData.Info + ldflags.Add("-X", fmt.Sprintf("'internal.app.ProductName=%s'", productInfo.ProductName)) + ldflags.Add("-X", fmt.Sprintf("'internal.app.ProductVersion=%s'", productInfo.ProductVersion)) + ldflags.Add("-X", fmt.Sprintf("'internal.app.CompanyName=%s'", productInfo.CompanyName)) + if productInfo.Copyright != nil { + ldflags.Add("-X", fmt.Sprintf("'internal.app.Copyright=%s'", *productInfo.Copyright)) + } + if productInfo.Comments != nil { + ldflags.Add("-X", fmt.Sprintf("'internal.app.Comments=%s'", *productInfo.Comments)) + } + ldflags.Deduplicate() if ldflags.Length() > 0 { diff --git a/v2/pkg/runtime/runtime.go b/v2/pkg/runtime/runtime.go index 6de5ea798..ac4427978 100644 --- a/v2/pkg/runtime/runtime.go +++ b/v2/pkg/runtime/runtime.go @@ -105,3 +105,44 @@ func Environment(ctx context.Context) EnvironmentInfo { result.Arch = goruntime.GOARCH return result } + +// ProductBuildInfo contains product information from the original wails.json file +type ProductBuildInfo struct { + ProductName string `json:"productName"` + ProductVersion string `json:"productVersion"` + CompanyName string `json:"companyName"` + Copyright string `json:"copyright"` + Comments string `json:"comments"` +} + +// ProductInfo returns product information from the original wails.json file +func ProductInfo(ctx context.Context) ProductBuildInfo { + productBuildInfo := ProductBuildInfo{ + ProductName: "Unset", + ProductVersion: "Unset", + CompanyName: "Unset", + Copyright: "Unset", + Comments: "Unset", + } + productName := ctx.Value("productName") + if productName != nil { + productBuildInfo.ProductName = productName.(string) + } + productVersion := ctx.Value("productVersion") + if productVersion != nil { + productBuildInfo.ProductVersion = productVersion.(string) + } + companyName := ctx.Value("companyName") + if companyName != nil { + productBuildInfo.CompanyName = companyName.(string) + } + copyright := ctx.Value("copyright") + if copyright != nil { + productBuildInfo.Copyright = copyright.(string) + } + comments := ctx.Value("comments") + if comments != nil { + productBuildInfo.Comments = comments.(string) + } + return productBuildInfo +}