gosuki/config.go

82 lines
1.5 KiB
Go
Raw Normal View History

2019-02-26 18:41:02 +00:00
package main
import (
"gomark/config"
2019-02-27 10:47:06 +00:00
"gomark/database"
2019-02-26 18:41:02 +00:00
"gomark/mozilla"
2019-02-27 10:47:06 +00:00
"gomark/utils"
)
2019-02-26 18:41:02 +00:00
2019-02-27 10:47:06 +00:00
// Config names
const (
FirefoxConf = "firefox"
ChromeConf = "chrome"
2019-02-26 18:41:02 +00:00
)
var FirefoxDefaultConfig = mozilla.FirefoxConfig{
2019-02-27 10:47:06 +00:00
// Default data source name query options for `places.sqlite` db
PlacesDSN: database.DsnOptions{
"_journal_mode": "WAL",
},
2019-02-26 18:41:02 +00:00
// default profile to use
DefaultProfile: "default",
WatchAllProfiles: false,
}
func InitDefaultConfig() {
2019-02-27 10:47:06 +00:00
//TODO: handle chrome
2019-02-26 18:41:02 +00:00
log.Debug("Creating default config on config.toml")
// Export default firefox config
2019-02-27 10:47:06 +00:00
config.RegisterBrowserConf(FirefoxConf, FirefoxDefaultConfig)
2019-02-26 18:41:02 +00:00
// Set default values for firefox module
2019-02-27 10:47:06 +00:00
config.MapConfStruct(FirefoxDefaultConfig, mozilla.Config)
2019-02-26 18:41:02 +00:00
2019-02-27 10:47:06 +00:00
err := config.InitConfigFile()
2019-02-26 18:41:02 +00:00
if err != nil {
log.Fatal(err)
}
}
// Loads config from config file and shares config with browser modules
func LoadConfig() {
log.Debug("Loading config.toml")
c, err := config.LoadConfigFile()
if err != nil {
log.Fatal(err)
}
// Sync to firefox module config
2019-02-27 10:47:06 +00:00
err = c.MapTo(FirefoxConf, mozilla.Config)
if err != nil {
log.Fatal(err)
2019-02-26 18:41:02 +00:00
}
log.Warningf("%#v", mozilla.Config)
2019-02-27 10:47:06 +00:00
}
func init() {
// Check if config file exists
exists, err := utils.CheckFileExists(config.ConfigFile)
if err != nil {
log.Fatal(err)
}
if !exists {
// Initialize default config
InitDefaultConfig()
} else {
//TODO: maybe no need to preload if we can preparse options with altsrc
LoadConfig()
}
2019-02-26 18:41:02 +00:00
2019-02-27 10:47:06 +00:00
// Execute config hooks
config.RunConfHooks()
2019-02-26 18:41:02 +00:00
}