mirror of
https://github.com/makeworld-the-better-one/amfora.git
synced 2024-09-11 14:55:51 +03:00
⚡️ Replace dir & path funcs with cached strings
This commit is contained in:
parent
61e2c51e40
commit
dd6ebf9254
4
NOTES.md
4
NOTES.md
@ -9,6 +9,4 @@
|
||||
- Text background not reset on ANSI pages
|
||||
- Filed [issue 25](https://gitlab.com/tslocum/cview/-/issues/25)
|
||||
- Modal styling messed up when wrapped - example occurence is the error modal for a long unsupported scheme URL
|
||||
- Filed [issue 26](https://gitlab.com/tslocum/cview/-/issues/26)
|
||||
- Newtab page doesn't get margin
|
||||
- Config funcs should become variables
|
||||
- Filed [issue 26](https://gitlab.com/tslocum/cview/-/issues/26)
|
@ -11,48 +11,19 @@ import (
|
||||
)
|
||||
|
||||
var amforaAppData string // Where amfora files are stored on Windows - cached here
|
||||
|
||||
func configDir() string {
|
||||
home, err := homedir.Dir()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if runtime.GOOS == "windows" {
|
||||
return amforaAppData
|
||||
}
|
||||
|
||||
// Unix / POSIX system
|
||||
return filepath.Join(home, ".config", "amfora")
|
||||
}
|
||||
|
||||
func configPath() string {
|
||||
return filepath.Join(configDir(), "config.toml")
|
||||
}
|
||||
var configDir string
|
||||
var configPath string
|
||||
|
||||
var TofuStore = viper.New()
|
||||
|
||||
func tofuDBDir() string {
|
||||
home, err := homedir.Dir()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
// Windows just stores it in APPDATA along with other stuff
|
||||
if runtime.GOOS == "windows" {
|
||||
return amforaAppData
|
||||
}
|
||||
// XDG cache dir on POSIX systems
|
||||
return filepath.Join(home, ".cache", "amfora")
|
||||
}
|
||||
|
||||
func tofuDBPath() string {
|
||||
return filepath.Join(tofuDBDir(), "tofu.toml")
|
||||
}
|
||||
var tofuDBDir string
|
||||
var tofuDBPath string
|
||||
|
||||
func Init() error {
|
||||
home, err := homedir.Dir()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
// Cache AppData path
|
||||
if runtime.GOOS == "windows" {
|
||||
appdata, ok := os.LookupEnv("APPDATA")
|
||||
if ok {
|
||||
@ -61,12 +32,30 @@ func Init() error {
|
||||
amforaAppData = filepath.Join(home, filepath.FromSlash("AppData/Roaming/amfora/"))
|
||||
}
|
||||
}
|
||||
// Cache config directory and file paths
|
||||
if runtime.GOOS == "windows" {
|
||||
configDir = amforaAppData
|
||||
} else {
|
||||
// Unix / POSIX system
|
||||
configDir = filepath.Join(home, ".config", "amfora")
|
||||
}
|
||||
configPath = filepath.Join(configDir, "config.toml")
|
||||
|
||||
err = os.MkdirAll(configDir(), 0755)
|
||||
// Cache TOFU db directory and file paths
|
||||
// Windows just stores it in APPDATA along with other stuff
|
||||
if runtime.GOOS == "windows" {
|
||||
tofuDBDir = amforaAppData
|
||||
} else {
|
||||
// XDG cache dir on POSIX systems
|
||||
tofuDBDir = filepath.Join(home, ".cache", "amfora")
|
||||
}
|
||||
tofuDBPath = filepath.Join(tofuDBDir, "tofu.toml")
|
||||
|
||||
err = os.MkdirAll(configDir, 0755)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
f, err := os.OpenFile(configPath(), os.O_RDWR|os.O_CREATE|os.O_EXCL, 0666)
|
||||
f, err := os.OpenFile(configPath, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0666)
|
||||
if err == nil {
|
||||
// Config file doesn't exist yet, write the default one
|
||||
_, err = f.Write(defaultConf)
|
||||
@ -77,13 +66,13 @@ func Init() error {
|
||||
f.Close()
|
||||
}
|
||||
|
||||
err = os.MkdirAll(tofuDBDir(), 0755)
|
||||
err = os.MkdirAll(tofuDBDir, 0755)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
os.OpenFile(tofuDBPath(), os.O_RDWR|os.O_CREATE|os.O_EXCL, 0666)
|
||||
os.OpenFile(tofuDBPath, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0666)
|
||||
|
||||
TofuStore.SetConfigFile(tofuDBPath())
|
||||
TofuStore.SetConfigFile(tofuDBPath)
|
||||
TofuStore.SetConfigType("toml")
|
||||
err = TofuStore.ReadInConfig()
|
||||
if err != nil {
|
||||
@ -100,7 +89,7 @@ func Init() error {
|
||||
viper.SetDefault("cache.max_size", 0)
|
||||
viper.SetDefault("cache.max_pages", 20)
|
||||
|
||||
viper.SetConfigFile(configPath())
|
||||
viper.SetConfigFile(configPath)
|
||||
viper.SetConfigType("toml")
|
||||
err = viper.ReadInConfig()
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user