Skip to content

Commit

Permalink
client,webserver: more fitting place to inject app.Version
Browse files Browse the repository at this point in the history
	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.
  • Loading branch information
dev-warrior777 committed Dec 2, 2024
1 parent 874fe24 commit 83d7766
Show file tree
Hide file tree
Showing 14 changed files with 19 additions and 24 deletions.
4 changes: 2 additions & 2 deletions client/app/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 != "" {
Expand Down Expand Up @@ -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,
}
}

Expand Down
2 changes: 1 addition & 1 deletion client/cmd/bisonw-desktop/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 0 additions & 2 deletions client/cmd/bisonw-desktop/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
1 change: 0 additions & 1 deletion client/cmd/bisonw/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion client/cmd/bisonw/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion client/webserver/locales/ar.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: "إيداع"},
Expand Down
2 changes: 1 addition & 1 deletion client/webserver/locales/de-de.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ var DeDE = map[string]*intl.Translation{
"Export Account": {T: "Account exportieren"},
"simultaneous_servers_msg": {T: "Der <span class=brand></span> 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"},
Expand Down
2 changes: 1 addition & 1 deletion client/webserver/locales/en-us.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion client/webserver/locales/pl-pl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down
2 changes: 1 addition & 1 deletion client/webserver/locales/pt-br.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down
2 changes: 1 addition & 1 deletion client/webserver/locales/zh-cn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: "存款"},
Expand Down
2 changes: 1 addition & 1 deletion client/webserver/site/src/html/settings.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
<span class="ico-ticket"></span> [[[Redeem game code]]]
</div>
{{$version := .AppVersion}}
<p class="grey">[[[Build ID]]]: <span id="version" class="mono">{{$version}}</span></p>
<p class="grey">[[[Version]]]: <span id="version" class="mono">{{$version}}</span></p>
</div>
</section>

Expand Down
9 changes: 5 additions & 4 deletions client/webserver/webserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
9 changes: 3 additions & 6 deletions client/webserver/webserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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.")
}
Expand All @@ -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)
}
Expand Down

0 comments on commit 83d7766

Please sign in to comment.