-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdata_config.go
85 lines (69 loc) · 1.92 KB
/
data_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
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"os/user"
"github.com/gotk3/gotk3/gtk"
)
type Config struct {
PATH string
WINDOW_WIDTH int `json:"window_width"`
HORIZONTAL_SPACING int `json:"horizontal_spacing"`
VERTICAL_SPACING int `json:"vertical_spacing"`
ICON_SIZE int `json:"icon_size"`
CSS_THEME_FILE string `json:"css_theme_file"`
}
type WidgetConfig struct {
Type string `json:"type"`
Properties WidgetProperties `json:"properties"`
Children []*WidgetConfig `json:"children"`
Action string `json:"action"`
Script string `json:"script"`
}
type WidgetProperties struct {
Orientation string `json:"orientation"`
Spacing int `json:"spacing"`
Label string `json:"label"`
}
var Conf *Config
var WidgetConfs []WidgetConfig
var StyleProvider *gtk.CssProvider
func LoadConfig() {
user, _ := user.Current()
path := "/home/" + user.Username + "/.config/actionCenter/"
configPath := path + "config.json"
widgetsPath := path + "widgets.json"
cfgFile, cer := ioutil.ReadFile(configPath)
wcfgFile, wer := ioutil.ReadFile(widgetsPath)
if cer != nil {
fmt.Println("Error reading config file:", cer)
}
if wer != nil {
fmt.Println("Error reading widget file:", wer)
}
var config Config
var widgets []WidgetConfig
cer = json.Unmarshal(cfgFile, &config)
wer = json.Unmarshal(wcfgFile, &widgets)
if cer != nil {
fmt.Println("Error parsing config file:", cer)
}
if wer != nil {
fmt.Println("Error parsing widget file:", wer)
}
config.PATH = path
Conf = &config
WidgetConfs = widgets
provider, err := gtk.CssProviderNew()
if err != nil {
fmt.Println("Error creating css provider: ", err)
panic(err)
}
err = provider.LoadFromPath(Conf.PATH + Conf.CSS_THEME_FILE)
if err != nil {
fmt.Println("Error loading "+Conf.PATH+Conf.CSS_THEME_FILE+": ", err)
panic(err)
}
StyleProvider = provider
}