-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
config.go
89 lines (80 loc) · 1.76 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package main
import (
"bytes"
"log"
"os"
"github.com/BurntSushi/toml"
"github.com/adrg/xdg"
)
const configPath = "mazesoba-continent/config.toml"
type Config struct {
General generalConfig
Window windowConfig
Credential credConfig
Kakikomi kakikomiConfig
}
type generalConfig struct {
// TBW
}
type windowConfig struct {
Width int
Height int
AlwaysOnTop bool
Transparent bool
BackgroundR int
BackgroundG int
BackgroundB int
BackgroundA float64
}
type credConfig struct {
Identifier string
Password string
Host string
}
type kakikomiConfig struct {
// TBW
// a.k.a kakikomi.txt
}
// loadOrCreateConfig ...
func loadOrCreateConfig(configPath string) (Config, error) {
var config Config
configFile, err := xdg.ConfigFile(configPath)
if err != nil {
log.Fatalf("Can't open config file: %s", configPath)
}
_, err = toml.DecodeFile(configFile, &config)
if err != nil {
log.Printf("Config file not found, initializing: %s", configFile)
defaultConfig := Config{
Window: windowConfig{
Width: 400,
Height: 200,
AlwaysOnTop: true,
Transparent: true,
BackgroundR: 27,
BackgroundG: 38,
BackgroundB: 54,
BackgroundA: 0.5,
},
Credential: credConfig{
Identifier: "ID (e.g. example.bsky.social)",
Password: "App Password (see https://tokimekibluesky-docs.vercel.app/ja/apppassword)",
Host: "https://bsky.social",
},
}
buf := new(bytes.Buffer)
err = toml.NewEncoder(buf).Encode(defaultConfig)
if err != nil {
log.Fatalln(err)
}
log.Println(
"",
"========Wrote default config toml========",
buf.String(),
"=========================================",
)
os.WriteFile(configFile, buf.Bytes(), 0644)
config = defaultConfig
}
return config, nil
}