Skip to content

Commit 4567492

Browse files
committed
fixed hardcoded path to translations, generate machine id
1 parent 23cf632 commit 4567492

File tree

15 files changed

+479
-1
lines changed

15 files changed

+479
-1
lines changed

app.go

+18-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"net/http"
99
"os"
1010
"os/exec"
11+
"os/user"
1112
"path/filepath"
1213
"runtime"
1314
"strings"
@@ -18,6 +19,7 @@ import (
1819
. "ytd/models"
1920
. "ytd/plugins"
2021

22+
"github.com/denisbrodbeck/machineid"
2123
"github.com/leonelquinteros/gotext"
2224
"github.com/mitchellh/mapstructure"
2325
"github.com/wailsapp/wails/v2"
@@ -26,8 +28,15 @@ import (
2628
"github.com/xujiajun/nutsdb"
2729
)
2830

31+
var i18nPath string
32+
2933
var wailsRuntime *wails.Runtime
3034

35+
type HostInfo struct {
36+
ID string `json:"id"`
37+
Username string `json:"username"`
38+
}
39+
3140
type AppState struct {
3241
runtime *wails.Runtime
3342
db *nutsdb.DB
@@ -37,6 +46,7 @@ type AppState struct {
3746
Config *AppConfig `json:"config"`
3847
Stats *AppStats `json:"stats"`
3948
AppVersion string `json:"appVersion"`
49+
Host HostInfo `json:"host"`
4050
PwaUrl string `json:"pwaUrl"`
4151
context.Context `json:"-"`
4252

@@ -64,6 +74,13 @@ func (state *AppState) PreWailsInit(ctx context.Context) {
6474
if _, err := mac.StartsAtLogin(); err == nil {
6575
state.canStartAtLogin = true
6676
}
77+
78+
if machineid, err := machineid.ProtectedID("ytd"); err == nil {
79+
state.Host.ID = machineid
80+
}
81+
if user, err := user.Current(); err == nil {
82+
state.Host.Username = user.Username
83+
}
6784
}
6885

6986
func (state *AppState) WailsInit(runtime *wails.Runtime) {
@@ -177,7 +194,7 @@ func (state *AppState) WailsShutdown() {
177194
}
178195

179196
func (state *AppState) ReloadNewLanguage() {
180-
gotext.Configure("/Users/oskarmarciniak/projects/golang/ytd/i18n", state.Config.Language, "default")
197+
gotext.Configure(i18nPath, state.Config.Language, "default")
181198
// re render tray to take effect for new language translations
182199
state.tray.reRenderTray(func() {})
183200
// do other stuff if needed to reload translations from some ui native elements

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ go 1.16
44

55
require (
66
github.com/Masterminds/semver/v3 v3.1.1
7+
github.com/denisbrodbeck/machineid v1.0.1
78
github.com/dsnet/compress v0.0.1 // indirect
89
github.com/frankban/quicktest v1.13.1 // indirect
910
github.com/go-ole/go-ole v1.2.5 // indirect

go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3
8989
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
9090
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
9191
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
92+
github.com/denisbrodbeck/machineid v1.0.1 h1:geKr9qtkB876mXguW2X6TU4ZynleN6ezuMSRhl4D7AQ=
93+
github.com/denisbrodbeck/machineid v1.0.1/go.mod h1:dJUwb7PTidGDeYyUBmXZ2GphQBbjJCrnectwCyxcUSI=
9294
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
9395
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
9496
github.com/dsnet/compress v0.0.1 h1:PlZu0n3Tuv04TzpfPbrnI0HW/YwodEXDS+oPKahKF0Q=

vendor/github.com/denisbrodbeck/machineid/.gitignore

+29
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/denisbrodbeck/machineid/LICENSE.md

+22
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/denisbrodbeck/machineid/README.md

+182
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/denisbrodbeck/machineid/helper.go

+36
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/denisbrodbeck/machineid/id.go

+45
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)