From 83d7766a4d7af0bdce0ccaeab8aa054db71604cd Mon Sep 17 00:00:00 2001 From: dev-warrior777 <> Date: Mon, 2 Dec 2024 18:11:05 +0800 Subject: [PATCH] client,webserver: more fitting place to inject app.Version Also: - Translation string 'BUILD ID' is no longer used. - 'BUILD ID' => 'Version' - Translations updated to mean Version - not Build Id. except arabic as I cannot handle the input method to edit arabic as the arrow/BS keys go the wrong way in the editor. And I do not understand how the editor concatenates arabic strings. Meaning left as previously translated: Build Id. --- client/app/config.go | 4 ++-- client/cmd/bisonw-desktop/app.go | 2 +- client/cmd/bisonw-desktop/config.go | 2 -- client/cmd/bisonw/config.go | 1 - client/cmd/bisonw/main.go | 2 +- client/webserver/locales/ar.go | 2 +- client/webserver/locales/de-de.go | 2 +- client/webserver/locales/en-us.go | 2 +- client/webserver/locales/pl-pl.go | 2 +- client/webserver/locales/pt-br.go | 2 +- client/webserver/locales/zh-cn.go | 2 +- client/webserver/site/src/html/settings.tmpl | 2 +- client/webserver/webserver.go | 9 +++++---- client/webserver/webserver_test.go | 9 +++------ 14 files changed, 19 insertions(+), 24 deletions(-) diff --git a/client/app/config.go b/client/app/config.go index 36e145b049..8c19be8755 100644 --- a/client/app/config.go +++ b/client/app/config.go @@ -143,7 +143,6 @@ type Config struct { WebConfig LogConfig MMConfig - AppVersion string // AppData and ConfigPath should be parsed from the command-line, // as it makes no sense to set these in the config file itself. If no values // are assigned, defaults will be used. @@ -163,7 +162,7 @@ type Config struct { // Web creates a configuration for the webserver. This is a Config method // instead of a WebConfig method because Language is an app-level setting used // by both core and rpcserver. -func (cfg *Config) Web(c *core.Core, mm *mm.MarketMaker, log dex.Logger, utc bool) *webserver.Config { +func (cfg *Config) Web(c *core.Core, mm *mm.MarketMaker, log dex.Logger, utc bool, appVersion string) *webserver.Config { addr := cfg.WebAddr host, _, err := net.SplitHostPort(addr) if err == nil && host != "" { @@ -197,6 +196,7 @@ func (cfg *Config) Web(c *core.Core, mm *mm.MarketMaker, log dex.Logger, utc boo NoEmbed: cfg.NoEmbedSite, HttpProf: cfg.HTTPProfile, Language: cfg.Language, + AppVersion: appVersion, } } diff --git a/client/cmd/bisonw-desktop/app.go b/client/cmd/bisonw-desktop/app.go index b7e33fe2cd..8efd6fafcd 100644 --- a/client/cmd/bisonw-desktop/app.go +++ b/client/cmd/bisonw-desktop/app.go @@ -222,7 +222,7 @@ func mainCore() error { }() } - webSrv, err := webserver.New(cfg.Web(clientCore, marketMaker, logMaker.Logger("WEB"), utc), cfg.AppVersion) + webSrv, err := webserver.New(cfg.Web(clientCore, marketMaker, logMaker.Logger("WEB"), utc, app.Version)) if err != nil { return fmt.Errorf("failed creating web server: %w", err) } diff --git a/client/cmd/bisonw-desktop/config.go b/client/cmd/bisonw-desktop/config.go index 36e9eee284..46f7202641 100644 --- a/client/cmd/bisonw-desktop/config.go +++ b/client/cmd/bisonw-desktop/config.go @@ -49,8 +49,6 @@ func configure() (*Config, error) { return nil, err } - cfg.AppVersion = app.Version - // Resolve unset fields. return &cfg, app.ResolveConfig(appData, &cfg.Config) } diff --git a/client/cmd/bisonw/config.go b/client/cmd/bisonw/config.go index 467c16b264..e102adf12e 100644 --- a/client/cmd/bisonw/config.go +++ b/client/cmd/bisonw/config.go @@ -13,7 +13,6 @@ func configure() (*app.Config, error) { // or the version flag was specified. Override any environment variables // with parsed command line flags. iniCfg := app.DefaultConfig - iniCfg.AppVersion = app.Version preCfg := iniCfg if err := app.ParseCLIConfig(&preCfg); err != nil { return nil, err diff --git a/client/cmd/bisonw/main.go b/client/cmd/bisonw/main.go index eb11e5c0d6..065160d832 100644 --- a/client/cmd/bisonw/main.go +++ b/client/cmd/bisonw/main.go @@ -154,7 +154,7 @@ func runCore(cfg *app.Config) error { } if !cfg.NoWeb { - webSrv, err := webserver.New(cfg.Web(clientCore, marketMaker, logMaker.Logger("WEB"), utc), cfg.AppVersion) + webSrv, err := webserver.New(cfg.Web(clientCore, marketMaker, logMaker.Logger("WEB"), utc, app.Version)) if err != nil { return fmt.Errorf("failed creating web server: %w", err) } diff --git a/client/webserver/locales/ar.go b/client/webserver/locales/ar.go index 27f7c264ac..136dd42e7d 100644 --- a/client/webserver/locales/ar.go +++ b/client/webserver/locales/ar.go @@ -137,7 +137,7 @@ var Ar = map[string]*intl.Translation{ "Export Account": {T: "تصدير الحساب"}, "simultaneous_servers_msg": {T: "يدعم عميل منصة المبادلات اللامركزية لديكريد الاستخدام المتزامن لأي عدد من خوادم منصة المبادلات اللامركزية DEX."}, "Change App Password": {T: "تغيير كلمة مرور التطبيق"}, - "Build ID": {T: "معرف البنية"}, + "Version": {T: "معرف البنية"}, "Connect": {T: "اتصل"}, "Send": {T: "ارسال"}, "Deposit": {T: "إيداع"}, diff --git a/client/webserver/locales/de-de.go b/client/webserver/locales/de-de.go index 497f316522..bcf462d8de 100644 --- a/client/webserver/locales/de-de.go +++ b/client/webserver/locales/de-de.go @@ -135,7 +135,7 @@ var DeDE = map[string]*intl.Translation{ "Export Account": {T: "Account exportieren"}, "simultaneous_servers_msg": {T: "Der unterstützt die gleichzeitige Nutzung einer beliebigen Anzahl von DEX-Servern."}, "Change App Password": {T: "App-Passwort ändern"}, - "Build ID": {T: "Version"}, + "Version": {T: "Version"}, "Connect": {T: "Verbinden"}, "Send": {T: "Senden"}, "Deposit": {T: "Einzahlen"}, diff --git a/client/webserver/locales/en-us.go b/client/webserver/locales/en-us.go index 2f8daa2291..799727bfe4 100644 --- a/client/webserver/locales/en-us.go +++ b/client/webserver/locales/en-us.go @@ -167,7 +167,7 @@ var EnUS = map[string]*intl.Translation{ "browser_ntfn_blocked": {T: "Browser notifications are currently blocked. Please unblock this site in your browser to receive notifications."}, "enable_browser_ntfn_info": {T: "Desktop notifications appear even when this window is not active. When you have other applications open this can be helpful as you will be notified on DCRDEX events. Customize below the types of notifications you would like to receive."}, "Save Notifications": {T: "Save Notifications"}, - "Build ID": {T: "Version"}, + "Version": {T: "Version"}, "Connect": {T: "Connect"}, "Send": {T: "Send"}, "Deposit": {T: "Deposit"}, // unused diff --git a/client/webserver/locales/pl-pl.go b/client/webserver/locales/pl-pl.go index d47cf94cb6..fa8898c193 100644 --- a/client/webserver/locales/pl-pl.go +++ b/client/webserver/locales/pl-pl.go @@ -133,7 +133,7 @@ var PlPL = map[string]*intl.Translation{ "Export Account": {T: "Eksportuj konto"}, "simultaneous_servers_msg": {T: "Klient Decred DEX wspiera jednoczesne korzystanie z wielu serwerów DEX."}, "Change App Password": {T: "Zmień hasło aplikacji"}, - "Build ID": {T: "Wersja"}, + "Version": {T: "Wersja"}, "Connect": {T: "Połącz"}, "Withdraw": {T: "Wypłać"}, "Deposit": {T: "Zdeponuj"}, diff --git a/client/webserver/locales/pt-br.go b/client/webserver/locales/pt-br.go index db2ccbcc89..cb9c96c6e5 100644 --- a/client/webserver/locales/pt-br.go +++ b/client/webserver/locales/pt-br.go @@ -133,7 +133,7 @@ var PtBr = map[string]*intl.Translation{ "Export Account": {T: "Exportar Conta"}, "simultaneous_servers_msg": {T: "O cliente da DEX suporta simultâneos números de servidores DEX."}, "Change App Password": {T: "Trocar Senha do aplicativo"}, - "Build ID": {T: "Versão"}, + "Version": {T: "Versão"}, "Connect": {T: "Conectar"}, "Withdraw": {T: "Retirar"}, "Deposit": {T: "Depositar"}, diff --git a/client/webserver/locales/zh-cn.go b/client/webserver/locales/zh-cn.go index 4adc2fe42d..01194cf367 100644 --- a/client/webserver/locales/zh-cn.go +++ b/client/webserver/locales/zh-cn.go @@ -135,7 +135,7 @@ var ZhCN = map[string]*intl.Translation{ "Export Account": {T: "退出账户"}, "simultaneous_servers_msg": {T: "Decred DEX 客户端支持同时使用任意数量的 DEX 服务器。"}, "Change App Password": {T: "更改应用程序密码"}, - "Build ID": {T: "版本"}, + "Version": {T: "版本"}, "Connect": {T: "连接"}, "Send": {T: "发送"}, "Deposit": {T: "存款"}, diff --git a/client/webserver/site/src/html/settings.tmpl b/client/webserver/site/src/html/settings.tmpl index 2c4b75f61e..48d992fb91 100644 --- a/client/webserver/site/src/html/settings.tmpl +++ b/client/webserver/site/src/html/settings.tmpl @@ -80,7 +80,7 @@ [[[Redeem game code]]] {{$version := .AppVersion}} -

[[[Build ID]]]: {{$version}}

+

[[[Version]]]: {{$version}}

diff --git a/client/webserver/webserver.go b/client/webserver/webserver.go index 9b2ab7a4ad..afed803691 100644 --- a/client/webserver/webserver.go +++ b/client/webserver/webserver.go @@ -238,8 +238,9 @@ type Config struct { // should be used by default since site files from older distributions may // be present on the disk. When NoEmbed is true, this also implies reloading // and execution of html templates on each request. - NoEmbed bool - HttpProf bool + NoEmbed bool + HttpProf bool + AppVersion string } type valStamp struct { @@ -277,7 +278,7 @@ type WebServer struct { // New is the constructor for a new WebServer. CustomSiteDir in the Config can // be left blank, in which case a handful of default locations will be checked. // This will work in most cases. -func New(cfg *Config, appVersion string) (*WebServer, error) { +func New(cfg *Config) (*WebServer, error) { log = cfg.Logger // Only look for files on disk if NoEmbed is set. This is necessary since @@ -393,7 +394,7 @@ func New(cfg *Config, appVersion string) (*WebServer, error) { cachedPasswords: make(map[string]*cachedPassword), bondBuf: map[uint32]valStamp{}, useDEXBranding: useDEXBranding, - appVersion: appVersion, + appVersion: cfg.AppVersion, } s.lang.Store(lang) diff --git a/client/webserver/webserver_test.go b/client/webserver/webserver_test.go index 5a24943f2b..40cbf0d52c 100644 --- a/client/webserver/webserver_test.go +++ b/client/webserver/webserver_test.go @@ -391,13 +391,12 @@ func newTServer(t *testing.T, start bool) (*WebServer, *TCore, func()) { t.Helper() c := &TCore{} var shutdown func() - var appVersion = "1.0.2+release.local" ctx, killCtx := context.WithCancel(tCtx) s, err := New(&Config{ Core: c, Addr: "127.0.0.1:0", Logger: tLogger, - }, appVersion) + }) if err != nil { t.Fatalf("error creating server: %v", err) } @@ -474,14 +473,13 @@ func TestNew_siteError(t *testing.T) { t.Fatalf("Cannot cd to %q", dir) } - var appVersion = "1.0.2+release.local" c := &TCore{} _, err = New(&Config{ Core: c, Addr: "127.0.0.1:0", Logger: tLogger, NoEmbed: true, // this tests locating on-disk files, not the embedded ones - }, appVersion) + }) if err == nil || !strings.HasPrefix(err.Error(), "no HTML template files found") { t.Errorf("Should have failed to start with no site folder.") } @@ -497,12 +495,11 @@ func TestConnectBindError(t *testing.T) { defer shutdown() tAddr := s0.addr - var appVersion = "1.0.2+release.local" s, err := New(&Config{ Core: &TCore{}, Addr: tAddr, Logger: tLogger, - }, appVersion) + }) if err != nil { t.Fatalf("error creating server: %v", err) }