forked from browserutils/kooky
-
Notifications
You must be signed in to change notification settings - Fork 0
/
find.go
61 lines (49 loc) · 1.3 KB
/
find.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
//go:build !windows && !android && !ios
package epiphany
import (
"os"
"path/filepath"
"github.com/favbox/kooky"
"github.com/favbox/kooky/internal/cookies"
)
type epiphanyFinder struct{}
var _ kooky.CookieStoreFinder = (*epiphanyFinder)(nil)
func init() {
kooky.RegisterFinder(`epiphany`, &epiphanyFinder{})
}
func (f *epiphanyFinder) FindCookieStores() ([]kooky.CookieStore, error) {
roots, err := epiphanyRoots()
if err != nil {
return nil, err
}
var ret []kooky.CookieStore
last := len(roots) - 1
for i, root := range roots {
ret = append(
ret,
&cookies.CookieJar{
CookieStore: &epiphanyCookieStore{
DefaultCookieStore: cookies.DefaultCookieStore{
BrowserStr: `epiphany`,
IsDefaultProfileBool: i == last,
FileNameStr: filepath.Join(root, `cookies.sqlite`),
},
},
},
)
}
return ret, nil
}
func epiphanyRoots() ([]string, error) {
var ret []string
if home, err := os.UserHomeDir(); err == nil {
ret = []string{
filepath.Join(home, `.var`, `app`, `org.gnome.Epiphany`, `data`, `epiphany`), // flatpak
filepath.Join(home, `.local`, `share`, `epiphany`), // fallback
}
}
if dataDir, ok := os.LookupEnv(`XDG_DATA_HOME`); ok {
ret = append(ret, filepath.Join(dataDir, `epiphany`))
}
return ret, nil
}