mirror of
https://github.com/wailsapp/wails.git
synced 2026-03-14 14:45:49 +01:00
Making product information from the wails.json available at runtime on Go and JavaScript ends via runtime::ProductInfo.
This commit is contained in:
parent
140a110e6d
commit
d3ecae418c
9 changed files with 97 additions and 0 deletions
|
|
@ -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())
|
||||
|
|
|
|||
19
v2/internal/app/app_product_info.go
Normal file
19
v2/internal/app/app_product_info.go
Normal file
|
|
@ -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)
|
||||
}
|
||||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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<EnvironmentInfo>;
|
||||
|
||||
// Returns product information from the original wails.json file
|
||||
export function ProductInfo(): Promise<ProductBuildInfo>;
|
||||
|
||||
// [Quit](https://wails.io/docs/reference/runtime/intro#quit)
|
||||
// Quits the application.
|
||||
export function Quit(): void;
|
||||
|
|
|
|||
|
|
@ -185,6 +185,10 @@ export function Environment() {
|
|||
return window.runtime.Environment();
|
||||
}
|
||||
|
||||
export function ProductInfo() {
|
||||
return window.runtime.ProductInfo();
|
||||
}
|
||||
|
||||
export function Quit() {
|
||||
window.runtime.Quit();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue