mirror of
https://github.com/muesli/telephant
synced 2024-11-27 05:40:21 +00:00
Store config in platform-specific path
This commit is contained in:
parent
2d12ecac44
commit
c876c23019
2 changed files with 14 additions and 9 deletions
10
config.go
10
config.go
|
@ -28,15 +28,11 @@ type Config struct {
|
|||
Style string
|
||||
}
|
||||
|
||||
const (
|
||||
configFile = "telephant.conf"
|
||||
)
|
||||
|
||||
// LoadConfig returns the current config as a Config struct
|
||||
func LoadConfig() Config {
|
||||
func LoadConfig(configFile string) Config {
|
||||
_, err := os.Stat(configFile)
|
||||
if err != nil {
|
||||
SaveConfig(Config{
|
||||
SaveConfig(configFile, Config{
|
||||
Style: "Material",
|
||||
Account: []Account{Account{}},
|
||||
})
|
||||
|
@ -52,7 +48,7 @@ func LoadConfig() Config {
|
|||
}
|
||||
|
||||
// SaveConfig stores the current config
|
||||
func SaveConfig(config Config) {
|
||||
func SaveConfig(configFile string, config Config) {
|
||||
f, err := os.Create(configFile)
|
||||
if err != nil {
|
||||
log.Fatal("Could not open config file: ", err)
|
||||
|
|
13
telephant.go
13
telephant.go
|
@ -10,6 +10,7 @@ import (
|
|||
"github.com/therecipe/qt/qml"
|
||||
"github.com/therecipe/qt/quickcontrols2"
|
||||
|
||||
gap "github.com/muesli/go-app-paths"
|
||||
"github.com/muesli/telephant/accounts/mastodon"
|
||||
)
|
||||
|
||||
|
@ -203,7 +204,15 @@ func main() {
|
|||
setupQmlBridges()
|
||||
|
||||
// load config
|
||||
config = LoadConfig()
|
||||
scope := gap.NewScope(gap.User, "fribbledom.com", "telephant")
|
||||
configDir, err := scope.ConfigPath("")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
os.MkdirAll(configDir, 0700)
|
||||
|
||||
configFile, err := scope.ConfigPath("telephant.conf")
|
||||
config = LoadConfig(configFile)
|
||||
if config.Style == "" {
|
||||
config.Style = "Material"
|
||||
}
|
||||
|
@ -214,5 +223,5 @@ func main() {
|
|||
|
||||
// save config
|
||||
config.Style = configBridge.Style()
|
||||
SaveConfig(config)
|
||||
SaveConfig(configFile, config)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue