-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.go
More file actions
75 lines (64 loc) · 1.51 KB
/
config.go
File metadata and controls
75 lines (64 loc) · 1.51 KB
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
package main
import (
"encoding/json"
"io/ioutil"
"os"
"pkg.deepin.io/lib/strv"
"strings"
)
const (
defaultOutputFile = "/usr/share/multi-display-session/outputs.json"
defaultAppsFile = "/usr/share/multi-display-session/autostart"
)
var (
outputConfigFile = os.Getenv("HOME") + "/.config/multi-display-session/outputs.json"
appConfigFile = os.Getenv("HOME") + "/.config/multi-display-session/autostart"
)
func launchApps() {
apps, err := newAppsFromFile(appConfigFile)
if err != nil {
apps, err = newAppsFromFile(defaultAppsFile)
if err != nil {
logger.Error("No apps config found:", err)
return
}
}
for _, app := range apps {
go runApp(app)
}
}
func checkOutputConfigValidity(names []string, infos []OutputInfo) bool {
if len(names) != len(infos) {
return false
}
for _, info := range infos {
if !strv.Strv(names).Contains(info.Name) {
return false
}
}
return true
}
func newOutputInfosFromFile(file string) ([]OutputInfo, error) {
var infos []OutputInfo
err := jsonUnmarshalFromFile(file, &infos)
if err != nil {
return nil, err
}
return infos, nil
}
func newAppsFromFile(file string) ([]string, error) {
content, err := ioutil.ReadFile(file)
if err != nil {
return nil, err
}
lines := strv.Strv(strings.Split(string(content), "\n"))
lines = lines.FilterEmpty()
return []string(lines), nil
}
func jsonUnmarshalFromFile(file string, value interface{}) error {
content, err := ioutil.ReadFile(file)
if err != nil {
return err
}
return json.Unmarshal(content, value)
}