Skip to content

Commit

Permalink
use consts for HOME and AyanDict
Browse files Browse the repository at this point in the history
  • Loading branch information
ilius committed Feb 25, 2024
1 parent aa8344d commit 922129a
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 12 deletions.
8 changes: 5 additions & 3 deletions pkg/appinfo/app_info.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package appinfo

const APP_NAME = "ayandict"

const VERSION = "v2.0.0"
const (
APP_NAME = "ayandict"
APP_DESC = "AyanDict"
VERSION = "v2.0.0"
)

const ABOUT = `AyanDict is simple dictionary application based on Qt and written in Go.
Expand Down
3 changes: 2 additions & 1 deletion pkg/application/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

// "github.com/ilius/qt/webengine"

"github.com/ilius/ayandict/v2/pkg/appinfo"
"github.com/ilius/ayandict/v2/pkg/config"
"github.com/ilius/ayandict/v2/pkg/dictmgr"
"github.com/ilius/ayandict/v2/pkg/dictmgr/qdictmgr"
Expand Down Expand Up @@ -110,7 +111,7 @@ func (app *Application) Run() {
// icon := gui.NewQIcon5("./img/icon.png")

window := app.window
window.SetWindowTitle("AyanDict")
window.SetWindowTitle(appinfo.APP_DESC)
window.Resize2(600, 400)

entry := widgets.NewQLineEdit(nil)
Expand Down
6 changes: 4 additions & 2 deletions pkg/config/paths_mac.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@ package config
import (
"os"
"path/filepath"

"github.com/ilius/ayandict/v2/pkg/appinfo"
)

func platformConfigDir() string {
return filepath.Join(
os.Getenv("HOME"),
os.Getenv(S_HOME),
"Library/Preferences/AyanDict",
)
}

func GetCacheDir() string {
return filepath.Join(os.Getenv("HOME"), "Library", "Caches", "AyanDict")
return filepath.Join(os.Getenv(S_HOME), "Library", "Caches", appinfo.APP_DESC)
}
8 changes: 5 additions & 3 deletions pkg/config/paths_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@ package config
import (
"os"
"path/filepath"

"github.com/ilius/ayandict/v2/pkg/appinfo"
)

func platformConfigDir() string {
parent := os.Getenv("XDG_CONFIG_HOME")
if parent == "" {
parent = filepath.Join(os.Getenv("HOME"), ".config")
parent = filepath.Join(os.Getenv(S_HOME), ".config")
}
return filepath.Join(parent, "ayandict")
return filepath.Join(parent, appinfo.APP_DESC)
}

func GetCacheDir() string {
return filepath.Join(os.Getenv("HOME"), ".cache", "ayandict")
return filepath.Join(os.Getenv(S_HOME), ".cache", appinfo.APP_DESC)
}
6 changes: 4 additions & 2 deletions pkg/config/paths_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"log"
"os"
"path/filepath"

"github.com/ilius/ayandict/v2/pkg/appinfo"
)

func platformConfigDir() string {
Expand All @@ -16,7 +18,7 @@ func platformConfigDir() string {
// user := os.Getenv("USERNAME")
// tmpDir := os.Getenv("TEMP")
appData := os.Getenv("APPDATA")
confDir := filepath.Join(appData, "AyanDict")
confDir := filepath.Join(appData, appinfo.APP_DESC)
return confDir
}

Expand All @@ -32,5 +34,5 @@ func GetCacheDir() string {
return ""
}
}
return filepath.Join(localAppData, "AyanDict", "Cache")
return filepath.Join(localAppData, appinfo.APP_DESC, "Cache")
}
3 changes: 3 additions & 0 deletions pkg/config/strings.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package config

const S_HOME = "HOME"
3 changes: 2 additions & 1 deletion pkg/qsettings/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"strings"
"time"

"github.com/ilius/ayandict/v2/pkg/appinfo"
"github.com/ilius/ayandict/v2/pkg/qerr"
"github.com/ilius/qt/core"
"github.com/ilius/qt/gui"
Expand Down Expand Up @@ -59,7 +60,7 @@ func splitterSizes(splitter *widgets.QSplitter) []int {
}

func GetQSettings(parent core.QObject_ITF) *core.QSettings {
return core.NewQSettings("ilius", "ayandict", parent)
return core.NewQSettings("ilius", appinfo.APP_NAME, parent)
}

func restoreSetting(qs *core.QSettings, key string, apply func(*core.QVariant)) {
Expand Down

0 comments on commit 922129a

Please sign in to comment.