1
0
mirror of https://github.com/makew0rld/amfora.git synced 2024-06-21 19:35:23 +00:00

🎨 Reorder config.Init code

This commit is contained in:
makeworld 2020-08-07 12:27:50 -04:00
parent 5cb629f4c3
commit 1e378fced2
4 changed files with 69 additions and 50 deletions

View File

@ -7,7 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Added
- Emoji favicons can now be seen if `emoji_favicons` is enabled in the config (#62)
- **Feed & page subscription** (#61)
- **Emoji favicons** can now be seen if `emoji_favicons` is enabled in the config (#62)
- The `shift_numbers` key in the config was added, so that non US keyboard users can navigate tabs (#64)
- <kbd>F1</kbd> and <kbd>F2</kbd> keys for navigating to the previous and next tabs (#64)

View File

@ -97,8 +97,8 @@ Features in *italics* are in the master branch, but not in the latest release.
- [x] Theming
- [x] *Emoji favicons*
- See `gemini://mozz.us/files/rfc_gemini_favicon.gmi` for details
- [ ] Subscribe to RSS and Atom feeds and display them
- Subscribing to page changes, similar to how Spacewalk works, will also be supported
- [x] *Subscribe to RSS and Atom feeds and display them*
- Subscribing to page changes, similar to how Spacewalk works, is also supported
- [ ] Stream support
- [ ] Full client certificate UX within the client
- Create transient and permanent certs within the client, per domain

View File

@ -30,7 +30,15 @@ var bkmkPath string
// For other pkgs to use
var DownloadsDir string
// Feeds
var Feeds = viper.New()
var feedsDir string
var feedsPath string
func Init() error {
// *** Set paths ***
home, err := homedir.Dir()
if err != nil {
return err
@ -92,7 +100,7 @@ func Init() error {
}
bkmkPath = filepath.Join(bkmkDir, "bookmarks.toml")
// Create necessary files and folders
// *** Create necessary files and folders ***
// Config
err = os.MkdirAll(configDir, 0755)
@ -114,56 +122,21 @@ func Init() error {
if err != nil {
return err
}
os.OpenFile(tofuDBPath, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0666)
f, err = os.OpenFile(tofuDBPath, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0666)
if err == nil {
f.Close()
}
// Bookmarks
err = os.MkdirAll(bkmkDir, 0755)
if err != nil {
return err
}
os.OpenFile(bkmkPath, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0666)
// Setup vipers
TofuStore.SetConfigFile(tofuDBPath)
TofuStore.SetConfigType("toml")
err = TofuStore.ReadInConfig()
if err != nil {
return err
f, err = os.OpenFile(bkmkPath, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0666)
if err == nil {
f.Close()
}
BkmkStore.SetConfigFile(bkmkPath)
BkmkStore.SetConfigType("toml")
err = BkmkStore.ReadInConfig()
if err != nil {
return err
}
BkmkStore.Set("DO NOT TOUCH", true)
err = BkmkStore.WriteConfig()
if err != nil {
return err
}
viper.SetDefault("a-general.home", "gemini.circumlunar.space")
viper.SetDefault("a-general.http", "default")
viper.SetDefault("a-general.search", "gus.guru/search")
viper.SetDefault("a-general.color", true)
viper.SetDefault("a-general.bullets", true)
viper.SetDefault("a-general.left_margin", 0.15)
viper.SetDefault("a-general.max_width", 100)
viper.SetDefault("a-general.downloads", "")
viper.SetDefault("a-general.page_max_size", 2097152)
viper.SetDefault("a-general.page_max_time", 10)
viper.SetDefault("a-general.emoji_favicons", false)
viper.SetDefault("keybindings.shift_numbers", "!@#$%^&*()")
viper.SetDefault("cache.max_size", 0)
viper.SetDefault("cache.max_pages", 20)
viper.SetConfigFile(configPath)
viper.SetConfigType("toml")
err = viper.ReadInConfig()
if err != nil {
return err
}
// *** Downloads paths, setup, and creation ***
// Setup downloads dir
if viper.GetString("a-general.downloads") == "" {
@ -196,11 +169,56 @@ func Init() error {
DownloadsDir = dDir
}
// *** Setup vipers ***
TofuStore.SetConfigFile(tofuDBPath)
TofuStore.SetConfigType("toml")
err = TofuStore.ReadInConfig()
if err != nil {
return err
}
BkmkStore.SetConfigFile(bkmkPath)
BkmkStore.SetConfigType("toml")
err = BkmkStore.ReadInConfig()
if err != nil {
return err
}
BkmkStore.Set("DO NOT TOUCH", true)
err = BkmkStore.WriteConfig()
if err != nil {
return err
}
// Setup main config
viper.SetDefault("a-general.home", "gemini.circumlunar.space")
viper.SetDefault("a-general.http", "default")
viper.SetDefault("a-general.search", "gus.guru/search")
viper.SetDefault("a-general.color", true)
viper.SetDefault("a-general.bullets", true)
viper.SetDefault("a-general.left_margin", 0.15)
viper.SetDefault("a-general.max_width", 100)
viper.SetDefault("a-general.downloads", "")
viper.SetDefault("a-general.page_max_size", 2097152)
viper.SetDefault("a-general.page_max_time", 10)
viper.SetDefault("a-general.emoji_favicons", false)
viper.SetDefault("keybindings.shift_numbers", "!@#$%^&*()")
viper.SetDefault("cache.max_size", 0)
viper.SetDefault("cache.max_pages", 20)
viper.SetConfigFile(configPath)
viper.SetConfigType("toml")
err = viper.ReadInConfig()
if err != nil {
return err
}
// Setup cache from config
cache.SetMaxSize(viper.GetInt("cache.max_size"))
cache.SetMaxPages(viper.GetInt("cache.max_pages"))
// Theme
// Setup theme
configTheme := viper.Sub("theme")
if configTheme != nil {
for k, v := range configTheme.AllSettings() {

View File

@ -8,7 +8,7 @@ import (
)
// Functions to allow themeing configuration.
// UI element colors are mapped to a string key, such as "error" or "tab_background"
// UI element colors are mapped to a string key, such as "error" or "tab_bg"
// These are the same keys used in the config file.
var themeMu = sync.RWMutex{}
@ -64,8 +64,8 @@ var theme = map[string]tcell.Color{
func SetColor(key string, color tcell.Color) {
themeMu.Lock()
defer themeMu.Unlock()
theme[key] = color
themeMu.Unlock()
}
// GetColor will return tcell.ColorBlack if there is no color for the provided key.