From 1e378fced2c5a34c94fd52335a0bd3e21e227932 Mon Sep 17 00:00:00 2001 From: makeworld Date: Fri, 7 Aug 2020 12:27:50 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Reorder=20config.Init=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 3 +- README.md | 4 +- config/config.go | 108 +++++++++++++++++++++++++++-------------------- config/theme.go | 4 +- 4 files changed, 69 insertions(+), 50 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4be83a0..98364e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) - F1 and F2 keys for navigating to the previous and next tabs (#64) diff --git a/README.md b/README.md index 243b639..ffbae0c 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/config/config.go b/config/config.go index 528b7c4..38887a4 100644 --- a/config/config.go +++ b/config/config.go @@ -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() { diff --git a/config/theme.go b/config/theme.go index 6c021cc..7de75f9 100644 --- a/config/theme.go +++ b/config/theme.go @@ -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.