-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
53 lines (45 loc) · 1.15 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
package gofirefox
import (
"os"
)
type Config struct {
// ProfileDir is directory where semi-persistent profile is stored
ProfileDir string
// FirefoxBin is override location for firefox binary
FirefoxBin string
// ProfileLocationURL is profile location file
ProfileLocationURL string
}
const (
PreferenceFile = "prefs.js"
DefaultProfileLocation = "https://raw.githubusercontent.com/unikiosk/user.js/master/user.js"
)
func getConfig() (*Config, error) {
c := Config{}
if path, ok := os.LookupEnv("GOFIREFOX_BIN"); ok {
if _, err := os.Stat(path); err == nil {
c.FirefoxBin = path
}
} else {
c.FirefoxBin = FirefoxExecutable()
}
if profileDir, ok := os.LookupEnv("GOFIREFOX_PROFILE_DIR"); ok {
err := os.MkdirAll(profileDir, os.ModeDir)
if err != nil {
return nil, err
}
c.ProfileDir = profileDir
} else {
tempDir, err := os.MkdirTemp(os.TempDir(), "gofirefox")
if err != nil {
return nil, err
}
c.ProfileDir = tempDir
}
if profileLocation, ok := os.LookupEnv("GOFIREFOX_PROFILE_LOCATION"); ok {
c.ProfileLocationURL = profileLocation
} else {
c.ProfileLocationURL = DefaultProfileLocation
}
return &c, nil
}